Mercurial > repos > greg > plant_tribes_assembly_post_processor
comparison utils.py @ 4:b0d9dc3c8535 draft
Uploaded
author | greg |
---|---|
date | Mon, 30 Oct 2017 09:51:13 -0400 |
parents | fcc558568020 |
children |
comparison
equal
deleted
inserted
replaced
3:07ee186ba16e | 4:b0d9dc3c8535 |
---|---|
25 fstdout = os.path.join(os.getcwd(), FSTDOUT) | 25 fstdout = os.path.join(os.getcwd(), FSTDOUT) |
26 fhout = open(fstdout, 'wb') | 26 fhout = open(fstdout, 'wb') |
27 return fstderr, fherr, fstdout, fhout | 27 return fstderr, fherr, fstdout, fhout |
28 | 28 |
29 | 29 |
30 def move_directory_files(source_dir, destination_dir, copy=False): | 30 def move_directory_files(source_dir, destination_dir, copy=False, remove_source_dir=False): |
31 source_directory = os.path.abspath(source_dir) | 31 source_directory = os.path.abspath(source_dir) |
32 destination_directory = os.path.abspath(destination_dir) | 32 destination_directory = os.path.abspath(destination_dir) |
33 if not os.path.isdir(destination_directory): | 33 if not os.path.isdir(destination_directory): |
34 os.makedirs(destination_directory) | 34 os.makedirs(destination_directory) |
35 for dir_entry in os.listdir(source_directory): | 35 for dir_entry in os.listdir(source_directory): |
36 source_entry = os.path.join(source_directory, dir_entry) | 36 source_entry = os.path.join(source_directory, dir_entry) |
37 if copy: | 37 if copy: |
38 shutil.copy(source_entry, destination_directory) | 38 shutil.copy(source_entry, destination_directory) |
39 else: | 39 else: |
40 shutil.move(source_entry, destination_directory) | 40 shutil.move(source_entry, destination_directory) |
41 if remove_source_dir: | |
42 os.rmdir(source_directory) | |
41 | 43 |
42 | 44 |
43 def run_command(cmd): | 45 def run_command(cmd): |
44 fstderr, fherr, fstdout, fhout = get_response_buffers() | 46 fstderr, fherr, fstdout, fhout = get_response_buffers() |
45 proc = subprocess.Popen(args=cmd, stderr=fherr, stdout=fhout, shell=True) | 47 proc = subprocess.Popen(args=cmd, stderr=fherr, stdout=fhout, shell=True) |
50 check_execution_errors(rc, fstderr, fstdout) | 52 check_execution_errors(rc, fstderr, fstdout) |
51 | 53 |
52 | 54 |
53 def stop_err(msg): | 55 def stop_err(msg): |
54 sys.exit(msg) | 56 sys.exit(msg) |
55 | |
56 | |
57 def write_html_output(output, title, dir): | |
58 with open(output, 'w') as fh: | |
59 dir_items = sorted(os.listdir(dir)) | |
60 # Directories can only contain either files or directories, | |
61 # but not both. | |
62 if len(dir_items) > 0: | |
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' | |
68 else: | |
69 header = '' | |
70 fh.write('<html><head><h3>%s: %d items</h3></head>\n' % (title, len(dir_items))) | |
71 fh.write('<body><p/><table cellpadding="2">\n') | |
72 fh.write('<tr><b>%s</th></b>\n' % header) | |
73 for index, fname in enumerate(dir_items): | |
74 if index % 2 == 0: | |
75 bgcolor = '#D8D8D8' | |
76 else: | |
77 bgcolor = '#FFFFFF' | |
78 link = '<a href="%s" type="text/plain">%s</a>\n' % (fname, fname) | |
79 fh.write('<tr bgcolor="%s"><td>%s</td></tr>\n' % (bgcolor, link)) | |
80 fh.write('</table></body></html>\n') |