diff options
-rw-r--r-- | README | 8 | ||||
-rwxr-xr-x | morphlib/app.py | 32 | ||||
-rw-r--r-- | morphlib/util.py | 45 |
3 files changed, 75 insertions, 10 deletions
@@ -40,11 +40,11 @@ something like this: cachedir = /home/username/baserock/cache log = /home/username/baserock/morph.log log-max = 200M - git-base-url = git://gitorious.org/baserock-morphs - bundle-server = http://roadtrain.codethink.co.uk/bundles + trove-host = git.baserock.org + bundle-server = http://git.baserock.org/bundles -All of the above settings apart from `log` are the defaults, so may be -omitted. +All of the above settings apart from `log` and `bundle-server` are the +defaults, so may be omitted. Morphology file syntax diff --git a/morphlib/app.py b/morphlib/app.py index 508e0975..7d7ddeb5 100755 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -25,13 +25,9 @@ import morphlib defaults = { + 'trove-host': 'git.baserock.org', + 'trove-prefix': [ ], 'repo-alias': [ - ('upstream=' - 'git://git.baserock.org/delta/#' - 'ssh://gitano@git.baserock.org/delta/'), - ('baserock=' - 'git://git.baserock.org/baserock/#' - 'ssh://gitano@git.baserock.org/baserock/'), ('freedesktop=' 'git://anongit.freedesktop.org/#' 'ssh://git.freedesktop.org/'), @@ -59,6 +55,22 @@ class Morph(cliapp.Application): 'show what is happening in much detail') self.settings.boolean(['quiet', 'q'], 'show no output unless there is an error') + self.settings.string(['trove-host'], + 'hostname of Trove instance', + metavar='HOST', + default=defaults['trove-host']) + self.settings.string_list(['trove-prefix'], + 'define URL prefix aliases stored ' + 'directly on the Trove host. Uses ' + 'the form ' + 'alias=pathprefix#pullmethod#pushmethod ' + 'for example, foocorp=fooprojects#git#ssh ' + 'will be expanded into a repo-alias of ' + 'foocorp=git://trove-host/fooprojects/%s#...' + ' with the push side set to the ssh url to ' + 'the trove.',\ + metavar='ALIAS=PREFIX#PULL#PUSH', + default=defaults['trove-prefix']) self.settings.string_list(['repo-alias'], 'define URL prefix aliases to allow ' 'repository addresses to be shortened; ' @@ -151,6 +163,14 @@ class Morph(cliapp.Application): metavar='PREFIX', default=defaults['build-ref-prefix']) + def process_args(self, args): + # Combine the aliases into repo-alias before passing on to normal + # command processing. This means everything from here on down can + # treat settings['repo-alias'] as the sole source of prefixes for git + # URL expansion. + self.settings['repo-alias'] = morphlib.util.combine_aliases(self) + cliapp.Application.process_args(self, args) + def setup_plugin_manager(self): cliapp.Application.setup_plugin_manager(self) diff --git a/morphlib/util.py b/morphlib/util.py index d1c60c36..ce9d0dc9 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -13,6 +13,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import re + import morphlib '''Utility functions for morph.''' @@ -97,6 +99,49 @@ def new_artifact_caches(settings): # pragma: no cover rac = None return lac, rac +def combine_aliases(app): # pragma: no cover + '''Create a full repo-alias set from the app's settings.''' + trove_host = app.settings['trove-host'] + trove_prefixes = app.settings['trove-prefix'] + repo_aliases = app.settings['repo-alias'] + repo_pat = r'^(?P<prefix>[a-z0-9]+)=(?P<pull>[^#]+)#(?P<push>[^#]+)$' + trove_pat = (r'^(?P<prefix>[a-z0-9]+)=(?P<path>[^#]+)#' + '(?P<pull>[^#]+)#(?P<push>[^#]+)$') + alias_map = {} + def _expand(protocol, path): + if protocol == "git": + return "git://%s/%s/%%s" % (trove_host, path) + elif protocol == "ssh": + return "ssh://git@%s/%s/%%s" % (trove_host, path) + else: + raise cliapp.AppException( + 'Unknown protocol in trove_prefix: %s' % protocol) + + if trove_host: + alias_map['baserock'] = "baserock=%s#%s" % ( + _expand('git', 'baserock'), + _expand('ssh', 'baserock')) + alias_map['upstream'] = "upstream=%s#%s" % ( + _expand('git', 'delta'), + _expand('ssh', 'delta')) + for trove_prefix in trove_prefixes: + m = re.match(trove_pat, trove_prefix) + if m: + alias_map[m.group('prefix')] = "%s=%s#%s" % ( + m.group('prefix'), + _expand(m.group('pull'), m.group('path')), + _expand(m.group('push'), m.group('path'))) + elif '=' not in trove_prefix: + alias_map[trove_prefix] = "%s=%s#%s" % ( + trove_prefix, + _expand('ssh', trove_prefix), + _expand('ssh', trove_prefix)) + for repo_alias in repo_aliases: + m = re.match(repo_pat, repo_alias) + if m: + alias_map[m.group('prefix')] = repo_alias + + return alias_map.values() def new_repo_caches(app): # pragma: no cover '''Create new objects for local, remote git repository caches.''' |