Mercurial > repos > greg > assembly_post_processor
comparison utils.py @ 44:58382c8ed01c draft
Uploaded
author | greg |
---|---|
date | Wed, 03 May 2017 10:13:37 -0400 |
parents | |
children | 73b38edd22dd |
comparison
equal
deleted
inserted
replaced
43:ac9b32bd719c | 44:58382c8ed01c |
---|---|
1 import os | |
2 import shutil | |
3 import sys | |
4 | |
5 | |
6 def check_execution_errors(rc, stderr, stdout=None): | |
7 if rc != 0: | |
8 if stdout is None: | |
9 stop_err(stderr.read()) | |
10 msg = '%s\n%s' % (stdout.read(), stderr.read()) | |
11 | |
12 | |
13 def move_directory_files(source_dir, destination_dir): | |
14 source_directory = os.path.abspath(source_dir) | |
15 destination_directory = os.path.abspath(destination_dir) | |
16 if not os.path.isdir(destination_directory): | |
17 os.makedirs(destination_directory) | |
18 for dir_entry in os.listdir(source_directory): | |
19 source_entry = os.path.join(source_directory, dir_entry) | |
20 shutil.move(source_entry, destination_directory) | |
21 | |
22 | |
23 def stop_err(msg): | |
24 sys.stderr.write(msg) | |
25 sys.exit(1) | |
26 | |
27 | |
28 def write_html_output(output, title, dir): | |
29 with open(output, 'w') as fh: | |
30 fh.write('<html><head><h3>%s</h3></head>\n' % title) | |
31 fh.write('<body><p/><table cellpadding="2">\n') | |
32 fh.write('<tr><th>Size</th><th>Name</th></tr>\n') | |
33 for index, fname in enumerate(sorted(os.listdir(dir))): | |
34 if index % 2 == 0: | |
35 bgcolor = '#D8D8D8' | |
36 else: | |
37 bgcolor = '#FFFFFF' | |
38 try: | |
39 size = str(os.path.getsize(os.path.join(dir, fname))) | |
40 except: | |
41 size = 'unknown' | |
42 link = '<a href="%s" type="text/plain">%s</a>\n' % (fname, fname) | |
43 fh.write('<tr bgcolor="%s"><td>%s</td><td>%s</td></tr>\n' % (bgcolor, size, link)) | |
44 fh.write('</table></body></html>\n') |