Skip to content

Commit

Permalink
- request_interactive_review: support "-f" parameter to force a reque…
Browse files Browse the repository at this point in the history
…st state change
  • Loading branch information
marcus-h committed Oct 26, 2012
1 parent 6c5806c commit b8dedd3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
6 changes: 4 additions & 2 deletions osc/commandline.py
Expand Up @@ -2033,7 +2033,8 @@ def do_request(self, subcmd, opts, *args):
for result in results:
if days == 0 or result.state.when > since or result.state.name == 'new':
if (opts.interactive or conf.config['request_show_interactive']) and not opts.non_interactive:
request_interactive_review(apiurl, result, group=opts.group)
ignore_reviews = subcmd != 'review'
request_interactive_review(apiurl, result, group=opts.group, ignore_reviews=ignore_reviews)
else:
print result.list_view(), '\n'
else:
Expand Down Expand Up @@ -2071,7 +2072,8 @@ def do_request(self, subcmd, opts, *args):
'(request has no \'submit\' action)')
return request_interactive_review(apiurl, r, 'e')
elif (opts.interactive or conf.config['request_show_interactive']) and not opts.non_interactive:
return request_interactive_review(apiurl, r, group=opts.group)
ignore_reviews = subcmd != 'review'
return request_interactive_review(apiurl, r, group=opts.group, ignore_reviews=ignore_reviews)
else:
print r
if opts.source_buildstatus:
Expand Down
33 changes: 24 additions & 9 deletions osc/core.py
Expand Up @@ -6118,12 +6118,21 @@ def print_request_list(apiurl, project, package = None, states = ('new','review'
for r in requests:
print r.list_view(), '\n'

def request_interactive_review(apiurl, request, initial_cmd='', group=None):
def request_interactive_review(apiurl, request, initial_cmd='', group=None, ignore_reviews=False):
"""review the request interactively"""
import tempfile, re

tmpfile = None

def safe_change_request_state(*args, **kwargs):
try:
change_request_state(*args, **kwargs)
return True
except urllib2.HTTPError, e:
print >>sys.stderr, 'Server returned an error:', e
print >>sys.stderr, 'Try -f to force the state change'
return False

def print_request(request):
print request

Expand Down Expand Up @@ -6189,12 +6198,13 @@ def print_request(request):
prompt = 'd(i)ff/(a)ccept/(b)uildstatus/(e)dit/(s)kip/(c)ancel > '
else:
state_map = {'a': 'accepted', 'd': 'declined', 'r': 'revoked'}
mo = re.search('^([adrl])(?:\s+-m\s+(.*))?$', repl)
mo = re.search('^([adrl])(?:\s+(-f)?\s*-m\s+(.*))?$', repl)
if mo is None or orequest and mo.group(1) != 'a':
print >>sys.stderr, 'invalid choice: \'%s\'' % repl
continue
state = state_map.get(mo.group(1))
msg = mo.group(2)
force = mo.group(2) is not None
msg = mo.group(3)
footer = ''
msg_template = ''
if not (state is None or request.state is None):
Expand All @@ -6216,18 +6226,23 @@ def print_request(request):
msg = msg.strip('\'').strip('"')
if not orequest is None:
request.create(apiurl)
change_request_state(apiurl, request.reqid, 'accepted', msg)
if not safe_change_request_state(apiurl, request.reqid, 'accepted', msg, force=force):
# an error occured
continue
repl = raw_input('Supersede original request? (y|N) ')
if repl in ('y', 'Y'):
change_request_state(apiurl, orequest.reqid, 'superseded',
'superseded by %s' % request.reqid, request.reqid)
safe_change_request_state(apiurl, orequest.reqid, 'superseded',
'superseded by %s' % request.reqid, request.reqid, force=force)
elif state is None:
clone_request(apiurl, request.reqid, msg)
else:
reviews = [r for r in request.reviews if r.state == 'new']
if not reviews:
change_request_state(apiurl, request.reqid, state, msg)
break
if not reviews or ignore_reviews:
if safe_change_request_state(apiurl, request.reqid, state, msg, force=force):
break
else:
# an error occured
continue
group_reviews = [r for r in reviews if (r.by_group is not None
and r.by_group == group)]
if len(group_reviews) == 1 and conf.config['review_inherit_group']:
Expand Down

0 comments on commit b8dedd3

Please sign in to comment.