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-06-30 18:28:22 +0300 |
commit | 44ead55d0638ba3eebd730f249bbc7f209119848 (patch) | |
tree | e707b05a5f965d78cdbd9c363241ad9eb7ed55ed | |
parent | 8ada32322e53fb820b2ee3e18b7a2cc22e78322a (diff) | |
download | git-buildpackage-44ead55d0638ba3eebd730f249bbc7f209119848.tar.gz git-buildpackage-44ead55d0638ba3eebd730f249bbc7f209119848.tar.bz2 git-buildpackage-44ead55d0638ba3eebd730f249bbc7f209119848.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.
Change-Id: I8d586489a277c227a7fb61801e0b774f11e7a67e
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-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 587c273b..7cc7e361 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -119,34 +119,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) |