diff options
-rwxr-xr-x | setuptools.txt | 4 | ||||
-rwxr-xr-x | setuptools/archive_util.py | 47 |
2 files changed, 48 insertions, 3 deletions
diff --git a/setuptools.txt b/setuptools.txt index 610ad49a..65b36bc2 100755 --- a/setuptools.txt +++ b/setuptools.txt @@ -2177,6 +2177,10 @@ Release Notes/Change History * Made all commands that use ``easy_install`` respect its configuration options, as this was causing some problems with ``setup.py install``. + * Added an ``unpack_directory()`` driver to ``setuptools.archive_util``, so + that you can process a directory tree through a processing filter as if it + were a zipfile or tarfile. + 0.6a8 * Fixed some problems building extensions when Pyrex was installed, especially with Python 2.4 and/or packages using SWIG. diff --git a/setuptools/archive_util.py b/setuptools/archive_util.py index d24c6c13..4cc80b60 100755 --- a/setuptools/archive_util.py +++ b/setuptools/archive_util.py @@ -3,10 +3,10 @@ __all__ = [ "unpack_archive", "unpack_zipfile", "unpack_tarfile", "default_filter", - "UnrecognizedFormat", "extraction_drivers" + "UnrecognizedFormat", "extraction_drivers", "unpack_directory", ] -import zipfile, tarfile, os +import zipfile, tarfile, os, shutil from pkg_resources import ensure_directory from distutils.errors import DistutilsError @@ -80,6 +80,47 @@ def unpack_archive(filename, extract_dir, progress_filter=default_filter, +def unpack_directory(filename, extract_dir, progress_filter=default_filter): + """"Unpack" a directory, using the same interface as for archives + + Raises ``UnrecognizedFormat`` if `filename` is not a directory + """ + if not os.path.isdir(filename): + raise UnrecognizedFormat("%s is not a directory" % (filename,)) + + paths = {filename:('',extract_dir)} + for base, dirs, files in os.walk(filename): + src,dst = paths[base] + for d in dirs: + paths[os.path.join(base,d)] = src+d+'/', os.path.join(dst,d) + for f in files: + name = src+f + target = os.path.join(dst,f) + target = progress_filter(src+f, target) + if not target: + continue # skip non-files + ensure_directory(target) + shutil.copyfile(os.path.join(base,f), target) + + + + + + + + + + + + + + + + + + + + def unpack_zipfile(filename, extract_dir, progress_filter=default_filter): """Unpack zip `filename` to `extract_dir` @@ -156,7 +197,7 @@ def unpack_tarfile(filename, extract_dir, progress_filter=default_filter): -extraction_drivers = unpack_zipfile, unpack_tarfile +extraction_drivers = unpack_directory, unpack_zipfile, unpack_tarfile |