From 45885095198f5ec1d7e80791a73c7385f2620b38 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Tue, 6 Dec 2005 03:12:48 +0000 Subject: 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. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041617 --- setuptools.txt | 4 ++++ 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 -- cgit v1.2.1