--- a/degal/main.py Fri Jun 05 23:05:23 2009 +0300
+++ b/degal/main.py Fri Jun 05 23:05:49 2009 +0300
@@ -2,7 +2,7 @@
Main entry point for the command-line interface
"""
-import commands
+import gallery, commands, config as config_module
from optparse import OptionParser
@@ -15,21 +15,78 @@
parser = OptionParser(prog=command_name)
# define options
- parser.add_option('-d', "--dir", dest='dir', help="Use DIR as the image/HTML path [default: CWD]", metavar='DIR', default='.')
+ 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)
return parser
+def build_config (options) :
+ """
+ Build a configuration object with the given options
+ """
+
+ # build default config
+ config = config_module.Configuration()
+
+ # apply options
+ if options.gallery_path :
+ config.gallery_path = options.gallery_path
+
+ if options.read_only :
+ config.read_only = True
+
+ # XXX: load config file(s)
+
+ return config
+
+def load_gallery (config) :
+ """
+ Create the Gallery object that we are manipulating
+ """
+
+ # read path from config
+ return gallery.Gallery(config.gallery_path, config)
+
+def load_command (options, args) :
+ """
+ Figure out what command to run and with what args
+ """
+
+ # XXX: hardcoded
+ return commands.main, args
+
def main (argv) :
"""
Main entry point
"""
+ # load commands
+ commands = load_commands()
+
# build optparser
parser = option_parser(argv[0])
# parse the given argv
- options, filter_targets = parser.parse_args(argv[1:])
+ options, args = parser.parse_args(argv[1:])
+
+ # build our config
+ config = build_config(options)
+
+ # open gallery
+ gallery = load_gallery(config)
+
+ # figure out what command to run
+ command_func, command_args = load_command(options, args)
# run the selected command
- return commands.main(options.dir, filter_targets)
+ ret = command_func(gallery, *command_args)
+
+ if ret is None :
+ # success
+ return 0
+ else :
+ # exit with error code
+ assert isinstance(ret, int)
+ return ret
+