comparison utils.py @ 18:2aef84b19da6 draft

Uploaded
author greg
date Mon, 22 May 2017 15:21:47 -0400
parents 3e5b6faed522
children 4234f6791a4a
comparison
equal deleted inserted replaced
17:3e5b6faed522 18:2aef84b19da6
54 sys.exit(msg) 54 sys.exit(msg)
55 55
56 56
57 def write_html_output(output, title, dir): 57 def write_html_output(output, title, dir):
58 with open(output, 'w') as fh: 58 with open(output, 'w') as fh:
59 fh.write('<html><head><h3>%s: %d files</h3></head>\n' % (title, len(os.listdir(dir)))) 59 dir_items = sorted(os.listdir(dir))
60 # Directories can only contain either files or directories, but not both.
61 item_path = os.path.join(dir, dir_items[0])
62 if os.path.isdir(item_path):
63 header = 'Directories'
64 else:
65 header = 'Datasets'
66 fh.write('<html><head><h3>%s: %d items</h3></head>\n' % (title, len(dir_items)))
60 fh.write('<body><p/><table cellpadding="2">\n') 67 fh.write('<body><p/><table cellpadding="2">\n')
61 fh.write('<tr><th>Size</th><th>Name</th></tr>\n') 68 fh.write('<tr><th>%s</th></tr>\n' % header)
62 for index, fname in enumerate(sorted(os.listdir(dir))): 69 for index, fname in enumerate(dir_items):
63 if index % 2 == 0: 70 if index % 2 == 0:
64 bgcolor = '#D8D8D8' 71 bgcolor = '#D8D8D8'
65 else: 72 else:
66 bgcolor = '#FFFFFF' 73 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) 74 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)) 75 fh.write('<tr bgcolor="%s"><td>%s</td></tr>\n' % (bgcolor, link))
73 fh.write('</table></body></html>\n') 76 fh.write('</table></body></html>\n')