From 1161b681e794ed034f6d43f5995dda71f7fbb5d0 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 10 Dec 2015 20:02:35 -0500 Subject: Improved output design - wrecked program design --- scripts/cbc_repo2html | 64 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-) (limited to 'scripts/cbc_repo2html') diff --git a/scripts/cbc_repo2html b/scripts/cbc_repo2html index 0eaffad..729ce4a 100755 --- a/scripts/cbc_repo2html +++ b/scripts/cbc_repo2html @@ -5,6 +5,47 @@ import json import os +def table_from_dict(data): + headers = ['subdir', + 'name', + 'version', + 'build', + 'build_number', + 'license', + 'depends', + 'md5', + 'sig', + 'size'] + + html = '' + + for header in headers: + html += '' + + for pkg_name, pkg_info in sorted(data.items()): + html += '' + html += '' + for header in headers: + if header not in pkg_info.keys(): + pkg_info[header] = '-' + + for key, value in pkg_info.items(): + if value is None or not value: + value = '-' + if key == header: + if isinstance(value, list): + html += '' + else: + html += '' + + html += '' + html += '' + html += '
' + header.upper() + '
' + for record in sorted(value): + html += '
  • ' + record + '
  • ' + html += '
    ' + str(value) + '
    ' + return html + if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('repodata', action='store') @@ -28,10 +69,25 @@ if __name__ == '__main__': print('') print('Repository Contents') print('') + print('') print('') - print('
    ')
    -    for key, subdict in sorted(repodata['packages'].items()):
    -        print("{0:50s} {1:>40s} {2:>20d}kb".format(key, subdict['md5'], subdict['size']))
    -    print('
    ') + #for key, subdict in sorted(repodata['packages'].items()): + # print("{0:50s} {1:>40s} {2:>20d}kb".format(key, subdict['md5'], subdict['size'])) + print(table_from_dict(repodata['packages'])) print('') print('') -- cgit