From 68d559e343f6720f87cb7d9d948c6db155b43e8d Mon Sep 17 00:00:00 2001 From: Marcus Huewe Date: Sat, 29 Jan 2011 17:24:45 +0100 Subject: [PATCH] - refactored request diff code --- osc/commandline.py | 36 ++++++++++------------------- osc/core.py | 57 +++++++++++++++++++++++----------------------- 2 files changed, 41 insertions(+), 52 deletions(-) diff --git a/osc/commandline.py b/osc/commandline.py index 38463683..8930c4ca 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -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': diff --git a/osc/core.py b/osc/core.py index 2f44eb71..064d585f 100644 --- a/osc/core.py +++ b/osc/core.py @@ -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)