fix option parsing
authorTimo Savola <tsavola@movial.fi>
Tue, 29 Apr 2008 20:00:13 +0000 (23:00 +0300)
committerTimo Savola <tsavola@movial.fi>
Tue, 29 Apr 2008 20:00:13 +0000 (23:00 +0300)
matrix/matrix.py

index 32737c1..265f2cb 100644 (file)
@@ -28,7 +28,10 @@ def main():
        config_parse('config', True)
 
        for name in options:
-               setattr(config, name, options[name])
+               value = options[name]
+               if type(value) == list:
+                       value = value + getattr(config, name, [])
+               setattr(config, name, value)
 
        cache.init()
        all_targets = components.init()
@@ -79,25 +82,25 @@ commands:
 '''
 
 def parse_args():
-       options = {}
+       values = dict(roots=[])
 
-       class Values(object):
+       class ValueProxy(object):
                def __setattr__(self, name, value):
-                       options[name] = value
+                       values[name] = value
 
        def help(option, opt, value, parser):
                print_help(sys.stdout, parser)
                sys.exit(0)
 
        def add_root(option, opt, value, parser):
-               config.roots.append(value)
+               values['roots'].insert(0, value)
 
        def set_jobs(option, opt, value, parser):
                if value < 1:
                        raise optparse.OptionValueError(
                                'option %s: invalid job count: %d' % \
                                (opt, value))
-               setattr(config, option.dest, value)
+               values[option.dest] = value
 
        parser = optparse.OptionParser(
                usage='%prog [<options>] <command> [<components>]',
@@ -147,12 +150,12 @@ def parse_args():
                dest='make_jobs', action='callback', callback=set_jobs,
                type='int')
 
-       values, args = parser.parse_args(values=Values())
+       proxy, args = parser.parse_args(values=ValueProxy())
        if not args:
                print_help(sys.stderr, parser)
                sys.exit(1)
 
-       return args[0], args[1:], options
+       return args[0], args[1:], values
 
 def execute(args):
        if config.debug: