From 796e5f80f5f712b5a8873bd8d002b895e95945af Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Mon, 26 Jan 2009 23:01:36 +0000 Subject: [PATCH] Merged in changes from the oblogout-distutils-extra branch --- oblogout | 73 +++++++++++++++++++++++++--------- openboxlogout/openboxlogout.py | 19 ++++----- 2 files changed, 63 insertions(+), 29 deletions(-) diff --git a/oblogout b/oblogout index 61ad636..599e339 100755 --- a/oblogout +++ b/oblogout @@ -25,30 +25,67 @@ import os import sys +import getopt import logging import logging.handlers from openboxlogout import openboxlogout -debug = True +class Usage(Exception): + def __init__(self, msg): + self.msg = msg -# Check config in local path, if it exists pass it on -if os.path.exists('openbox-logout.conf'): - config = 'openbox-logout.conf' -else: +def main(argv = None): + + # Start logger instace used by the OpenboxLogout class + logger = logging.getLogger('OpenboxLogout') + logout = logging.StreamHandler(sys.stdout) + logout.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")) + logger.addHandler(logout) + + verbose = None config = None + if argv is None: + argv = sys.argv -# Start logger instace used by the OpenboxLogout class -logger = logging.getLogger('OpenboxLogout') -logout = logging.StreamHandler(sys.stdout) -logout.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")) -logger.addHandler(logout) + try: + try: + opts, args = getopt.getopt(argv[1:], "hvc:", ["help", "verbose", "config="]) + except getopt.error, msg: + raise Usage(msg) + # more code, unchanged + except Usage, err: + logger.error(err.msg) + logger.error("for help use --help") + return 2 -# If debug mode is enabled, output debug messages -if debug: - logger.setLevel(logging.DEBUG) -else: - logger.setLevel(logging.INFO) + for o, a in opts: + if o in ("-h", "--help"): + print __doc__ + return 0 + elif o in ("-v", "--verbose"): + verbose = True + elif o in ("-c", "--config"): + config = a + + if not config: + config = '/etc/openbox-logout.conf' + + # Check config in local path, if it exists pass it on + if not os.path.exists(config): + logger.error("Invalid config file: %s" % config) + return 1 + + # If debug mode is enabled, output debug messages + if verbose: + logger.setLevel(logging.DEBUG) + else: + logger.setLevel(logging.INFO) + + # Start the application + app = openboxlogout.OpenboxLogout(config) + #app.run() + return 0 + +if __name__ == "__main__": + sys.exit(main()) -# Start the application -app = openboxlogout.OpenboxLogout(config) -app.run() diff --git a/openboxlogout/openboxlogout.py b/openboxlogout/openboxlogout.py index c2d61de..4e77978 100644 --- a/openboxlogout/openboxlogout.py +++ b/openboxlogout/openboxlogout.py @@ -69,7 +69,11 @@ class OpenboxLogout(): # Load configuration file self.load_config(config) - + + # Start the window + self.init_window() + + def init_window(self): # Start pyGTK setup self.window = gtk.Window() self.window.set_title(_("Openbox Logout")) @@ -169,14 +173,7 @@ class OpenboxLogout(): def load_config(self, config): """ Load the configuration file and parse entries, when encountering a issue change safe defaults """ - - if config == None: - config = '/etc/openbox-logout.conf' - - if not os.path.exists(config): - self.logger.error(_("Unable to find config file %s") % config) - exit() - + self.img_path = "%s/themes" % self.determine_path() self.parser = ConfigParser.SafeConfigParser() @@ -377,7 +374,7 @@ class OpenboxLogout(): def quit(self, widget=None, data=None): gtk.main_quit() - def run(self): + def run_logout(self): self.window.show_all() gtk.main() @@ -391,4 +388,4 @@ if __name__ == "__main__": config = None app = OpenboxLogout(config) - app.run() + app.run_logout()