stagingapi: convert rebuild_broken to a generator for instant feedback.

Otherwise, the rebuild command does not print output until all the
rebuilds for a whole staging are completed. With this change each package
should be printed immediately.
This commit is contained in:
Jimmy Berry 2017-04-20 23:10:05 -05:00
parent 52d356db29
commit 50f8042ba9
2 changed files with 14 additions and 20 deletions

View File

@ -13,5 +13,5 @@ class RebuildCommand(object):
for staging in stagings: for staging in stagings:
status = self.api.project_status(staging) status = self.api.project_status(staging)
rebuilt = self.api.rebuild_broken(status, not force) rebuilt = self.api.rebuild_broken(status, not force)
for key, code in rebuilt.items(): for key, code in rebuilt:
print('rebuild {} {}'.format(key, code)) print('rebuild {} {}'.format(key, code))

View File

@ -801,26 +801,20 @@ class StagingAPI(object):
def rebuild_broken(self, status, check=True): def rebuild_broken(self, status, check=True):
""" Rebuild broken packages given a staging's status information. """ """ Rebuild broken packages given a staging's status information. """
rebuilt = {} for project in self.project_status_walk(status):
for package in status['broken_packages']: for package in project['broken_packages']:
package = {k: str(v) for k, v in package.items()} package = {k: str(v) for k, v in package.items()}
if package['state'] == 'unresolvable': if package['state'] == 'unresolvable':
continue continue
key = '/'.join((package['project'], package['package'], package['repository'], package['arch'])) key = '/'.join((package['project'], package['package'], package['repository'], package['arch']))
if check and not self.rebuild_check(package['project'], package['package'], if check and not self.rebuild_check(package['project'], package['package'],
package['repository'], package['arch']): package['repository'], package['arch']):
rebuilt[key] = 'skipped' yield (key, 'skipped')
continue continue
code = rebuild(self.apiurl, package['project'], package['package'], code = rebuild(self.apiurl, package['project'], package['package'],
package['repository'], package['arch']) package['repository'], package['arch'])
rebuilt[key] = code yield (key, code)
for project in status['subprojects']:
if project:
rebuilt.update(self.rebuild_broken(project, check))
return rebuilt
def rebuild_check(self, project, package, repository, architecture): def rebuild_check(self, project, package, repository, architecture):
history = self.job_history_get(project, repository, architecture, package) history = self.job_history_get(project, repository, architecture, package)