Skip to content

Commit

Permalink
Merge pull request #714 from jberry-suse/rebuild-command
Browse files Browse the repository at this point in the history
osc-staging: provide rebuild command.
  • Loading branch information
lnussel committed Mar 10, 2017
2 parents 0bf2d43 + 13b7ae9 commit 0a3f07e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions osc-staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from osclib.cache import Cache
from osclib.unselect_command import UnselectCommand
from osclib.repair_command import RepairCommand
from osclib.rebuild_command import RebuildCommand
from osclib.request_splitter import RequestSplitter

OSC_STAGING_VERSION = '0.0.1'
Expand Down Expand Up @@ -205,6 +206,8 @@ def do_staging(self, subcmd, opts, *args):
"unlock" will remove the staging lock in case it gets stuck
"rebuild" will rebuild broken packages in the given stagings or all
Usage:
osc staging accept [--force] [--no-cleanup] [LETTER...]
osc staging acheck
Expand All @@ -223,6 +226,7 @@ def do_staging(self, subcmd, opts, *args):
[STAGING...] [REQUEST...]
osc staging unselect REQUEST...
osc staging unlock
osc staging rebuild [STAGING...]
osc staging repair REQUEST...
"""
if opts.version:
Expand Down Expand Up @@ -252,6 +256,8 @@ def do_staging(self, subcmd, opts, *args):
min_args, max_args = 0, 0
elif cmd == 'unlock':
min_args, max_args = 0, 0
elif cmd == 'rebuild':
min_args, max_args = 0, None
else:
raise oscerr.WrongArgs('Unknown command: %s' % cmd)
if len(args) - 1 < min_args:
Expand Down Expand Up @@ -466,5 +472,7 @@ def do_staging(self, subcmd, opts, *args):
ListCommand(api).perform(args[1:], supersede=opts.supersede)
elif cmd == 'adi':
AdiCommand(api).perform(args[1:], move=opts.move, by_dp=opts.by_develproject, split=opts.split)
elif cmd == 'rebuild':
RebuildCommand(api).perform(args[1:])
elif cmd == 'repair':
RepairCommand(api).perform(args[1:])
17 changes: 17 additions & 0 deletions osclib/rebuild_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from osc.core import get_request
from osclib.comments import CommentAPI


class RebuildCommand(object):
def __init__(self, api):
self.api = api

def perform(self, stagings=None):
if not stagings:
stagings = self.api.get_staging_projects_short()

for staging in stagings:
status = self.api.project_status(staging)
rebuilt = self.api.rebuild_broken(status)
for key, code in rebuilt.items():
print('rebuild {} {}'.format(key, code))
17 changes: 17 additions & 0 deletions osclib/stagingapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from osc.core import http_GET
from osc.core import http_POST
from osc.core import http_PUT
from osc.core import rebuild

from osclib.cache import Cache
from osclib.comments import CommentAPI
Expand Down Expand Up @@ -735,6 +736,22 @@ def check_ring_packages(self, project, requests):

return False

def rebuild_broken(self, status):
""" 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()}
code = rebuild(self.apiurl, package['project'], package['package'],
package['repository'], package['arch'])
key = '/'.join((package['project'], package['package'], package['repository'], package['arch']))
rebuilt[key] = code

for project in status['subprojects']:
if project:
rebuilt.update(self.rebuild_broken(project))

return rebuilt

def project_status(self, project):
short = self.extract_staging_short(project)
query = {'format': 'json'}
Expand Down

0 comments on commit 0a3f07e

Please sign in to comment.