diff --git a/osc-staging.py b/osc-staging.py index 7e21cd9c..39896d4e 100644 --- a/osc-staging.py +++ b/osc-staging.py @@ -47,6 +47,7 @@ from osclib.unselect_command import UnselectCommand from osclib.repair_command import RepairCommand from osclib.rebuild_command import RebuildCommand from osclib.request_splitter import RequestSplitter +from osclib.prio_command import PrioCommand OSC_STAGING_VERSION = '0.0.1' @@ -237,6 +238,7 @@ def do_staging(self, subcmd, opts, *args): osc staging unlock osc staging rebuild [--force] [STAGING...] osc staging repair REQUEST... + osc staging setprio [STAGING...] """ if opts.version: self._print_version() @@ -249,6 +251,8 @@ def do_staging(self, subcmd, opts, *args): min_args, max_args = 1, None elif cmd == 'frozenage': min_args, max_args = 0, None + elif cmd == 'setprio': + min_args, max_args = 0, 1 elif cmd == 'check': min_args, max_args = 0, 1 elif cmd == 'select': @@ -491,3 +495,5 @@ def do_staging(self, subcmd, opts, *args): RebuildCommand(api).perform(args[1:], opts.force) elif cmd == 'repair': RepairCommand(api).perform(args[1:]) + elif cmd == 'setprio': + PrioCommand(api).perform(args[1:]) diff --git a/osclib/prio_command.py b/osclib/prio_command.py new file mode 100644 index 00000000..2f688213 --- /dev/null +++ b/osclib/prio_command.py @@ -0,0 +1,71 @@ +# Copyright (C) 2016,2017 SUSE LLC +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import json +import osc +import urllib2 + +class PrioCommand(object): + def __init__(self, api): + self.api = api + + def _setprio(self, project): + """ + Set prios for requests that are still in review + :param project: project to check + + """ + + # XXX taking name verbatim would produce null byte error + # https://github.com/openSUSE/open-build-service/issues/2493 + message = 'raising priority for %s'%str(project['name']) + for r in project['missing_reviews']: + reqid = str(r['request']) + req = osc.core.get_request(self.api.apiurl, reqid) + priority = req.priority + if priority is None: + priority = 'important' + query = { 'cmd': 'setpriority', 'priority': priority } + url = osc.core.makeurl(self.api.apiurl, ['request', reqid], query) + print reqid, message + try: + osc.core.http_POST(url, data=message) + print reqid, r['by'], priority + except urllib2.HTTPError, e: + print e + + + def perform(self, project=None): + """ + Check one staging project verbosibly or all of them at once + :param project: project to check, None for all + """ + + query = {'format': 'json'} + path = [ 'project', 'staging_projects', self.api.project ] + if project: + path += project + url = self.api.makeurl(path, query=query) + info = json.load(self.api.retried_GET(url)) + if not project: + for prj in info: + if not prj['selected_requests']: + continue + self._setprio(prj) + else: + self._setprio(info) + + return True