import fnmatch
import cProfile
import io
+import binascii
import pstats
def test_tarfile(res, compression_level=9, path='source_dir', tarmode="w:gz"):
'''
- Test that creates a tarfile called test_tarfile.tar.gz
+ Test that creates a tarfile called test_tarfile.tar.gz from a directory.
'''
+ encryptor = None
+ dstfile = "test_tarfile.tar.gz"
+
if res == 'delta-tarfile':
- deltatar = os.path.abspath("../deltatar")
import sys
- sys.path.append("..")
- from deltatar import tarfile as TarFile
+ # need to fix up the path before we can load a module explicitly
+ dtarpath = os.getenv ("DELTATAR")
+ if dtarpath is not None:
+ sys.path.append (dtarpath)
+
+ try:
+ from deltatar import tarfile as TarFile
+ from deltatar import crypto
+ except ImportError:
+ raise Exception ("location of deltatar not found; "
+ "set $DELTATAR to provide an explicit path")
+
+ if tarmode.endswith (".pdtcrypt"):
+ dstfile = dstfile + ".pdtcrypt"
+ tarmode = tarmode.rstrip (".pdtcrypt")
+ encryptor = crypto.Encrypt (password="test1234",
+ nacl=binascii.unhexlify(b"0011223344556677"
+ b"8899aabbccddeeff"),
+ version=1,
+ paramversion=1)
+
elif res == 'tarfile':
import tarfile as TarFile
- print("creating a tarfile with mode = '%s'" % tarmode)
- with open('test_tarfile.tar.gz', 'wb') as fo:
- tar = TarFile.open(mode=tarmode, fileobj=fo,
- compresslevel=compression_level)
- tar.add(path)
+ tar = TarFile.open (dstfile,
+ mode=tarmode,
+ concat='#' in tarmode,
+ encryption=encryptor,
+ compresslevel=compression_level)
+ tar.add(path)
+
def test_zlib(compression_level=9, path='source_dir', strategy='default',
BUFSIZE = 16 * 1024):