implement --progress option for borg upgrade, fixes #291

This commit is contained in:
Thomas Waldmann 2016-01-16 20:32:24 +01:00
parent e68b800d01
commit 0213164d46
2 changed files with 11 additions and 6 deletions

View File

@ -520,7 +520,7 @@ class Archiver:
# XXX: should auto-detect if it is an attic repository here
repo = AtticRepositoryUpgrader(args.location.path, create=False)
try:
repo.upgrade(args.dry_run, inplace=args.inplace)
repo.upgrade(args.dry_run, inplace=args.inplace, progress=args.progress)
except NotImplementedError as e:
print("warning: %s" % e)
return self.exit_code
@ -1156,6 +1156,9 @@ class Archiver:
epilog=upgrade_epilog,
formatter_class=argparse.RawDescriptionHelpFormatter)
subparser.set_defaults(func=self.do_upgrade)
subparser.add_argument('-p', '--progress', dest='progress',
action='store_true', default=False,
help="""show progress display while upgrading the repository""")
subparser.add_argument('-n', '--dry-run', dest='dry_run',
default=False, action='store_true',
help='do not change repository')

View File

@ -20,7 +20,7 @@ class AtticRepositoryUpgrader(Repository):
kw['lock'] = False # do not create borg lock files (now) in attic repo
super().__init__(*args, **kw)
def upgrade(self, dryrun=True, inplace=False):
def upgrade(self, dryrun=True, inplace=False, progress=False):
"""convert an attic repository to a borg repository
those are the files that need to be upgraded here, from most
@ -54,7 +54,7 @@ class AtticRepositoryUpgrader(Repository):
try:
self.convert_cache(dryrun)
self.convert_repo_index(dryrun=dryrun, inplace=inplace)
self.convert_segments(segments, dryrun=dryrun, inplace=inplace)
self.convert_segments(segments, dryrun=dryrun, inplace=inplace, progress=progress)
self.borg_readme()
finally:
self.lock.release()
@ -68,7 +68,7 @@ class AtticRepositoryUpgrader(Repository):
fd.write('This is a Borg repository\n')
@staticmethod
def convert_segments(segments, dryrun=True, inplace=False):
def convert_segments(segments, dryrun=True, inplace=False, progress=False):
"""convert repository segments from attic to borg
replacement pattern is `s/ATTICSEG/BORG_SEG/` in files in
@ -80,12 +80,14 @@ class AtticRepositoryUpgrader(Repository):
segment_count = len(segments)
pi = ProgressIndicatorPercent(total=segment_count, msg="Converting segments %3.0f%%", same_line=True)
for i, filename in enumerate(segments):
pi.show(i)
if progress:
pi.show(i)
if dryrun:
time.sleep(0.001)
else:
AtticRepositoryUpgrader.header_replace(filename, ATTIC_MAGIC, MAGIC, inplace=inplace)
pi.finish()
if progress:
pi.finish()
@staticmethod
def header_replace(filename, old_magic, new_magic, inplace=True):