1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-23 13:31:48 +01:00

- refactored request diff code

This commit is contained in:
Marcus Huewe 2011-01-29 17:24:45 +01:00
parent 89ceb20abb
commit 68d559e343
2 changed files with 41 additions and 52 deletions

View File

@ -1896,34 +1896,22 @@ Please submit there instead, or use --nodevelproject to force direct submission.
'request type: \'%s\'' % r.actions[0].type)
print 'Buildstatus for \'%s/%s\':' % (r.actions[0].src_project, r.actions[0].src_package)
print '\n'.join(get_results(apiurl, r.actions[0].src_project, r.actions[0].src_package))
# FIXME: will inevitably fail if the given target doesn't exist
# FIXME: diff should work if there are submit actions anyway
if opts.diff and r.actions[0].type != 'submit':
raise oscerr.WrongOptions('\'--diff\' is not possible for request type: \'%s\'' % r.actions[0].type)
elif opts.diff:
rdiff = ''
if opts.diff:
diff = ''
try:
# works since OBS 2.1
rdiff = request_diff(apiurl, reqid)
diff = request_diff(apiurl, reqid)
except urllib2.HTTPError, e:
# for OBS 2.0 and before
try:
rdiff = server_diff(apiurl,
r.actions[0].tgt_project, r.actions[0].tgt_package, None,
r.actions[0].src_project, r.actions[0].src_package, r.actions[0].src_rev, opts.unified, True)
except urllib2.HTTPError, e:
if e.code != 400:
e.osc_msg = 'Diff not possible'
raise e
# backward compatiblity: only a recent api/backend supports the missingok parameter
try:
rdiff = server_diff(apiurl,
r.actions[0].tgt_project, r.actions[0].tgt_package, None,
r.actions[0].src_project, r.actions[0].src_package, r.actions[0].src_rev, opts.unified, False)
except urllib2.HTTPError, e:
e.osc_msg = 'Diff not possible'
raise
run_pager(rdiff)
sr_actions = [i for i in r.actions if i.type == 'submit']
if not sr_actions:
raise oscerr.WrongOptions('\'--diff\' not possible (request has no \'submit\' actions)')
for action in sr_actions:
diff += 'old: %s/%s\nnew: %s/%s\n' % (action.src_project, action.src_package,
action.tgt_project, action.tgt_package)
diff += submit_action_diff(apiurl, action)
diff += '\n\n'
run_pager(diff)
# checkout
elif cmd == 'checkout' or cmd == 'co':

View File

@ -3957,6 +3957,26 @@ def request_diff(apiurl, reqid):
f = http_POST(u)
return f.read()
def submit_action_diff(apiurl, action):
"""diff a single submit action"""
# backward compatiblity: only a recent api/backend supports the missingok parameter
try:
return server_diff(apiurl, action.tgt_project, action.tgt_package, None,
action.src_project, action.src_package, action.src_rev, True, True)
except urllib2.HTTPError, e:
if e.code == 400:
try:
return server_diff(apiurl, action.tgt_project, action.tgt_package, None,
action.src_project, action.src_package, action.src_rev, True, False)
except urllib2.HTTPError, e:
if e.code != 404:
raise e
root = ET.fromstring(e.read())
return 'error: \'%s\' does not exist' % root.find('summary').text
elif e.code == 404:
root = ET.fromstring(e.read())
return 'error: \'%s\' does not exist' % root.find('summary').text
raise e
def make_dir(apiurl, project, package, pathname=None, prj_dir=None, package_tracking=True):
"""
@ -5892,39 +5912,20 @@ def request_interactive_review(apiurl, request):
print_request(request)
try:
msg = '(a)ccept/(d)ecline/(r)evoke/(b)uildstatus/c(l)one/(s)kip/(c)ancel > '
if request.actions[0].type == 'submit':
sr_actions = [i for i in request.actions if i.type == 'submit']
if sr_actions:
msg = 'd(i)ff/%s' % msg
while True:
repl = raw_input(msg).strip()
if repl == 'i' and request.actions[0].type == 'submit':
if repl == 'i' and sr_actions:
if tmpfile is None:
tmpfile = tempfile.NamedTemporaryFile()
# backward compatiblity: only a recent api/backend supports the missingok parameter
try:
diff = server_diff(apiurl, request.actions[0].tgt_project, request.actions[0].tgt_package, None,
request.actions[0].src_project, request.actions[0].src_package, request.actions[0].src_rev, True, True)
except urllib2.HTTPError, e:
if e.code == 400:
try:
diff = server_diff(apiurl, request.actions[0].tgt_project, request.actions[0].tgt_package, None,
request.actions[0].src_project, request.actions[0].src_package, request.actions[0].src_rev, True, False)
except urllib2.HTTPError, e:
tmpfile.close()
tmpfile = None
if e.code != 404:
raise e
root = ET.fromstring(e.read())
print >>sys.stderr, root.find('summary').text
continue
elif e.code == 404:
tmpfile.close()
tmpfile = None
root = ET.fromstring(e.read())
print >>sys.stderr, root.find('summary').text
continue
else:
raise e
tmpfile.write(diff)
for action in sr_actions:
diff = 'old: %s/%s\nnew: %s/%s\n' % (action.src_project, action.src_package,
action.tgt_project, action.tgt_package)
diff += submit_action_diff(apiurl, action)
diff += '\n\n'
tmpfile.write(diff)
tmpfile.flush()
run_editor(tmpfile.name)
print_request(request)