1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-08-31 10:24:13 +02:00

Pretty print dists table with two spaces between columns

This commit is contained in:
Anatoli Babenia
2020-11-14 19:45:29 +03:00
parent c000e0e372
commit 48e8a1e802

View File

@@ -5598,19 +5598,37 @@ def get_distibutions(apiurl, discon=False):
r.insert(1, '------------ -------')
else:
result_line_templ = '%(name)-25s %(project)-25s %(repository)-25s %(reponame)s'
f = http_GET(makeurl(apiurl, ['distributions']))
root = ET.fromstring(b''.join(f))
distlist = []
for node in root.findall('distribution'):
rmap = {}
dmap = {}
for child in node:
if child.tag in ('name', 'project', 'repository', 'reponame'):
rmap[child.tag] = child.text
r.append(result_line_templ % rmap)
dmap[child.tag] = child.text
dmap['distribution'] = dmap.pop('name')
distlist.append(dmap)
r.insert(0, 'distribution project repository reponame')
r.insert(1, '------------ ------- ---------- --------')
# pretty printing table
headers = ('distribution', 'project', 'repository', 'reponame')
maxlen = [len(h) for h in headers]
for d in distlist:
for i,field in enumerate(headers):
maxlen[i] = max(maxlen[i], len(d[field]))
def format_row(dist, proj, repotype, reponame):
result_line_templ = '%-*s %-*s %-*s %-s'
return result_line_templ % (
maxlen[0], dist,
maxlen[1], proj,
maxlen[2], repotype,
reponame
)
r.append(format_row('distribution', 'project', 'repository', 'reponame'))
r.append(format_row('-'*maxlen[0], '-'*maxlen[1], '-'*maxlen[2], '-'*maxlen[2]))
for d in distlist:
r.append(format_row(d['distribution'], d['project'], d['repository'], d['reponame']))
return r