diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2014-06-27 08:39:15 +0300 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2014-11-14 14:22:08 +0200 |
commit | 293e7e28937cf24dec690510fe011f1ab2e0236c (patch) | |
tree | b590d204f1cf7d86eff9b2e00c5df0381721ab90 /tests | |
parent | 37256761982d7f4c39e76d33140eb7467b7a3094 (diff) | |
download | git-buildpackage-293e7e28937cf24dec690510fe011f1ab2e0236c.tar.gz git-buildpackage-293e7e28937cf24dec690510fe011f1ab2e0236c.tar.bz2 git-buildpackage-293e7e28937cf24dec690510fe011f1ab2e0236c.zip |
tests/testutils: add directories arg to ls_* functions
With this you can exclude directories from the listing returned by the
ls_tar(), ls_zip() and ls_dir() functions.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testutils.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/tests/testutils.py b/tests/testutils.py index ce0c20c8..6331e12d 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -115,34 +115,35 @@ def get_dch_default_urgency(): shutil.rmtree(tempdir) return urgency -def ls_dir(directory): +def ls_dir(directory, directories=True): """List the contents of directory, recurse to subdirectories""" contents = set() for root, dirs, files in os.walk(directory): prefix = '' if root != directory: prefix = os.path.relpath(root, directory) + '/' - contents.update(['%s%s' % (prefix, fname) for fname in files] + - ['%s%s' % (prefix, dname) for dname in dirs]) + contents.update(['%s%s' % (prefix, fname) for fname in files]) + if directories: + contents.update(['%s%s' % (prefix, dname) for dname in dirs]) return contents -def ls_tar(tarball): +def ls_tar(tarball, directories=True): """List the contents of tar archive""" tmpdir = tempfile.mkdtemp() try: tarobj = tarfile.open(tarball, 'r') tarobj.extractall(tmpdir) - return ls_dir(tmpdir) + return ls_dir(tmpdir, directories) finally: shutil.rmtree(tmpdir) -def ls_zip(archive): +def ls_zip(archive, directories=True): """List the contents of zip file""" tmpdir = tempfile.mkdtemp() try: zipobj = zipfile.ZipFile(archive, 'r') zipobj.extractall(tmpdir) - return ls_dir(tmpdir) + return ls_dir(tmpdir, directories) finally: shutil.rmtree(tmpdir) |