mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Added exclude keyword argument to the TarFile.add() method.
This commit is contained in:
parent
9d0476f7da
commit
104490e615
4 changed files with 39 additions and 7 deletions
|
@ -558,6 +558,27 @@ class WriteTest(unittest.TestCase):
|
|||
os.chdir(cwd)
|
||||
self.assert_(tar.getnames() == [], "added the archive to itself")
|
||||
|
||||
def test_exclude(self):
|
||||
tempdir = os.path.join(TEMPDIR, "exclude")
|
||||
os.mkdir(tempdir)
|
||||
try:
|
||||
for name in ("foo", "bar", "baz"):
|
||||
name = os.path.join(tempdir, name)
|
||||
open(name, "wb").close()
|
||||
|
||||
def exclude(name):
|
||||
return os.path.isfile(name)
|
||||
|
||||
tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
|
||||
tar.add(tempdir, arcname="empty_dir", exclude=exclude)
|
||||
tar.close()
|
||||
|
||||
tar = tarfile.open(tmpname, "r")
|
||||
self.assertEqual(len(tar.getmembers()), 1)
|
||||
self.assertEqual(tar.getnames()[0], "empty_dir")
|
||||
finally:
|
||||
shutil.rmtree(tempdir)
|
||||
|
||||
|
||||
class StreamWriteTest(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue