comparison utils.py @ 35:88c9bd1583d8 draft

Uploaded
author greg
date Tue, 23 May 2017 10:54:28 -0400
parents ea2be77b575c
children 9962341547d3
comparison
equal deleted inserted replaced
34:f9b60c34dfd7 35:88c9bd1583d8
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 dir_items = sorted(os.listdir(dir)) 59 dir_items = sorted(os.listdir(dir))
60 # Directories can only contain either files or directories, but not both. 60 # Directories can only contain either files or directories,
61 item_path = os.path.join(dir, dir_items[0]) 61 # but not both.
62 if os.path.isdir(item_path): 62 if len(dir_items) > 0:
63 header = 'Directories' 63 item_path = os.path.join(dir, dir_items[0])
64 if os.path.isdir(item_path):
65 header = 'Directories'
66 else:
67 header = 'Datasets'
64 else: 68 else:
65 header = 'Datasets' 69 header = ''
66 fh.write('<html><head><h3>%s: %d items</h3></head>\n' % (title, len(dir_items))) 70 fh.write('<html><head><h3>%s: %d items</h3></head>\n' % (title, len(dir_items)))
67 fh.write('<body><p/><table cellpadding="2">\n') 71 fh.write('<body><p/><table cellpadding="2">\n')
68 fh.write('<tr><th>%s</th></tr>\n' % header) 72 fh.write('<tr><b>%s</th></b>\n' % header)
69 for index, fname in enumerate(dir_items): 73 for index, fname in enumerate(dir_items):
70 if index % 2 == 0: 74 if index % 2 == 0:
71 bgcolor = '#D8D8D8' 75 bgcolor = '#D8D8D8'
72 else: 76 else:
73 bgcolor = '#FFFFFF' 77 bgcolor = '#FFFFFF'