From 3c415218dbdc112a26eef7eec2c6608eb100487c Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Wed, 20 Oct 2010 12:56:55 +0000 Subject: More sugar-lint fixes --- diff --git a/.gitignore b/.gitignore index 12965e2..e99077d 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,6 @@ m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4 m4/lt~obsolete.m4 +*.tar.* +.sweets +install diff --git a/bin/copy-from-journal b/bin/copy-from-journal index 7a10bfd..c8d2d84 100755 --- a/bin/copy-from-journal +++ b/bin/copy-from-journal @@ -4,7 +4,6 @@ # Reinier Heeres, , 2007-12-24 # Phil Bordelon -import sys import os import shutil import optparse @@ -20,81 +19,84 @@ import sugar.mime # for quicker operation. RETURN_LIMIT = 2 + def build_option_parser(): usage = "Usage: %prog [-o OBJECT_ID] [-q SEARCH_STR] [-m] OUTFILE" parser = optparse.OptionParser(usage=usage) parser.add_option("-o", "--object_id", action="store", dest="object_id", - help="Retrieve object with explicit ID OBJECT_ID", + help="Retrieve object with explicit ID OBJECT_ID", metavar="OBJECT_ID", default=None) parser.add_option("-q", "--query", action="store", dest="query", - help="Full-text-search the metadata for SEARCH_STR", + help="Full-text-search the metadata for SEARCH_STR", metavar="SEARCH_STR", default=None) - parser.add_option("-m", "--metadata", action="store_true", dest="show_meta", - help="Show all non-preview metadata [default: hide]", - default=False) + parser.add_option("-m", "--metadata", action="store_true", + dest="show_meta", + help="Show all non-preview metadata [default: hide]", + default=False) return parser if __name__ == "__main__": - parser = build_option_parser() - options, args = parser.parse_args() + option_parser = build_option_parser() + options, args = option_parser.parse_args() if len(args) < 1: - parser.print_help() + option_parser.print_help() exit(0) try: dsentry = None - + # Get object directly if we were given an explicit object ID. if options.object_id is not None: dsentry = datastore.get(options.object_id) - + # Compose the query based on the options provided. if dsentry is None: query = {} - + if options.query is not None: query['query'] = options.query - + # We only want a single file at a time; limit the number of objects - # returned to two, as anything more than one means the criteria were - # not limited enough. - objects, count = datastore.find(query, limit=RETURN_LIMIT, sorting='-mtime') + # returned to two, as anything more than one means the criteria + # were not limited enough. + objects, count = \ + datastore.find(query, limit=RETURN_LIMIT, sorting='-mtime') if count > 1: - print 'WARNING: %d objects found; retrieving most recent.' % (count) + print 'WARNING: %d objects found; getting most recent.' % count for i in xrange(1, RETURN_LIMIT): objects[i].destroy() - + if count > 0: dsentry = objects[0] - + # If neither an explicit object ID nor a query gave us data, fail. if dsentry is None: print 'ERROR: unable to determine journal object to copy.' - parser.print_help() + option_parser.print_help() exit(0) - + # Print metadata if that is what the user asked for. if options.show_meta: print 'Metadata:' for key, val in dsentry.metadata.get_dictionary().iteritems(): if key != 'preview': print '%20s -> %s' % (key, val) - + # If no file is associated with this object, we can't save it out. if dsentry.get_file_path() == "": print 'ERROR: no file associated with object, just metadata.' dsentry.destroy() exit(0) - + outname = args[0] outroot, outext = os.path.splitext(outname) - + # Do our best to determine the output file extension, based on Sugar's # MIME-type-to-extension mappings. if outext == "": @@ -102,13 +104,13 @@ if __name__ == "__main__": outext = sugar.mime.get_primary_extension(mimetype) if outext == None: outext = "dsobject" - outext = '.' + outext - + outext = '.' + outext + # Lastly, actually copy the file out of the datastore and onto the # filesystem. shutil.copyfile(dsentry.get_file_path(), outroot + outext) print '%s -> %s' % (dsentry.get_file_path(), outroot + outext) - + # Cleanup. dsentry.destroy() diff --git a/bin/copy-to-journal b/bin/copy-to-journal index ca6f872..e675441 100755 --- a/bin/copy-to-journal +++ b/bin/copy-to-journal @@ -7,7 +7,6 @@ # to support adding metadata. Note that the MIME-type is required, # as otherwise the datastore will not accept the file. -import sys import os import optparse from gettext import gettext as _ @@ -19,9 +18,11 @@ if os.path.exists("/tmp/olpc-session-bus"): from sugar.datastore import datastore from sugar import mime + def build_option_parser(): - usage = "Usage: %prog [-m MIMETYPE] [-t TITLE] [-d DESC] [-T tag1 [-T tag2 ...]]" + usage = "Usage: %prog [-m MIMETYPE] [-t TITLE] [-d DESC] " \ + "[-T tag1 [-T tag2 ...]]" parser = optparse.OptionParser(usage=usage) parser.add_option("-t", "--title", action="store", dest="title", @@ -36,23 +37,24 @@ def build_option_parser(): help="Set the file's MIME-type to MIMETYPE", default=None) parser.add_option("-T", "--tag", action="append", dest="tag_list", - help="Add tag TAG to the journal entry's tags; this option can be repeated", + help="Add tag TAG to the journal entry's tags; " \ + "this option can be repeated", metavar="TAG") return parser if __name__ == "__main__": - parser = build_option_parser() - options, args = parser.parse_args() + option_parser = build_option_parser() + options, args = option_parser.parse_args() if len(args) < 1: - parser.print_help() + option_parser.print_help() exit(0) - + fname = args[0] absname = os.path.abspath(fname) if not os.path.exists(absname): print 'Error: File does not exist.' - parser.print_help() + option_parser.print_help() exit(0) try: @@ -85,9 +87,9 @@ if __name__ == "__main__": datastore.write(entry) print 'Created as %s' % (entry.object_id) - + entry.destroy() - + except dbus.DBusException: print 'ERROR: Unable to connect to the datastore.\n'\ 'Check that you are running in the same environment as the '\ diff --git a/bin/datastore-service b/bin/datastore-service index 06b6517..008b66d 100755 --- a/bin/datastore-service +++ b/bin/datastore-service @@ -1,5 +1,8 @@ #!/usr/bin/env python -import sys, os, signal, logging +import sys +import os +import signal +import logging import gobject import dbus.service import dbus.mainloop.glib @@ -11,7 +14,8 @@ from sugar import logger 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) +if not os.path.exists(log_dir): + os.makedirs(log_dir) # setup logger logger.start('datastore') @@ -23,16 +27,16 @@ connected = True ds = DataStore() -# and run it +# and run it mainloop = gobject.MainLoop() + def handle_disconnect(): - global mainloop mainloop.quit() logging.debug("Datastore disconnected from the bus.") + def handle_shutdown(signum, frame): - global mainloop mainloop.quit() raise SystemExit("Shutting down on signal %s" % signum) @@ -44,6 +48,7 @@ bus.add_signal_receiver(handle_disconnect, signal.signal(signal.SIGHUP, handle_shutdown) signal.signal(signal.SIGTERM, handle_shutdown) + def main(): try: mainloop.run() @@ -51,8 +56,7 @@ def main(): logging.info("DataStore shutdown by user") except: logging.error("Datastore shutdown with error", exc_info=sys.exc_info()) - + main() ds.stop() - -- cgit v0.9.1