annotate ctat_bash_command_executer.py @ 0:702a3586942a draft default tip

Upload ctat tools.
author trinity_ctat
date Tue, 17 Jul 2018 11:48:23 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
1 #!/usr/bin/env python
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
2
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
3 import sys, subprocess, os
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
4
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
5 def stop_err( msg ):
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
6 sys.stderr.write( "%s\n" % msg )
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
7 sys.exit()
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
8
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
9 def __main__():
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
10 # Get command-line arguments
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
11 args = sys.argv
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
12 # Remove name of calling program, i.e. ./stderr_wrapper.py
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
13 args.pop(0)
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
14
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
15 # If there are no arguments left, we're done
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
16 if len(args) == 0:
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
17 return
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
18
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
19 # If one needs to silence stdout
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
20 #args.append( ">" )
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
21 #args.append( "/dev/null" )
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
22
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
23 cmdline = " ".join(args)
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
24
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
25
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
26 try:
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
27 # Run program
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
28 err_capture = open("stderr.txt", 'w')
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
29 proc = subprocess.Popen( args=cmdline, shell=True, stderr=err_capture, stdout=sys.stdout )
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
30 returncode = proc.wait()
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
31 err_capture.close()
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
32
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
33
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
34 if returncode != 0:
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
35 raise Exception
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
36
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
37 except Exception:
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
38 # Running Grinder failed: write error message to stderr
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
39 err_text = open("stderr.txt").readlines()
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
40 stop_err( "ERROR:\n" + "\n".join(err_text))
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
41
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
42
702a3586942a Upload ctat tools.
trinity_ctat
parents:
diff changeset
43 if __name__ == "__main__": __main__()