summaryrefslogtreecommitdiff
path: root/morphlib/util.py
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-09-12 10:12:12 +0000
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-09-12 14:04:37 +0100
commitda5a4968789e45d90f4b855874835d35c2614e58 (patch)
tree0fb71bb33b47dfe56c5b24e900e5410f617e9db6 /morphlib/util.py
parent1c89026bc70003b302167248c0d2ed229cd27223 (diff)
downloadmorph-da5a4968789e45d90f4b855874835d35c2614e58.tar.gz
Add support for Trove hosted content to morph configuration.
Trove has a fixed structure for repositories and prefixes. By taking advantage of this, we can simplify the repo-alias configuration in morph somewhat and thus make it easier for others to add their own aliases and prefixes later, without worrying that they'll miss out on default ones created by the Baserock team. We override process_args in the application class to achieve this because cliapp's setup() hook is not quite right for our purposes.
Diffstat (limited to 'morphlib/util.py')
-rw-r--r--morphlib/util.py45
1 files changed, 45 insertions, 0 deletions
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.'''