aboutsummaryrefslogtreecommitdiff
path: root/scripts/cbc_repo2html
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunk@stsci.edu>2015-12-10 20:02:35 -0500
committerJoseph Hunkeler <jhunk@stsci.edu>2015-12-10 20:02:35 -0500
commit1161b681e794ed034f6d43f5995dda71f7fbb5d0 (patch)
tree210bd4975f39210bf06219e0387328e2ccd71d9a /scripts/cbc_repo2html
parenta62ac34c8195b45efb75c693d20bd6afb7ab2b70 (diff)
downloadcbc-1161b681e794ed034f6d43f5995dda71f7fbb5d0.tar.gz
Improved output design - wrecked program design
Diffstat (limited to 'scripts/cbc_repo2html')
-rwxr-xr-xscripts/cbc_repo2html64
1 files changed, 60 insertions, 4 deletions
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 = '<table>'
+
+ for header in headers:
+ html += '<th>' + header.upper() + '</th>'
+
+ for pkg_name, pkg_info in sorted(data.items()):
+ html += '<tr>'
+ html += '<tr>'
+ 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 += '<td>'
+ for record in sorted(value):
+ html += '<li>' + record + '</li>'
+ html += '</td>'
+ else:
+ html += '<td>' + str(value) + '</td>'
+
+ html += '</tr>'
+ html += '</tr>'
+ html += '</table>'
+ return html
+
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('repodata', action='store')
@@ -28,10 +69,25 @@ if __name__ == '__main__':
print('<head>')
print('<title>Repository Contents</title>')
print('</head>')
+ print('<style>')
+ print('''
+ table {
+ border-collapse: collapse;
+ width: 100%;
+ }
+
+ th, td {
+ width: 5%;
+ padding: 8px;
+ text-align: left;
+ /*border-bottom: 1px solid #ddd;*/
+ border: 1px solid #ddd;
+ }
+ ''')
+ print('</style>')
print('<body>')
- print('<pre>')
- for key, subdict in sorted(repodata['packages'].items()):
- print("{0:50s} {1:>40s} {2:>20d}kb".format(key, subdict['md5'], subdict['size']))
- print('</pre>')
+ #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('</body>')
print('</html>')