mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-23 21:36:13 +01:00
- refactored request diff code
This commit is contained in:
parent
89ceb20abb
commit
68d559e343
@ -1896,34 +1896,22 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
'request type: \'%s\'' % r.actions[0].type)
|
'request type: \'%s\'' % r.actions[0].type)
|
||||||
print 'Buildstatus for \'%s/%s\':' % (r.actions[0].src_project, r.actions[0].src_package)
|
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))
|
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
|
if opts.diff:
|
||||||
# FIXME: diff should work if there are submit actions anyway
|
diff = ''
|
||||||
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 = ''
|
|
||||||
try:
|
try:
|
||||||
# works since OBS 2.1
|
# works since OBS 2.1
|
||||||
rdiff = request_diff(apiurl, reqid)
|
diff = request_diff(apiurl, reqid)
|
||||||
except urllib2.HTTPError, e:
|
except urllib2.HTTPError, e:
|
||||||
# for OBS 2.0 and before
|
# for OBS 2.0 and before
|
||||||
try:
|
sr_actions = [i for i in r.actions if i.type == 'submit']
|
||||||
rdiff = server_diff(apiurl,
|
if not sr_actions:
|
||||||
r.actions[0].tgt_project, r.actions[0].tgt_package, None,
|
raise oscerr.WrongOptions('\'--diff\' not possible (request has no \'submit\' actions)')
|
||||||
r.actions[0].src_project, r.actions[0].src_package, r.actions[0].src_rev, opts.unified, True)
|
for action in sr_actions:
|
||||||
except urllib2.HTTPError, e:
|
diff += 'old: %s/%s\nnew: %s/%s\n' % (action.src_project, action.src_package,
|
||||||
if e.code != 400:
|
action.tgt_project, action.tgt_package)
|
||||||
e.osc_msg = 'Diff not possible'
|
diff += submit_action_diff(apiurl, action)
|
||||||
raise e
|
diff += '\n\n'
|
||||||
# backward compatiblity: only a recent api/backend supports the missingok parameter
|
run_pager(diff)
|
||||||
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)
|
|
||||||
|
|
||||||
# checkout
|
# checkout
|
||||||
elif cmd == 'checkout' or cmd == 'co':
|
elif cmd == 'checkout' or cmd == 'co':
|
||||||
|
55
osc/core.py
55
osc/core.py
@ -3957,6 +3957,26 @@ def request_diff(apiurl, reqid):
|
|||||||
f = http_POST(u)
|
f = http_POST(u)
|
||||||
return f.read()
|
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):
|
def make_dir(apiurl, project, package, pathname=None, prj_dir=None, package_tracking=True):
|
||||||
"""
|
"""
|
||||||
@ -5892,38 +5912,19 @@ def request_interactive_review(apiurl, request):
|
|||||||
print_request(request)
|
print_request(request)
|
||||||
try:
|
try:
|
||||||
msg = '(a)ccept/(d)ecline/(r)evoke/(b)uildstatus/c(l)one/(s)kip/(c)ancel > '
|
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
|
msg = 'd(i)ff/%s' % msg
|
||||||
while True:
|
while True:
|
||||||
repl = raw_input(msg).strip()
|
repl = raw_input(msg).strip()
|
||||||
if repl == 'i' and request.actions[0].type == 'submit':
|
if repl == 'i' and sr_actions:
|
||||||
if tmpfile is None:
|
if tmpfile is None:
|
||||||
tmpfile = tempfile.NamedTemporaryFile()
|
tmpfile = tempfile.NamedTemporaryFile()
|
||||||
# backward compatiblity: only a recent api/backend supports the missingok parameter
|
for action in sr_actions:
|
||||||
try:
|
diff = 'old: %s/%s\nnew: %s/%s\n' % (action.src_project, action.src_package,
|
||||||
diff = server_diff(apiurl, request.actions[0].tgt_project, request.actions[0].tgt_package, None,
|
action.tgt_project, action.tgt_package)
|
||||||
request.actions[0].src_project, request.actions[0].src_package, request.actions[0].src_rev, True, True)
|
diff += submit_action_diff(apiurl, action)
|
||||||
except urllib2.HTTPError, e:
|
diff += '\n\n'
|
||||||
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)
|
tmpfile.write(diff)
|
||||||
tmpfile.flush()
|
tmpfile.flush()
|
||||||
run_editor(tmpfile.name)
|
run_editor(tmpfile.name)
|
||||||
|
Loading…
Reference in New Issue
Block a user