config: confdirs renamed to config_dirs; ConfigDir() added
authorTimo Savola <tsavola@movial.fi>
Wed, 11 Jun 2008 08:54:01 +0000 (11:54 +0300)
committerTimo Savola <tsavola@movial.fi>
Wed, 11 Jun 2008 08:54:01 +0000 (11:54 +0300)
ConfigDir(path=<config dir>, url=<git repository>, branch=<branch>) can be
used to clone a <git repository> (and check out <branch>) if <config dir>
doesn't already exist.

matrix/config.py
matrix/repositories.py

index b7e4967..c9df472 100644 (file)
@@ -5,7 +5,7 @@
 import sre
 from glob import glob
 from os import getenv
-from os.path import basename, exists, isabs, join
+from os.path import basename, exists, isabs, isdir, join
 from sets import Set as set
 
 Error = RuntimeError
@@ -21,6 +21,28 @@ def _make_list(arg):
 
        return list(arg)
 
+def config_dir(path=None, url=None, branch='master'):
+       from repositories import Repository
+
+       if not path:
+               if not url:
+                       raise Error('No path or URL specified')
+
+               path = basename(url)
+               if path.endswith('.git'):
+                       path = path.rsplit('.', 1)[0]
+
+       if url:
+               name = basename(path)
+               repo = Repository(name=name, path=path, url=url, branch=branch)
+               if not repo.exists():
+                       repo.clone()
+       else:
+               if not isdir(path):
+                       raise Error('Config dir does not exist: %s' % path)
+
+       config.config_dirs.append(path)
+
 class Board(object):
        def __init__(self, name, arch, gcc_march,
                     gcc_mcpu=None,
@@ -70,8 +92,8 @@ def parse(pattern, require=True):
        if isabs(pattern):
                dirs = [None]
        else:
-               all_confdirs = config.confdirs + config.initial_confdirs
-               dirs = [join(config.top_dir, dir) for dir in all_confdirs]
+               config_dirs = config.config_dirs + config.initial_config_dirs
+               dirs = [join(config.top_dir, dir) for dir in config_dirs]
                dirs.append(config.top_dir)
 
        found = False
@@ -97,8 +119,8 @@ def parse(pattern, require=True):
 
 class Config(object):
        def __init__(self):
-               self.initial_confdirs = []
-               self.confdirs = []
+               self.initial_config_dirs = []
+               self.config_dirs = []
 
                self.top_dir = getenv('MATRIX_TOPDIR', '')
                __cache_dir = join(self.top_dir, 'build-cache')
@@ -119,6 +141,7 @@ class Config(object):
                self.make_jobs = 1
 
 actions = dict(
+       ConfigDir = config_dir,
        Board = Board,
        Component = component,
        ProvideComponent = provide_component,
index 5fb2200..ac1fd63 100644 (file)
@@ -10,10 +10,11 @@ from config import config
 Error = RuntimeError
 
 class Repository(object):
-       def __init__(self, name, path, branch, exclude=None):
+       def __init__(self, name, path, branch, url=None, exclude=None):
                self.name = name
                self.path = path
                self.branch = branch
+               self.url = url
                self.exclude = exclude
                self.__url_branch = None
                self.__hash = None
@@ -40,6 +41,9 @@ class Repository(object):
                return self.__url_branch
 
        def __new_url_branch(self):
+               if self.url:
+                       return self.url, self.branch
+
                rev_roots = config.roots[:]
                rev_roots.reverse()