diff options
author | Benjamin Saller <bcsaller@objectrealms.net> | 2007-05-22 15:58:01 (GMT) |
---|---|---|
committer | Benjamin Saller <bcsaller@objectrealms.net> | 2007-05-22 15:58:01 (GMT) |
commit | a77bea18582f224d6ccf0fa0835182064802756c (patch) | |
tree | 3e7a9f8b1e6ca7b845ab4a385f2d046efdc77bb7 /bin | |
parent | 415af81dba333be655e53ad2acbf57479256b7d2 (diff) |
minor api changes, signal handling (unverified)
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/datastore | 32 | ||||
-rwxr-xr-x | bin/datastore-service | 28 | ||||
-rwxr-xr-x | bin/sample-client.py | 21 |
3 files changed, 63 insertions, 18 deletions
diff --git a/bin/datastore b/bin/datastore index 4405c52..6ca5e39 100755 --- a/bin/datastore +++ b/bin/datastore @@ -1,16 +1,18 @@ #!/usr/bin/env python from ore.main import Application from olpc.datastore import DataStore -import os +import os, signal base_dir = os.path.expanduser("~/.sugar/default") repo_dir = os.path.join(base_dir, 'datastore') db_dir = "sqlite:///%s/datastore.db" % repo_dir -# operate from the repo directory -if not os.path.exists(repo_dir): - os.makedirs(repo_dir) -os.chdir(repo_dir) +import logging + +def handle_shutdown(signum, frame): + ds.stop() + raise SystemExit("Shutting down on signal %s" % signum) + class DataStoreApplication(Application): def manage_options(self): @@ -22,13 +24,31 @@ class DataStoreApplication(Application): 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""") + 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) - + + 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) + self.eventloop.run() dsa = DataStoreApplication("datastore") +dsa.plugins.append('ore.main.profile_support.ProfileSupport') dsa() diff --git a/bin/datastore-service b/bin/datastore-service index e2a96d9..e37487c 100755 --- a/bin/datastore-service +++ b/bin/datastore-service @@ -1,5 +1,5 @@ #!/usr/bin/env python -import sys, os +import sys, os, signal import gobject import dbus.service import dbus.mainloop.glib @@ -37,9 +37,25 @@ ds = DataStore(repo_dir, db_dir) logger.info("Starting Datastore %s:%s" % (repo_dir, db_dir)) mainloop = gobject.MainLoop() -try: mainloop.run() -except KeyboardInterrupt: logger.info("DataStore shutdown by user") -except: logger.debug("Datastore shutdown with error", - exc_info=sys.exc_info()) - +def handle_shutdown(signum, frame): + ds.stop() + print "shutdown cleanly" + raise SystemExit("Shutting down on signal %s" % signum) + +signal.signal(signal.SIGHUP, handle_shutdown) +signal.signal(signal.SIGTERM, handle_shutdown) + +def main(): + try: mainloop.run() + except KeyboardInterrupt: logger.info("DataStore shutdown by user") + except: + ds.stop() + logger.debug("Datastore shutdown with error", + exc_info=sys.exc_info()) + +#main() + +import hotshot +p = hotshot.Profile('hs.prof') +p.run('main()') diff --git a/bin/sample-client.py b/bin/sample-client.py index 6dba02d..a642818 100755 --- a/bin/sample-client.py +++ b/bin/sample-client.py @@ -1,22 +1,31 @@ #!/usr/bin/env python - +from ore.main import Application import dbus +import os def main(): bus = dbus.SessionBus() datastore = bus.get_object("org.laptop.sugar.DataStore", - "/org/laptop/sugar/DataStore") + "/org/laptop/sugar/DataStore") - uid = datastore.create(dict(title="from dbus"), '/etc/passwd') + uid = datastore.create(dict(title="from dbus", author="Benjamin"), os.path.abspath('tests/test.pdf')) print "created uid", uid - - print "all", datastore.all() + + #print "all", datastore.all() + #for u in datastore.all(): + # if u != uid: + # datastore.delete(u) + print "find", datastore.find(dict(author="Benjamin", title="from")) + print "bcsaller", datastore.find(dict(fulltext="bcsaller")) print "huh?", datastore.find(dict(fulltext="kfdshaksjd")) datastore.update(uid, dict(title="updated title"), "/etc/passwd") + datastore.update(uid, dict(title="another updated title"), "/etc/passwd") print datastore.get_properties(uid) datastore.delete(uid) if __name__ == '__main__': - main() + a = Application("client", main) + a.plugins.append('ore.main.profile_support.ProfileSupport') + a() |