Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bin/datastore-service.py
blob: 404d1519cd4081ca52fcc9a7a86233e7d4f9fdf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python2
import os
import sys
sys.path.append(os.path.join(os.path.expanduser('~'), 'Code/SemanticXO/datastore/src'))
sys.path.append(os.path.join(os.path.expanduser('~'), 'Code/SemanticXO/common/src'))

import signal
import logging
import gobject
import dbus.service
import dbus.mainloop.glib
import dbus.glib
from carquinyol.datastore import DataStore
from sugar import logger

# Path handling
profile = os.environ.get('SUGAR_PROFILE', 'default')
base_dir = os.path.join(os.path.expanduser('~'), '.sugar', profile)
log_dir = os.path.join(base_dir, "logs")
if not os.path.exists(log_dir):
    os.makedirs(log_dir)

# setup logger
logger.start('datastore')
#logging.basicConfig(level=5, format='%(created)f %(levelname)s %(name)s: %(message)s', stream=sys.stderr)

#logging.getLogger('').setLevel(5)
# build the datastore
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
connected = True

ds = DataStore()


# and run it
mainloop = gobject.MainLoop()


def handle_disconnect():
    mainloop.quit()
    logging.debug("Datastore disconnected from the bus.")


def handle_shutdown(signum, frame):
    mainloop.quit()
    raise SystemExit("Shutting down on signal %s" % signum)

bus.set_exit_on_disconnect(False)
bus.add_signal_receiver(handle_disconnect,
                        signal_name='Disconnected',
                        dbus_interface='org.freedesktop.DBus.Local')

signal.signal(signal.SIGHUP, handle_shutdown)
signal.signal(signal.SIGTERM, handle_shutdown)


def main():
    try:
        print "test"
        mainloop.run()
    except KeyboardInterrupt:
        logging.info("DataStore shutdown by user")
    except:
        logging.error("Datastore shutdown with error", exc_info=sys.exc_info())

main()

ds.stop()