[Python-checkins] commit of r41617 - in sandbox/trunk/setuptools: setuptools.txt setuptools/archive_util.py
phillip.eby
python-checkins at python.org
Tue Dec 6 04:12:53 CET 2005
Author: phillip.eby
Date: Tue Dec 6 04:12:48 2005
New Revision: 41617
Modified:
sandbox/trunk/setuptools/setuptools.txt
sandbox/trunk/setuptools/setuptools/archive_util.py
Log:
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.
Modified: sandbox/trunk/setuptools/setuptools.txt
==============================================================================
--- sandbox/trunk/setuptools/setuptools.txt (original)
+++ sandbox/trunk/setuptools/setuptools.txt Tue Dec 6 04:12:48 2005
@@ -2177,6 +2177,10 @@
* 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.
Modified: sandbox/trunk/setuptools/setuptools/archive_util.py
==============================================================================
--- sandbox/trunk/setuptools/setuptools/archive_util.py (original)
+++ sandbox/trunk/setuptools/setuptools/archive_util.py Tue Dec 6 04:12:48 2005
@@ -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_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 @@
-extraction_drivers = unpack_zipfile, unpack_tarfile
+extraction_drivers = unpack_directory, unpack_zipfile, unpack_tarfile
More information about the Python-checkins
mailing list