From: Philipp Gesang Date: Fri, 31 Mar 2017 14:37:43 +0000 (+0200) Subject: rename open_index to open_auxiliary_file X-Git-Tag: v2.2~7^2~197 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=9eccb1c25ca01d7134f0b7b8816237d01e972afa;p=python-delta-tar rename open_index to open_auxiliary_file We need a more neutral name since the functionality is accessed elsewhere to write the info file too. --- diff --git a/deltatar/deltatar.py b/deltatar/deltatar.py index d4169a1..924c134 100644 --- a/deltatar/deltatar.py +++ b/deltatar/deltatar.py @@ -56,6 +56,9 @@ PARENT_MATCH = 2 # suchlike). PDTCRYPT_EXTENSION = "pdtcrypt" +AUXILIARY_FILE_INDEX = 0 +AUXILIARY_FILE_INFO = 1 + class DeltaTar(object): ''' Backup class used to create backups @@ -493,15 +496,15 @@ class DeltaTar(object): return path[len(prefix):] return path - def open_index(self, path, mode='r', kind="index"): + def open_auxiliary_file(self, path, mode='r', kind=AUXILIARY_FILE_INDEX): ''' - Given the specified configuration, opens the index for reading or - writing. It transparently handles if the index is encrypted and/or - compressed, returning a file object ready to use. + Given the specified configuration, opens a file for reading or writing, + inheriting the encryption and compression settings from the backup. + Returns a file object ready to use. - :param kind: Role of file. The only special value is “info” - which sets the appropriate counter in the crypto - layer. + :param kind: Role of the file, see AUXILIARY_FILE_* constants. The + only special value is AUXILIARY_FILE_INFO which + sets the appropriate counter in the crypto layer. :type kind: str ''' if self.index_mode.startswith('gz'): @@ -513,7 +516,7 @@ class DeltaTar(object): encver = None counter = None - if self.crypto_ctx is not None and kind == "info": + if self.crypto_ctx is not None and kind == AUXILIARY_FILE_INFO: counter = crypto.AES_GCM_IV_CNT_INFOFILE return tarfile._Stream(name=path, mode=mode, comptype=comptype, @@ -596,7 +599,7 @@ class DeltaTar(object): # init index index_name = self.index_name_func(True) index_path = os.path.join(backup_path, index_name) - index_fd = self.open_index(index_path, 'w') # **NOT** an fd + index_fd = self.open_auxiliary_file(index_path, 'w') # **NOT** an fd if index_fd.encryption is not None: self.nacl = index_fd.encryption.nacl @@ -760,7 +763,7 @@ class DeltaTar(object): # init index index_name = self.index_name_func(is_full=False) index_path = os.path.join(backup_path, index_name) - index_fd = self.open_index(index_path, 'w') # **NOT** an fd + index_fd = self.open_auxiliary_file(index_path, 'w') # **NOT** an fd if index_fd.encryption is not None: self.nacl = index_fd.encryption.nacl @@ -925,7 +928,7 @@ class DeltaTar(object): Allows this iterator to be used with the "with" statement ''' if self.f is None: - self.f = self.delta_tar.open_index(self.index_path, 'r') + self.f = self.delta_tar.open_auxiliary_file(self.index_path, 'r') # check index header j, l_no = self.delta_tar._parse_json_line(self.f, 0) if j.get("type", '') != 'python-delta-tar-index' or\ diff --git a/testing/test_deltatar.py b/testing/test_deltatar.py index 77c7195..9b4cc92 100644 --- a/testing/test_deltatar.py +++ b/testing/test_deltatar.py @@ -389,7 +389,7 @@ class DeltaTarTest(BaseTest): index_path = os.path.join("backup_dir", index_filename) # this should automatically restore the huge file - f = deltatar.open_index(index_path, 'r') + f = deltatar.open_auxiliary_file(index_path, 'r') offset = None while True: l = f.readline()