diff options
| author | Alexis Metaireau <ametaireau@gmail.com> | 2010-07-29 17:17:31 +0200 |
|---|---|---|
| committer | Alexis Metaireau <ametaireau@gmail.com> | 2010-07-29 17:17:31 +0200 |
| commit | 7e3f9b03710cd644c685be5cb1a6bfc47fe7056f (patch) | |
| tree | eea7f7a4f5af93dc5185c689d084eae2ea9867ab /src | |
| parent | 4d985423ab2a9643017605363fbcc240920c68cd (diff) | |
| download | disutils2-7e3f9b03710cd644c685be5cb1a6bfc47fe7056f.tar.gz | |
Add cache support for unpack
Diffstat (limited to 'src')
| -rw-r--r-- | src/distutils2/index/dist.py | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/distutils2/index/dist.py b/src/distutils2/index/dist.py index cac8c07..55a1268 100644 --- a/src/distutils2/index/dist.py +++ b/src/distutils2/index/dist.py @@ -229,6 +229,7 @@ class DistInfo(IndexReference): 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 @@ class DistInfo(IndexReference): 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 |
