From 50f8042ba944608070ad2105d8619bf289baa1ef Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Thu, 20 Apr 2017 23:10:05 -0500 Subject: [PATCH] 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. --- osclib/rebuild_command.py | 2 +- osclib/stagingapi.py | 32 +++++++++++++------------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/osclib/rebuild_command.py b/osclib/rebuild_command.py index defe3105..0ae7fb41 100644 --- a/osclib/rebuild_command.py +++ b/osclib/rebuild_command.py @@ -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)) diff --git a/osclib/stagingapi.py b/osclib/stagingapi.py index 53551f89..a9b603e3 100644 --- a/osclib/stagingapi.py +++ b/osclib/stagingapi.py @@ -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)