mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-12 23:56:13 +01:00
Move format_table
to util.helper
This commit is contained in:
parent
fed3de9c11
commit
0bc142df91
21
osc/core.py
21
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
|
||||
from .util.helper import decode_list, decode_it, raw_input, _html_escape, format_table
|
||||
|
||||
|
||||
ET_ENCODING = "unicode"
|
||||
@ -5626,25 +5626,6 @@ def get_distributions(apiurl, discon=False):
|
||||
f = http_GET(makeurl(apiurl, ['distributions']))
|
||||
root = ET.fromstring(b''.join(f))
|
||||
|
||||
def format_table(rows, headers):
|
||||
"""Format list of tuples into equal width table with headers"""
|
||||
maxlens = [len(h) for h in headers]
|
||||
for r in rows:
|
||||
for i, c in enumerate(r):
|
||||
maxlens[i] = max(maxlens[i], len(c))
|
||||
tpltpl = []
|
||||
for i, m in enumerate(maxlens):
|
||||
tpltpl.append('{%s:<%s}' % (i, m))
|
||||
# {0:12} {1:7} {2:10} {3:8}
|
||||
templ = ' '.join(tpltpl) + '\n'
|
||||
|
||||
out = ''
|
||||
out += templ.format(*headers)
|
||||
out += templ.format(*['-'*m for m in maxlens])
|
||||
for r in rows:
|
||||
out += templ.format(*r)
|
||||
return out
|
||||
|
||||
headers = ('distribution', 'project', 'repository', 'reponame')
|
||||
distlist = []
|
||||
rows = []
|
||||
|
@ -51,3 +51,22 @@ def raw_input(*args):
|
||||
|
||||
def _html_escape(data):
|
||||
return html.escape(data, quote=False)
|
||||
|
||||
|
||||
def format_table(rows, headers):
|
||||
"""Format list of tuples into equal width table with headers"""
|
||||
maxlens = [len(h) for h in headers]
|
||||
for r in rows:
|
||||
for i, c in enumerate(r):
|
||||
maxlens[i] = max(maxlens[i], len(c))
|
||||
tpltpl = []
|
||||
for i, m in enumerate(maxlens):
|
||||
tpltpl.append('{%s:<%s}' % (i, m))
|
||||
# {0:12} {1:7} {2:10} {3:8}
|
||||
templ = ' '.join(tpltpl) + '\n'
|
||||
|
||||
out = templ.format(*headers)
|
||||
out += templ.format(*['-'*m for m in maxlens])
|
||||
for r in rows:
|
||||
out += templ.format(*r)
|
||||
return out
|
||||
|
Loading…
Reference in New Issue
Block a user