From 850963790d3f6da310f855ea154759239d11c1c9 Mon Sep 17 00:00:00 2001 From: Will Thames Date: Fri, 22 Aug 2014 10:04:12 +1000 Subject: [PATCH] Allow roles to be installed from archives on github Ensure that the automated scm determination for github.com repos still copes with .tar.gz archive files. Handling .zip archives is left as an exercise for the interested reader --- lib/ansible/utils/__init__.py | 11 ++++------- test/units/TestUtils.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/ansible/utils/__init__.py b/lib/ansible/utils/__init__.py index a618b5dc91a..ffb88598126 100644 --- a/lib/ansible/utils/__init__.py +++ b/lib/ansible/utils/__init__.py @@ -384,14 +384,11 @@ def role_spec_parse(role_spec): if role_spec == "" or role_spec.startswith("#"): return (None, None, None, None) - # FIXME: coding guidelines want this as a list comprehension - tokens = map(lambda s: s.strip(), role_spec.split(',')) + tokens = [s.strip() for s in role_spec.split(',')] # assume https://github.com URLs are git+https:// URLs and not - # tarballs - print "0=%s" % tokens[0] - if 'github.com/' in tokens[0] and not tokens[0].startswith("git+"): - print "DONE!" + # tarballs unless they end in '.zip' + if 'github.com/' in tokens[0] and not tokens[0].startswith("git+") and not tokens[0].endswith('.tar.gz'): tokens[0] = 'git+' + tokens[0] if '+' in tokens[0]: @@ -409,7 +406,7 @@ def role_spec_parse(role_spec): def role_yaml_parse(role): - if 'github.com' in role["src"] and 'http' in role["src"] and '+' not in role["src"]: + if 'github.com' in role["src"] and 'http' in role["src"] and '+' not in role["src"] and not role["src"].endswith('.tar.gz'): role["src"] = "git+" + role["src"] if '+' in role["src"]: (scm, src) = role["src"].split('+') diff --git a/test/units/TestUtils.py b/test/units/TestUtils.py index dda9d5c676e..f3f991bf7f3 100644 --- a/test/units/TestUtils.py +++ b/test/units/TestUtils.py @@ -825,7 +825,7 @@ class TestUtils(unittest.TestCase): } ), ( - # test that http://github URLs are assumed git+http:// + # test that http://github URLs are assumed git+http:// unless they end in .tar.gz "http://github.com/ansible/fakerole/fake", { 'scm' : 'git', @@ -833,6 +833,16 @@ class TestUtils(unittest.TestCase): 'version' : '', 'name' : 'fake' } + ), + ( + # test that http://github URLs are assumed git+http:// unless they end in .tar.gz + "http://github.com/ansible/fakerole/fake/archive/master.tar.gz", + { + 'scm' : None, + 'src' : 'http://github.com/ansible/fakerole/fake/archive/master.tar.gz', + 'version' : '', + 'name' : 'master' + } ) ] for (spec, result) in tests: