diff options
author | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-02-24 13:39:18 +0000 |
---|---|---|
committer | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-02-24 13:39:18 +0000 |
commit | 3598043989d215cf2c02d50cfec33046eb0e2358 (patch) | |
tree | 52d535fa470925c6927a33c5a6405a28938beeea /morphlib | |
parent | e543fc5760dde600c9699955214e7392954f0778 (diff) | |
download | morph-3598043989d215cf2c02d50cfec33046eb0e2358.tar.gz |
Rework the bundle code to set the bundle filename outside _wget().
This is a bit stupid and requires tests to be adjusted (which is done in
this commit as well).
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/sourcemanager.py | 17 | ||||
-rw-r--r-- | morphlib/sourcemanager_tests.py | 21 |
2 files changed, 14 insertions, 24 deletions
diff --git a/morphlib/sourcemanager.py b/morphlib/sourcemanager.py index e1d1f33c..21c99fa9 100644 --- a/morphlib/sourcemanager.py +++ b/morphlib/sourcemanager.py @@ -79,18 +79,13 @@ class SourceManager(object): spaces = ' ' * self.indent self.real_msg('%s%s' % (spaces, text)) - def _wget(self, url): # pragma: no cover + def _wget(self, url, filename): # pragma: no cover # the following doesn't work during bootstrapping # ex = morphlib.execute.Execute(self.cache_dir, msg=self.msg) # ex.runv(['wget', '-c', url]) # so we do it poorly in pure Python instead - t = urlparse.urlparse(url) - path = t[2] - basename = os.path.basename(path) - saved_name = os.path.join(self.cache_dir, basename) - source_handle = urllib2.urlopen(url) - target_handle = open(saved_name, 'wb') + target_handle = open(filename, 'wb') data = source_handle.read(4096) while data: @@ -100,19 +95,20 @@ class SourceManager(object): source_handle.close() target_handle.close() - return saved_name + return filename def _cache_repo_from_bundle(self, server, repo_url): quoted_url = quote_url(repo_url) cached_repo = os.path.join(self.cache_dir, quoted_url) bundle_name = '%s.bndl' % quoted_url bundle_url = server + bundle_name + bundle = os.path.join(self.cache_dir, bundle_name) self.msg('Trying to fetch bundle %s' % bundle_url) request = urllib2.Request(bundle_url) try: urllib2.urlopen(request) try: - bundle = self._wget(bundle_url) + self._wget(bundle_url, bundle) self.msg('Extracting bundle %s into %s' % (bundle, cached_repo)) try: @@ -134,9 +130,6 @@ class SourceManager(object): os.remove(bundle) except morphlib.execute.CommandFailure, e: # pragma: no cover return None, 'Unable to fetch bundle %s: %s' % (bundle, e) - finally: - if os.path.exists(bundle): - os.remove(bundle) except urllib2.URLError, e: return None, 'Unable to fetch bundle %s: %s' % (bundle_url, e) diff --git a/morphlib/sourcemanager_tests.py b/morphlib/sourcemanager_tests.py index 75bac956..7dc77b11 100644 --- a/morphlib/sourcemanager_tests.py +++ b/morphlib/sourcemanager_tests.py @@ -14,6 +14,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import glob import unittest import tempfile import shutil @@ -127,10 +128,10 @@ class SourceManagerTests(unittest.TestCase): s = morphlib.sourcemanager.SourceManager(app, tempdir) - def wget(url): - path=urlparse.urlparse(url).path - shutil.copy(path, s.cache_dir) - return self.temprepo + def wget(url, filename): + bundle_file = os.path.join(self.temprepodir, + os.path.basename(filename)) + shutil.copy(bundle_file, s.cache_dir) s._wget = wget @@ -146,10 +147,8 @@ class SourceManagerTests(unittest.TestCase): s = morphlib.sourcemanager.SourceManager(app, tempdir) - def wget(url): - path=urlparse.urlparse(url).path - shutil.copy(path, s.cache_dir) - return self.temprepo + def wget(url, filename): + shutil.copy(filename, s.cache_dir) s._wget = wget self.assertRaises(morphlib.sourcemanager.RepositoryFetchError, @@ -165,10 +164,8 @@ class SourceManagerTests(unittest.TestCase): s = morphlib.sourcemanager.SourceManager(app, tempdir) - def wget(url): - path=urlparse.urlparse(url).path - shutil.copy(path, s.cache_dir) - return self.temprepo + def wget(url, filename): + shutil.copy(filename, s.cache_dir) s._wget = wget self.assertRaises(morphlib.sourcemanager.RepositoryFetchError, |