From b17405d9d076ea13bcc731b2586287ff946873b4 Mon Sep 17 00:00:00 2001 From: Michal Vyskocil Date: Tue, 20 Apr 2010 14:18:02 +0200 Subject: [PATCH] split the formating rules from get_results The osc.core.get_results parses the xml and also construct the status field in little bit complicate way. For future csv support it is necessary split the xml parsing and formatting to two functions: * get_package_results - returns a dict containing all important elements * get_results - behave as old implementation, just do a formating only --- osc/core.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/osc/core.py b/osc/core.py index fba6d938..da51a87c 100644 --- a/osc/core.py +++ b/osc/core.py @@ -3483,9 +3483,9 @@ def show_prj_results_meta(apiurl, prj): return f.readlines() -def get_results(apiurl, prj, package, lastbuild=None, repository=[], arch=[]): +def get_package_results(apiurl, prj, package, lastbuild=None, repository=[], arch=[]): + """ return a package results as a list of dicts """ r = [] - result_line_templ = '%(rep)-20s %(arch)-10s %(status)s' f = show_results_meta(apiurl, prj, package, lastbuild, repository, arch) root = ET.fromstring(''.join(f)) @@ -3500,21 +3500,32 @@ def get_results(apiurl, prj, package, lastbuild=None, repository=[], arch=[]): rmap['dirty'] = node.get('dirty') statusnode = node.find('status') - try: - rmap['status'] = statusnode.get('code') - except: - # code can be missing when package is too new: - rmap['status'] = '' + rmap['code'] = statusnode.get('code') if 'code' in statusnode.keys() else '' + rmap['details'] = '' - if rmap['status'] in ['expansion error', 'broken', 'blocked', 'finished']: + if rmap['code'] in ('expansion error', 'broken', 'blocked', 'finished'): details = statusnode.find('details') if details != None: - rmap['status'] += ': ' + details.text + rmap['details'] = details.text - if rmap['dirty'] == 'true': - rmap['status'] = 'state is outdated (was: %s)' % rmap['status'] + rmap['dirty'] = rmap['dirty'] == 'true' + + r.append(rmap) + return r + +def get_results(apiurl, prj, package, lastbuild=None, repository=[], arch=[]): + r = [] + result_line_templ = '%(rep)-20s %(arch)-10s %(status)s' + + for res in get_package_results(apiurl, prj, package, lastbuild=None, repository=[], arch=[]): + res['status'] = res['code'] + if res['details'] != '': + res['status'] += ': %s' % (res['details'], ) + if res['dirty']: + res['status'] = 'state is outdated (was: %s)' % res['status'] + + r.append(result_line_templ % res) - r.append(result_line_templ % rmap) return r def get_prj_results(apiurl, prj, hide_legend=False, csv=False, status_filter=None, name_filter=None, arch=None, repo=None, vertical=None):