From 5368092db5c486e312bcd8d83b986fdf93dcc000 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 23 Apr 2020 13:53:55 +0200 Subject: [PATCH] add support for PDT encryption to run_benchmark.py The script was still expecting the encryption to be handled in the pre-crypto.py fashion. Paths need some preparing as well so we can inject a deltatar from arbitrary locations; the $DELTATAR environment variable is used for this. --- deltatar/__init__.py | 4 +++- testing/run_benchmark.py | 42 +++++++++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/deltatar/__init__.py b/deltatar/__init__.py index 8d1c8b6..3d91d64 100644 --- a/deltatar/__init__.py +++ b/deltatar/__init__.py @@ -1 +1,3 @@ - +from . import crypto +from . import tarfile +from . import deltatar diff --git a/testing/run_benchmark.py b/testing/run_benchmark.py index d7a0083..18114d1 100755 --- a/testing/run_benchmark.py +++ b/testing/run_benchmark.py @@ -25,6 +25,7 @@ import zlib import fnmatch import cProfile import io +import binascii import pstats @@ -88,21 +89,44 @@ def main(args = None): 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): -- 1.7.1