config: git-pull config dirs automatically
authorTimo Savola <tsavola@movial.fi>
Fri, 8 Aug 2008 10:45:35 +0000 (13:45 +0300)
committerTimo Savola <tsavola@movial.fi>
Fri, 8 Aug 2008 10:45:35 +0000 (13:45 +0300)
   * -p / --pull-config-dirs command-line option

   * PullConfigDirs(bool) config API function

matrix/config.py
matrix/matrix.py

index 6ec304a..776d1e0 100644 (file)
@@ -40,7 +40,11 @@ def config_dir(path=None, url=None, branch='master', optional=False):
        if url:
                name = basename(path)
                repo = Repository(name=name, path=path, url=url, branch=branch)
-               if not repo.exists():
+
+               if repo.exists():
+                       if config.pull_config_dirs:
+                               repo.pull()
+               else:
                        repo.clone()
        else:
                if not isdir(path):
@@ -49,6 +53,9 @@ def config_dir(path=None, url=None, branch='master', optional=False):
        if path not in config.initial_config_dirs:
                config.config_dirs.append(path)
 
+def pull_config_dirs(flag):
+       config.pull_config_dirs = flag
+
 def root(url, branch='master'):
        config.roots.append((url, branch))
 
@@ -216,6 +223,7 @@ class Config(object):
                self.debug = False
                self.force = False
                self.keep_going = False
+               self.pull_config_dirs = False
                self.jobs = 1
                self.make_jobs = 1
 
@@ -232,6 +240,7 @@ actions = dict(
        GetVariables = get_variables,
        Parse = parse,
        ProvideComponent = provide_component,
+       PullConfigDirs = pull_config_dirs,
        Root = root,
        SB2Compiler = sb2_compiler,
        SB2InitOptions = sb2_init_options,
index a6b3147..7814d49 100644 (file)
@@ -27,7 +27,7 @@ def merge_config(name, value):
 def main():
        command, targets, options = parse_args()
 
-       for name in ('debug', 'initial_config_dirs'):
+       for name in ('debug', 'initial_config_dirs', 'pull_config_dirs'):
                if name in options:
                        merge_config(name, options[name])
 
@@ -139,6 +139,11 @@ def parse_args():
                type='string')
 
        parser.add_option(
+               '-p', '--pull-config-dirs',
+               help='git-pull config dirs which are backed by Git repositories',
+               dest='pull_config_dirs', action='callback', callback=set_flag)
+
+       parser.add_option(
                '-r', '--root', metavar='URL',
                help='add a location for finding git repos when cloning ' \
                     '(may be set multiple times)',