comparison utils.py @ 20:4234f6791a4a draft

Uploaded
author greg
date Tue, 23 May 2017 10:53:56 -0400
parents 2aef84b19da6
children 346dc0d9af6f
comparison
equal deleted inserted replaced
19:1dee3b4be156 20:4234f6791a4a
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'