--- a/degal/main.py Fri Jun 05 23:41:57 2009 +0300
+++ b/degal/main.py Fri Jun 05 23:42:03 2009 +0300
@@ -16,7 +16,7 @@
# define options
parser.add_option('-G', "--gallery-path", dest='gallery_path', help="Use DIR as the Gallery path [default: CWD]", metavar='DIR', default=None)
- parser.add_option('-R', "--read-only", dest='read_only', help="Do not attempt to modify the gallery", default=True)
+ parser.add_option('-R', "--read-only", dest='read_only', help="Do not attempt to modify the gallery", action="store_true", default=False)
return parser
@@ -47,21 +47,36 @@
# read path from config
return gallery.Gallery(config.gallery_path, config)
-def load_command (options, args) :
+def load_command (config, args) :
"""
Figure out what command to run and with what args
"""
# XXX: hardcoded
- return commands.main, args
+ return commands.main, args, {}
+
+def run_command (config, gallery, command, args, kwargs) :
+ """
+ Run the given command
+ """
+
+ # setup the command execution context
+ command_ctx = command.setup(config, gallery)
+
+ try :
+ # run it
+ return command_ctx(*args, **kwargs)
+
+ except :
+ command_ctx.handle_error()
def main (argv) :
"""
Main entry point
"""
- # load commands
- commands = load_commands()
+ ## load commands
+ #commands = load_commands()
# build optparser
parser = option_parser(argv[0])
@@ -76,10 +91,10 @@
gallery = load_gallery(config)
# figure out what command to run
- command_func, command_args = load_command(options, args)
-
+ command, args, kwargs = load_command(config, args)
+
# run the selected command
- ret = command_func(gallery, *command_args)
+ ret = run_command(config, gallery, command, args, kwargs)
if ret is None :
# success