summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJUN JIE NAN <nanjj@cn.ibm.com>2013-06-28 17:27:56 +0800
committerJUN JIE NAN <nanjj@cn.ibm.com>2013-07-01 17:38:26 +0800
commita4e7c722f74384b913b48e0f18d5ea6b19a484e0 (patch)
tree59914de445d64ca94f0c8eaf758aba6f7c2015bd
parent1ad95945fab379bc8303d0629f2f1bc77cd76959 (diff)
downloadheat-cfntools-a4e7c722f74384b913b48e0f18d5ea6b19a484e0.tar.gz
Add GitHub tarball and zipball support
Github tarball and zipball support was removed in the change set to pipe handing in sources. The changeset add it in and restructured. Change-Id: I107f42e9961cd8776161d1f6a2efe9d103aea125 Fixes: bug #1195622
-rw-r--r--heat_cfntools/cfntools/cfn_helper.py39
-rw-r--r--heat_cfntools/tests/test_cfn_helper.py8
2 files changed, 32 insertions, 15 deletions
diff --git a/heat_cfntools/cfntools/cfn_helper.py b/heat_cfntools/cfntools/cfn_helper.py
index 5e0395c..9f8c669 100644
--- a/heat_cfntools/cfntools/cfn_helper.py
+++ b/heat_cfntools/cfntools/cfn_helper.py
@@ -562,23 +562,31 @@ class SourcesHandler(object):
def _url_to_tmp_filename(self, url):
tempdir = tempfile.mkdtemp()
atexit.register(lambda: shutil.rmtree(tempdir, True))
- sp = url.split('/')
- if 'https://github.com' in url:
- if 'zipball' == sp[-2]:
- return '%s/%s-%s.zip' % (tempdir, sp[-3], sp[-1])
- elif 'tarball' == sp[-2]:
- return '%s/%s-%s.tar.gz' % (tempdir, sp[-3], sp[-1])
- else:
- pass
-
- return '%s/%s' % (tempdir, sp[-1])
+ name = os.path.basename(url)
+ return os.path.join(tempdir, name)
def _splitext(self, path):
(r, ext) = os.path.splitext(path)
return (r, ext.lower())
- def _source_type(self, name):
- (r, ext) = self._splitext(name)
+ def _github_ball_type(self, url):
+ ext = ""
+ if url.endswith('/'):
+ url = url[0:-1]
+ sp = url.split('/')
+ if len(sp) > 2:
+ http = sp[0].startswith('http')
+ github = sp[2].endswith('github.com')
+ btype = sp[-2]
+ if http and github:
+ if 'zipball' == btype:
+ ext = '.zip'
+ elif 'tarball' == btype:
+ ext = '.tgz'
+ return ext
+
+ def _source_type(self, url):
+ (r, ext) = self._splitext(url)
if ext == '.gz':
(r, ext2) = self._splitext(r)
if ext2 == '.tar':
@@ -587,12 +595,15 @@ class SourcesHandler(object):
(r, ext2) = self._splitext(r)
if ext2 == '.tar':
ext = '.tbz2'
+ elif ext == "":
+ ext = self._github_ball_type(url)
+
return ext
def _apply_source_cmd(self, dest, url):
cmd = ""
basename = os.path.basename(url)
- stype = self._source_type(basename)
+ stype = self._source_type(url)
if stype == '.tgz':
cmd = "wget -q -O - '%s' | gunzip | tar -xvf -" % url
elif stype == '.tbz2':
@@ -608,8 +619,6 @@ class SourcesHandler(object):
elif stype == '.bz2':
(r, ext) = self._splitext(basename)
cmd = "wget -q -O - '%s' | bunzip2 > '%s'" % (url, r)
- else:
- pass
if cmd != '':
cmd = "mkdir -p '%s'; cd '%s'; %s" % (dest, dest, cmd)
diff --git a/heat_cfntools/tests/test_cfn_helper.py b/heat_cfntools/tests/test_cfn_helper.py
index 99f3a03..a992cc5 100644
--- a/heat_cfntools/tests/test_cfn_helper.py
+++ b/heat_cfntools/tests/test_cfn_helper.py
@@ -719,6 +719,14 @@ class TestSourcesHandler(MockPopenTestCase):
url = 'http://www.example.com/a.tar.gz'
cmd = sh._apply_source_cmd(dest, url)
self.assertEqual(er % (dest, dest, url, "gunzip"), cmd)
+ # test github - tarball 1
+ url = 'https://github.com/openstack/heat-cfntools/tarball/master'
+ cmd = sh._apply_source_cmd(dest, url)
+ self.assertEqual(er % (dest, dest, url, "gunzip"), cmd)
+ # test github - tarball 2
+ url = 'https://github.com/openstack/heat-cfntools/tarball/master/'
+ cmd = sh._apply_source_cmd(dest, url)
+ self.assertEqual(er % (dest, dest, url, "gunzip"), cmd)
# test tbz2
url = 'http://www.example.com/a.tbz2'
cmd = sh._apply_source_cmd(dest, url)