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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#!/usr/bin/env python
from ore.main import Application
from olpc.datastore import DataStore
from olpc.datastore.indexer import INDEX_SERVICE, INDEX_OBJECT_PATH
import os, signal, sys
import dbus
import dbus.mainloop.glib
profile = os.environ.get('SUGAR_PROFILE', 'default')
base_dir = os.path.join(os.path.expanduser('~'), '.sugar', profile)
repo_dir = os.path.join(base_dir, 'datastore')
db_dir = "sqlite:///%s/datastore.db" % repo_dir
import logging
def handle_shutdown(signum, frame):
dsa.stop()
raise SystemExit("Shutting down on signal %s" % signum)
# check for old lockfiles, the rules here are that we can't be
# connected to a tty. If we are not then in all likelyhood the process
# was started automatically, which hopefully implies a single instance
if not sys.stdin.isatty():
lf = os.path.join(repo_dir, 'fulltext', 'flintlock')
if os.path.exists(lf):
logging.warning("Old lock file found -- removing.")
os.unlink(lf)
class DataStoreApplication(Application):
def manage_options(self):
self.parser.add_option("--olpc.repo", dest="repo_dir",
action="store", default=repo_dir,
help="""Location of the Repository""")
self.parser.add_option("--olpc.metadata", dest="md_db",
action="store", default=db_dir,
help="""Location of the Repository""")
self.parser.add_option("--olpc.debug.db", dest="debug_db",
action="store_true", default=False,
help="""Dump database work""")
self.parser.add_option("--olpc.fulltext.sync", dest="querymanager_sync_index",
action="store_true", default=False,
help="""Force the indexer in-process in
synchronous mode.""")
self.parser.add_option("--olpc.fulltext.debug_indexer",
dest="start_indexer",
action="store_false", default=True,
help="""Don't make an attempt to start the indexer (use existing -- for debug)""")
def main(self):
# operate from the repo directory
if not os.path.exists(repo_dir):
os.makedirs(repo_dir)
os.chdir(repo_dir)
self.ds = DataStore(self.options.repo_dir,
self.options.md_db,
querymanager_sync_index=self.options.querymanager_sync_index)
if self.options.sync_index is False and self.options.start_indexer:
# trigger the index service
bus = dbus.SessionBus()
indexer = bus.get_object(INDEX_SERVICE, INDEX_OBJECT_PATH)
if self.options.debug_db:
logging.getLogger('sqlalchemy.orm.unitofwork').setLevel(logging.DEBUG)
self.ds.querymanager.db.echo = True
# register the signal handler
signal.signal(signal.SIGHUP, handle_shutdown)
signal.signal(signal.SIGTERM, handle_shutdown)
try:
self.eventloop.run()
except: self.ds.stop()
dsa = DataStoreApplication("datastore")
dsa.plugins.append('ore.main.profile_support.ProfileSupport')
dsa()
|