[Python-checkins] distutils2: Add cache support for unpack
tarek.ziade
python-checkins at python.org
Sun Aug 8 11:50:46 CEST 2010
tarek.ziade pushed 981897e28aca to distutils2:
http://hg.python.org/distutils2/rev/981897e28aca
changeset: 469:981897e28aca
user: Alexis Metaireau <ametaireau at gmail.com>
date: Thu Jul 29 17:17:31 2010 +0200
summary: Add cache support for unpack
files: src/distutils2/index/dist.py
diff --git a/src/distutils2/index/dist.py b/src/distutils2/index/dist.py
--- a/src/distutils2/index/dist.py
+++ b/src/distutils2/index/dist.py
@@ -229,6 +229,7 @@
self.release = release
self.dist_type = dist_type
self.python_version = python_version
+ self._unpacked_dir = None
# set the downloaded path to None by default. The goal here
# is to not download distributions multiple times
self.downloaded_location = None
@@ -306,22 +307,24 @@
Returns the location of the extracted files (root).
"""
- if path is None:
- path = tempfile.mkdtemp()
-
- filename = self.download()
- content_type = mimetypes.guess_type(filename)[0]
-
- if (content_type == 'application/zip'
- or filename.endswith('.zip')
- or filename.endswith('.pybundle')
- or zipfile.is_zipfile(filename)):
- unzip_file(filename, path, flatten=not filename.endswith('.pybundle'))
- elif (content_type == 'application/x-gzip'
- or tarfile.is_tarfile(filename)
- or splitext(filename)[1].lower() in ('.tar', '.tar.gz', '.tar.bz2', '.tgz', '.tbz')):
- untar_file(filename, path)
- return path
+ if not self._unpacked_dir:
+ if path is None:
+ path = tempfile.mkdtemp()
+
+ filename = self.download()
+ content_type = mimetypes.guess_type(filename)[0]
+
+ if (content_type == 'application/zip'
+ or filename.endswith('.zip')
+ or filename.endswith('.pybundle')
+ or zipfile.is_zipfile(filename)):
+ unzip_file(filename, path, flatten=not filename.endswith('.pybundle'))
+ elif (content_type == 'application/x-gzip'
+ or tarfile.is_tarfile(filename)
+ or splitext(filename)[1].lower() in ('.tar', '.tar.gz', '.tar.bz2', '.tgz', '.tbz')):
+ untar_file(filename, path)
+ self._unpacked_dir = path
+ return self._unpacked_dir
def _check_md5(self, filename):
"""Check that the md5 checksum of the given file matches the one in
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list