Mercurial > repos > greg > assembly_post_processor
comparison utils.py @ 59:6995393bda9f draft
Uploaded
author | greg |
---|---|
date | Mon, 22 May 2017 11:31:50 -0400 |
parents | 0f65703d5bb8 |
children | f7a999b3b19c |
comparison
equal
deleted
inserted
replaced
58:e7f264e21d9a | 59:6995393bda9f |
---|---|
52 | 52 |
53 def stop_err(msg): | 53 def stop_err(msg): |
54 sys.exit(msg) | 54 sys.exit(msg) |
55 | 55 |
56 | 56 |
57 def write_dir_contents_as_html(fh, dir): | |
58 for index, dir_entry in enumerate(sorted(os.listdir(dir))): | |
59 if index % 2 == 0: | |
60 bgcolor = '#D8D8D8' | |
61 else: | |
62 bgcolor = '#FFFFFF' | |
63 link = '<a href="%s" type="text/plain">%s</a>\n' % (dir_entry, dir_entry) | |
64 fh.write('<tr bgcolor="%s"><td>%s</td></tr>\n' % (bgcolor, link)) | |
65 | |
66 | |
67 | |
57 def write_html_output(output, title, dir): | 68 def write_html_output(output, title, dir): |
58 with open(output, 'w') as fh: | 69 with open(output, 'w') as fh: |
59 fh.write('<html><head><h3>%s: %d files</h3></head>\n' % (title, len(os.listdir(dir)))) | 70 fh.write('<html><head><h3>%s: %d items</h3></head>\n' % (title, len(os.listdir(dir)))) |
60 fh.write('<body><p/><table cellpadding="2">\n') | 71 fh.write('<body><p/><table cellpadding="2">\n') |
61 fh.write('<tr><th>Size</th><th>Name</th></tr>\n') | 72 fh.write('<tr><th>Size</th><th>Name</th></tr>\n') |
62 for index, fname in enumerate(sorted(os.listdir(dir))): | 73 for index, fname in enumerate(sorted(os.listdir(dir))): |
63 if index % 2 == 0: | 74 if index % 2 == 0: |
64 bgcolor = '#D8D8D8' | 75 bgcolor = '#D8D8D8' |
65 else: | 76 else: |
66 bgcolor = '#FFFFFF' | 77 bgcolor = '#FFFFFF' |
67 try: | |
68 size = str(os.path.getsize(os.path.join(dir, fname))) | |
69 except: | |
70 size = 'unknown' | |
71 link = '<a href="%s" type="text/plain">%s</a>\n' % (fname, fname) | 78 link = '<a href="%s" type="text/plain">%s</a>\n' % (fname, fname) |
72 fh.write('<tr bgcolor="%s"><td>%s</td><td>%s</td></tr>\n' % (bgcolor, size, link)) | 79 fh.write('<tr bgcolor="%s"><td>%s</td></tr>\n' % (bgcolor, link)) |
73 fh.write('</table></body></html>\n') | 80 fh.write('</table></body></html>\n') |