style fixes (pep8, append, file builtin)

This commit is contained in:
Antoine Beaupré 2015-10-03 11:49:01 -04:00
parent 3773681f00
commit 690541264e
1 changed files with 13 additions and 11 deletions

View File

@ -10,6 +10,7 @@ from .key import KeyfileKey, KeyfileNotFoundError
ATTIC_MAGIC = b'ATTICSEG'
class AtticRepositoryConverter(Repository):
def convert(self, dryrun=True):
"""convert an attic repository to a borg repository
@ -143,28 +144,29 @@ class AtticRepositoryConverter(Repository):
# copy of attic's get_cache_dir()
attic_cache_dir = os.environ.get('ATTIC_CACHE_DIR',
os.path.join(os.path.expanduser('~'), '.cache', 'attic'))
os.path.join(os.path.expanduser('~'),
'.cache', 'attic'))
attic_cache_dir = os.path.join(attic_cache_dir, hexlify(self.id).decode('ascii'))
borg_cache_dir = os.path.join(get_cache_dir(), hexlify(self.id).decode('ascii'))
def copy_cache_file(file):
"""copy the given attic cache file into the borg directory
def copy_cache_file(path):
"""copy the given attic cache path into the borg directory
does nothing if dryrun is True. also expects
attic_cache_dir and borg_cache_dir to be set in the parent
scope, to the directories path including the repository
identifier.
:params file: the basename of the cache file to copy
:params path: the basename of the cache file to copy
(example: "files" or "chunks") as a string
:returns: the borg file that was created or None if non
was created.
"""
attic_file = os.path.join(attic_cache_dir, file)
attic_file = os.path.join(attic_cache_dir, path)
if os.path.exists(attic_file):
borg_file = os.path.join(borg_cache_dir, file)
borg_file = os.path.join(borg_cache_dir, path)
if os.path.exists(borg_file):
print("borg cache file already exists in %s, skipping conversion of %s" % (borg_file, attic_file))
else:
@ -173,7 +175,7 @@ class AtticRepositoryConverter(Repository):
shutil.copyfile(attic_file, borg_file)
return borg_file
else:
print("no %s cache file found in %s" % (file, attic_file))
print("no %s cache file found in %s" % (path, attic_file))
return None
if os.path.exists(attic_cache_dir):
@ -186,7 +188,7 @@ class AtticRepositoryConverter(Repository):
for cache in ['files', 'chunks']:
copied = copy_cache_file(cache)
if copied:
caches += [copied]
caches.append(copied)
for cache in caches:
print("converting cache %s" % cache)