diff -r a6e53a20fccb -r 97505a789003 degal/main.py --- a/degal/main.py Wed Jul 01 20:57:03 2009 +0300 +++ b/degal/main.py Thu Jul 02 21:59:01 2009 +0300 @@ -2,11 +2,18 @@ Main entry point for the command-line interface """ -import gallery, commands, config, version +import gallery, command, commands, config, version from optparse import OptionParser import os.path +def load_commands () : + """ + Build the CommandList for us to use + """ + + return command.CommandList(commands.COMMANDS) + def build_config () : """ Build the default configuration to use @@ -14,28 +21,20 @@ return config.Configuration() -def option_parser (exec_name) : +def option_parser (exec_name, command) : """ - Build the OptionParser that we use + Build the OptionParser that we use, with the given command """ parser = OptionParser(prog=exec_name, description="Degal - A photo gallery", version="Degal %s" % version.VERSION_STRING) + # core options parser.add_option('-C', "--config", metavar='PATH', dest="_load_config_path", help="Load configuration from PATH") parser.add_option('-H', "--gallery-path", metavar='DIR', help="Use DIR as the Gallery path instead of the CWD") - parser.add_option('-F', "--force-update", action="store_true", - help="--force-thumb + --force-html") - - parser.add_option("--force-thumb", action="store_true", - help="Force-update thumbnails") - - parser.add_option("--force-html", action="store_true", - help="Force-update .html files") - parser.add_option("--with-exif", action="store_true", help="Include Exif metadata in updated .html files") @@ -51,6 +50,9 @@ parser.add_option('-q', "--quiet", action="store_const", dest="log_level", const=config.logging.WARN, help="Reduced output (only warnings)") + # command's options + parser.add_option_group(command.option_group(parser)) + return parser def parse_args (config, parser, args) : @@ -94,38 +96,23 @@ # read path from config return gallery.Gallery(config.gallery_path, config) -def load_command (config, args) : - """ - Figure out what command to run and with what args - """ - - # XXX: hardcoded - 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) - - # run with error handling - return command_ctx.run() - def main (argv) : """ Main entry point """ ## load commands - #commands = load_commands() + commands = load_commands() # build our default config config = build_config() + + + # XXX: hardcoded + command = commands.lookup('update') # build optparser - parser = option_parser(argv[0]) + parser = option_parser(argv[0], command) # parse the args into our config args = parse_args(config, parser, argv[1:]) @@ -136,13 +123,9 @@ # open gallery gallery = load_gallery(config) - # figure out what command to run - command, args, kwargs = load_command(config, args) - - - # run the selected command - ret = run_command(config, gallery, command, args, kwargs) + # XXX: mix up configs with options + ret = command.apply(config, gallery, config, *args).run() if ret is None :