mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-10 06:46:15 +01:00
Move output formatting from core
into commandline
This makes `get_distributions()` return list of dicts.
This commit is contained in:
parent
0bc142df91
commit
4d6a6aaf96
@ -19,7 +19,7 @@ from . import conf
|
||||
from . import oscerr
|
||||
from .core import *
|
||||
from .util import safewriter
|
||||
from .util.helper import _html_escape
|
||||
from .util.helper import _html_escape, format_table
|
||||
|
||||
|
||||
MAN_HEADER = r""".TH %(ucname)s "1" "%(date)s" "%(name)s %(version)s" "User Commands"
|
||||
@ -5358,7 +5358,14 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
"""
|
||||
apiurl = self.get_api_url()
|
||||
|
||||
print('\n'.join(get_distributions(apiurl))) # FIXME:, opts.discontinued))
|
||||
dists = get_distributions(apiurl)
|
||||
if dists:
|
||||
headers = dists[0].keys()
|
||||
rows = []
|
||||
for dist in dists:
|
||||
rows.append([dist[h] for h in headers])
|
||||
print(format_table(rows, headers))
|
||||
|
||||
|
||||
@cmdln.hide(1)
|
||||
def do_results_meta(self, subcmd, opts, *args):
|
||||
|
16
osc/core.py
16
osc/core.py
@ -40,7 +40,7 @@ except ImportError:
|
||||
from . import conf
|
||||
from . import oscerr
|
||||
from .connection import http_request, http_GET, http_POST, http_PUT, http_DELETE
|
||||
from .util.helper import decode_list, decode_it, raw_input, _html_escape, format_table
|
||||
from .util.helper import decode_list, decode_it, raw_input, _html_escape
|
||||
|
||||
|
||||
ET_ENCODING = "unicode"
|
||||
@ -5604,10 +5604,12 @@ def get_repositories(apiurl):
|
||||
|
||||
|
||||
def get_distributions(apiurl, discon=False):
|
||||
r = []
|
||||
"""Returns list of dicts with headers
|
||||
'distribution', 'project', 'repository', 'reponame'"""
|
||||
|
||||
# FIXME: this is just a naming convention on api.opensuse.org, but not a general valid apparoach
|
||||
if discon:
|
||||
r = []
|
||||
result_line_templ = '%(name)-25s %(project)s'
|
||||
f = http_GET(makeurl(apiurl, ['build']))
|
||||
root = ET.fromstring(''.join(f))
|
||||
@ -5621,14 +5623,13 @@ def get_distributions(apiurl, discon=False):
|
||||
|
||||
r.insert(0, 'distribution project')
|
||||
r.insert(1, '------------ -------')
|
||||
return r
|
||||
|
||||
else:
|
||||
f = http_GET(makeurl(apiurl, ['distributions']))
|
||||
root = ET.fromstring(b''.join(f))
|
||||
|
||||
headers = ('distribution', 'project', 'repository', 'reponame')
|
||||
distlist = []
|
||||
rows = []
|
||||
for node in root.findall('distribution'):
|
||||
dmap = {}
|
||||
for child in node:
|
||||
@ -5637,12 +5638,7 @@ def get_distributions(apiurl, discon=False):
|
||||
elif child.tag in ('project', 'repository', 'reponame'):
|
||||
dmap[child.tag] = child.text
|
||||
distlist.append(dmap)
|
||||
# append row sorted by headers
|
||||
rows.append([dmap[h] for h in headers])
|
||||
|
||||
return format_table(rows, headers).splitlines()
|
||||
|
||||
return r
|
||||
return distlist
|
||||
|
||||
|
||||
# old compat lib call
|
||||
|
Loading…
Reference in New Issue
Block a user