comparison utils.py @ 31:5691bc0a32d2 draft

Uploaded
author greg
date Mon, 15 May 2017 08:26:23 -0400
parents 437a43ec5fb4
children f61d568666f1
comparison
equal deleted inserted replaced
30:3b80ba2c0fd1 31:5691bc0a32d2
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): 30 def move_directory_files(source_dir, destination_dir, copy=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 shutil.move(source_entry, destination_directory) 37 if copy:
38 shutil.copy(source_entry, destination_directory)
39 else:
40 shutil.move(source_entry, destination_directory)
38 41
39 42
40 def run_command(cmd): 43 def run_command(cmd):
41 fstderr, fherr, fstdout, fhout = get_response_buffers() 44 fstderr, fherr, fstdout, fhout = get_response_buffers()
42 proc = subprocess.Popen(args=cmd, stderr=fherr, stdout=fhout, shell=True) 45 proc = subprocess.Popen(args=cmd, stderr=fherr, stdout=fhout, shell=True)
51 sys.exit(msg) 54 sys.exit(msg)
52 55
53 56
54 def write_html_output(output, title, dir): 57 def write_html_output(output, title, dir):
55 with open(output, 'w') as fh: 58 with open(output, 'w') as fh:
56 fh.write('<html><head><h3>%s</h3></head>\n' % title) 59 fh.write('<html><head><h3>%s: %d files</h3></head>\n' % (title, len(os.listdir(dir))))
57 fh.write('<body><p/><table cellpadding="2">\n') 60 fh.write('<body><p/><table cellpadding="2">\n')
58 fh.write('<tr><th>Size</th><th>Name</th></tr>\n') 61 fh.write('<tr><th>Size</th><th>Name</th></tr>\n')
59 for index, fname in enumerate(sorted(os.listdir(dir))): 62 for index, fname in enumerate(sorted(os.listdir(dir))):
60 if index % 2 == 0: 63 if index % 2 == 0:
61 bgcolor = '#D8D8D8' 64 bgcolor = '#D8D8D8'