2009-02-28 23:28:56 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
#justPrintCommands = False
|
|
|
|
|
|
2009-05-22 06:26:19 +08:00
|
|
|
def cmd(cmd_str_from_user, farm_queue=False, output_head=None, just_print_commands=False, outputFile = None):
|
2009-02-28 23:28:56 +08:00
|
|
|
# if farm_queue is non-False, submits to queue, other
|
|
|
|
|
|
|
|
|
|
if farm_queue:
|
2009-04-16 05:41:30 +08:00
|
|
|
if outputFile <> None:
|
|
|
|
|
farm_stdout = outputFile
|
2009-05-20 20:54:41 +08:00
|
|
|
elif output_head <> None:
|
2009-04-16 05:41:30 +08:00
|
|
|
farm_stdout = output_head+".stdout"
|
2009-05-20 20:54:41 +08:00
|
|
|
else:
|
|
|
|
|
farm_stdout = None
|
|
|
|
|
|
2009-05-22 06:26:19 +08:00
|
|
|
cmd_str = "bsub -q "+farm_queue
|
2009-05-20 20:54:41 +08:00
|
|
|
if farm_stdout <> None:
|
|
|
|
|
cmd_str += " -o " + farm_stdout
|
2009-05-22 06:26:19 +08:00
|
|
|
cmd_str += " "+cmd_str_from_user
|
2009-05-20 20:54:41 +08:00
|
|
|
|
2009-02-28 23:28:56 +08:00
|
|
|
print ">>> Farming via "+cmd_str
|
|
|
|
|
else:
|
2009-05-22 06:26:19 +08:00
|
|
|
cmd_str = cmd_str_from_user
|
2009-02-28 23:28:56 +08:00
|
|
|
print ">>> Executing "+cmd_str
|
|
|
|
|
|
|
|
|
|
if just_print_commands or (globals().has_key("justPrintCommands") and globals().justPrintCommands):
|
|
|
|
|
return -1
|
|
|
|
|
else:
|
|
|
|
|
# Actually execute the command if we're not just in debugging output mode
|
|
|
|
|
status = os.system(cmd_str)
|
|
|
|
|
if not farm_queue:
|
|
|
|
|
print "<<< Exit code:", status,"\n"
|
|
|
|
|
return status
|
|
|
|
|
|