mirror of
https://github.com/nikdoof/oblogout.git
synced 2025-12-23 07:19:24 +00:00
Merged in changes from the oblogout-distutils-extra branch
This commit is contained in:
73
oblogout
73
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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user