mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
progress: hide progress bar when --quiet
We want progress bars in the default output mode, but not when the user specifies --quiet. Add a setting to the Progress bar class so it takes care of not displaying anything itself rather than having to update every subcommand to conditionally setup & call the object. Change-Id: I1134993bffc5437bc22e26be11a512125f10597f Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/303225 Reviewed-by: Raman Tenneti <rtenneti@google.com> Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
parent
9180a07b8f
commit
151701e85f
10
progress.py
10
progress.py
@ -42,7 +42,8 @@ def duration_str(total):
|
|||||||
|
|
||||||
|
|
||||||
class Progress(object):
|
class Progress(object):
|
||||||
def __init__(self, title, total=0, units='', print_newline=False, delay=True):
|
def __init__(self, title, total=0, units='', print_newline=False, delay=True,
|
||||||
|
quiet=False):
|
||||||
self._title = title
|
self._title = title
|
||||||
self._total = total
|
self._total = total
|
||||||
self._done = 0
|
self._done = 0
|
||||||
@ -54,6 +55,13 @@ class Progress(object):
|
|||||||
self._show_jobs = False
|
self._show_jobs = False
|
||||||
self._active = 0
|
self._active = 0
|
||||||
|
|
||||||
|
# When quiet, never show any output. It's a bit hacky, but reusing the
|
||||||
|
# existing logic that delays initial output keeps the rest of the class
|
||||||
|
# clean. Basically we set the start time to years in the future.
|
||||||
|
if quiet:
|
||||||
|
self._show = False
|
||||||
|
self._start += 2**32
|
||||||
|
|
||||||
def start(self, name):
|
def start(self, name):
|
||||||
self._active += 1
|
self._active += 1
|
||||||
if not self._show_jobs:
|
if not self._show_jobs:
|
||||||
|
@ -81,7 +81,7 @@ It is equivalent to "git branch -D <branchname>".
|
|||||||
err[branch].append(project)
|
err[branch].append(project)
|
||||||
pm.update()
|
pm.update()
|
||||||
|
|
||||||
pm = Progress('Abandon %s' % nb, len(all_projects))
|
pm = Progress('Abandon %s' % nb, len(all_projects), quiet=opt.quiet)
|
||||||
# NB: Multiprocessing is heavy, so don't spin it up for one job.
|
# NB: Multiprocessing is heavy, so don't spin it up for one job.
|
||||||
if len(all_projects) == 1 or opt.jobs == 1:
|
if len(all_projects) == 1 or opt.jobs == 1:
|
||||||
_ProcessResults(self._ExecuteOne(opt, nb, x) for x in all_projects)
|
_ProcessResults(self._ExecuteOne(opt, nb, x) for x in all_projects)
|
||||||
|
@ -59,7 +59,7 @@ The command is equivalent to:
|
|||||||
err.append(project)
|
err.append(project)
|
||||||
pm.update()
|
pm.update()
|
||||||
|
|
||||||
pm = Progress('Checkout %s' % nb, len(all_projects))
|
pm = Progress('Checkout %s' % nb, len(all_projects), quiet=opt.quiet)
|
||||||
# NB: Multiprocessing is heavy, so don't spin it up for one job.
|
# NB: Multiprocessing is heavy, so don't spin it up for one job.
|
||||||
if len(all_projects) == 1 or opt.jobs == 1:
|
if len(all_projects) == 1 or opt.jobs == 1:
|
||||||
_ProcessResults(self._ExecuteOne(nb, x) for x in all_projects)
|
_ProcessResults(self._ExecuteOne(nb, x) for x in all_projects)
|
||||||
|
@ -106,7 +106,7 @@ revision specified in the manifest.
|
|||||||
if not os.path.exists(os.getcwd()):
|
if not os.path.exists(os.getcwd()):
|
||||||
os.chdir(self.manifest.topdir)
|
os.chdir(self.manifest.topdir)
|
||||||
|
|
||||||
pm = Progress('Syncing %s' % nb, len(all_projects))
|
pm = Progress('Syncing %s' % nb, len(all_projects), quiet=opt.quiet)
|
||||||
for project in all_projects:
|
for project in all_projects:
|
||||||
gitc_project = self.gitc_manifest.paths[project.relpath]
|
gitc_project = self.gitc_manifest.paths[project.relpath]
|
||||||
# Sync projects that have not been opened.
|
# Sync projects that have not been opened.
|
||||||
@ -129,7 +129,7 @@ revision specified in the manifest.
|
|||||||
err.append(project)
|
err.append(project)
|
||||||
pm.update()
|
pm.update()
|
||||||
|
|
||||||
pm = Progress('Starting %s' % nb, len(all_projects))
|
pm = Progress('Starting %s' % nb, len(all_projects), quiet=opt.quiet)
|
||||||
# NB: Multiprocessing is heavy, so don't spin it up for one job.
|
# NB: Multiprocessing is heavy, so don't spin it up for one job.
|
||||||
if len(all_projects) == 1 or opt.jobs == 1:
|
if len(all_projects) == 1 or opt.jobs == 1:
|
||||||
_ProcessResults(self._ExecuteOne(opt, nb, x) for x in all_projects)
|
_ProcessResults(self._ExecuteOne(opt, nb, x) for x in all_projects)
|
||||||
|
@ -367,7 +367,7 @@ later is required to fix a server side protocol bug.
|
|||||||
|
|
||||||
jobs = opt.jobs_network if opt.jobs_network else self.jobs
|
jobs = opt.jobs_network if opt.jobs_network else self.jobs
|
||||||
fetched = set()
|
fetched = set()
|
||||||
pm = Progress('Fetching', len(projects), delay=False)
|
pm = Progress('Fetching', len(projects), delay=False, quiet=opt.quiet)
|
||||||
|
|
||||||
objdir_project_map = dict()
|
objdir_project_map = dict()
|
||||||
for project in projects:
|
for project in projects:
|
||||||
@ -470,7 +470,7 @@ later is required to fix a server side protocol bug.
|
|||||||
# Only checkout projects with worktrees.
|
# Only checkout projects with worktrees.
|
||||||
all_projects = [x for x in all_projects if x.worktree]
|
all_projects = [x for x in all_projects if x.worktree]
|
||||||
|
|
||||||
pm = Progress('Checking out', len(all_projects))
|
pm = Progress('Checking out', len(all_projects), quiet=opt.quiet)
|
||||||
|
|
||||||
def _ProcessResults(results):
|
def _ProcessResults(results):
|
||||||
for (success, project, start, finish) in results:
|
for (success, project, start, finish) in results:
|
||||||
@ -504,7 +504,7 @@ later is required to fix a server side protocol bug.
|
|||||||
return ret and not err_results
|
return ret and not err_results
|
||||||
|
|
||||||
def _GCProjects(self, projects, opt, err_event):
|
def _GCProjects(self, projects, opt, err_event):
|
||||||
pm = Progress('Garbage collecting', len(projects), delay=False)
|
pm = Progress('Garbage collecting', len(projects), delay=False, quiet=opt.quiet)
|
||||||
pm.update(inc=0, msg='prescan')
|
pm.update(inc=0, msg='prescan')
|
||||||
|
|
||||||
gc_gitdirs = {}
|
gc_gitdirs = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user