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:
status = self.api.project_status(staging)
rebuilt = self.api.rebuild_broken(status, not force)
for key, code in rebuilt.items():
for key, code in rebuilt:
print('rebuild {} {}'.format(key, code))

View File

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