comparison utils.py @ 11:1c5a484fc06f draft default tip

planemo upload for repository https://github.com/gregvonkuster/galaxy_tools/tree/master/tools/phylogenetics/plant_tribes/gene_family_aligner commit f7690d10e0515911ee00455806e457bc53f145c7-dirty
author greg
date Thu, 13 Jun 2024 11:54:31 +0000
parents 79ea0eef1942
children
comparison
equal deleted inserted replaced
10:79ea0eef1942 11:1c5a484fc06f
1 import os
2 import shutil
3 import subprocess
4 import sys
5
6 FSTDERR = 'stderr.txt'
7 FSTDOUT = 'stdout.txt'
8
9
10 def check_execution_errors(rc, fstderr, fstdout):
11 if rc != 0:
12 fh = open(fstdout, 'rb')
13 out_msg = fh.read()
14 fh.close()
15 fh = open(fstderr, 'rb')
16 err_msg = fh.read()
17 fh.close()
18 msg = '%s\n%s\n' % (str(out_msg), str(err_msg))
19 stop_err(msg)
20
21
22 def get_response_buffers():
23 fstderr = os.path.join(os.getcwd(), FSTDERR)
24 fherr = open(fstderr, 'wb')
25 fstdout = os.path.join(os.getcwd(), FSTDOUT)
26 fhout = open(fstdout, 'wb')
27 return fstderr, fherr, fstdout, fhout
28
29
30 def move_directory_files(source_dir, destination_dir, copy=False, remove_source_dir=False):
31 source_directory = os.path.abspath(source_dir)
32 destination_directory = os.path.abspath(destination_dir)
33 if not os.path.isdir(destination_directory):
34 os.makedirs(destination_directory)
35 for dir_entry in os.listdir(source_directory):
36 source_entry = os.path.join(source_directory, dir_entry)
37 if copy:
38 shutil.copy(source_entry, destination_directory)
39 else:
40 shutil.move(source_entry, destination_directory)
41 if remove_source_dir:
42 os.rmdir(source_directory)
43
44
45 def run_command(cmd):
46 fstderr, fherr, fstdout, fhout = get_response_buffers()
47 proc = subprocess.Popen(args=cmd, stderr=fherr, stdout=fhout, shell=True)
48 rc = proc.wait()
49 # Check results.
50 fherr.close()
51 fhout.close()
52 check_execution_errors(rc, fstderr, fstdout)
53
54
55 def stop_err(msg):
56 sys.exit(msg)