Commit 45885095 authored by PJ Eby's avatar PJ Eby

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
parent c8e2cdfc
...@@ -2177,6 +2177,10 @@ Release Notes/Change History ...@@ -2177,6 +2177,10 @@ Release Notes/Change History
* Made all commands that use ``easy_install`` respect its configuration * Made all commands that use ``easy_install`` respect its configuration
options, as this was causing some problems with ``setup.py install``. 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 0.6a8
* Fixed some problems building extensions when Pyrex was installed, especially * Fixed some problems building extensions when Pyrex was installed, especially
with Python 2.4 and/or packages using SWIG. with Python 2.4 and/or packages using SWIG.
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
__all__ = [ __all__ = [
"unpack_archive", "unpack_zipfile", "unpack_tarfile", "default_filter", "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 pkg_resources import ensure_directory
from distutils.errors import DistutilsError from distutils.errors import DistutilsError
...@@ -80,6 +80,47 @@ def unpack_archive(filename, extract_dir, progress_filter=default_filter, ...@@ -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): def unpack_zipfile(filename, extract_dir, progress_filter=default_filter):
"""Unpack zip `filename` to `extract_dir` """Unpack zip `filename` to `extract_dir`
...@@ -156,7 +197,7 @@ def unpack_tarfile(filename, extract_dir, progress_filter=default_filter): ...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment