Giovanni Marco Dall'Olio committed 1b3fbcb

Add: a gsub command

Comments (0)

Files changed (1)

+#!/usr/bin/env python
+Fake qsub command, for testing qsub jobs in local
+import argparse
+import subprocess
+import logging
+import os
+import re
+class MissingParameterException(Exception):
+    def __init__(self, message):
+        self.message = message
+    def __repr__(self):
+        return repr(message)
+parser = argparse.ArgumentParser(description = __doc__, 
+    epilog='fake-qsub is an environment for testing Grid jobs in local')
+parser.add_argument('commandsfile', metavar='commands', type=str, help='the file containing the commands to be run')
+parser.add_argument('--queue', '-q', metavar='queue', type=str, help='queue', default='medium')
+parser.add_argument('--debug', '-d', action='store_true', help='show debug messages', default=False)
+parser.add_argument('-cwd', action='store_true', help='execute job from current directory', default=False)
+parser.add_argument('-v', metavar='vars', help='set up environment variables')  # STUB
+parser.add_argument('-m', metavar='mail', help='send a mail')                   # STUB
+parser.add_argument('-l', metavar='memory', help='set memory limit', default=False) # STUB
+parser.add_argument('-N', metavar='jobname', help='set job name') # STUB
+parser.add_argument('-hold_jid', metavar='hold', help='Hold/wait for another job to complete first') # STUB
+# Parse arguments and eventually set debug mode
+args = parser.parse_args()
+if args.debug is True:
+    logging.basicConfig(level=logging.DEBUG)
+# Simulate CWD option
+if args.cwd is True:
+    # if cwd is True, the command will be executed from the current directory
+    commandsfile = os.getcwd() + '/' + args.commandsfile
+    # otherwise, it is better if the absolute url is given
+    os.chdir('/')
+    commandsfile = '/' + args.commandsfile
+# Memory limit should always be given
+if args.l is False:
+    raise MissingParameterException('You forgot to specify the Memory requirements. Example: -l h_vmem=500MB')
+    if not re.match(('h_vmem=\d+'), args.l, re.I):
+        raise MissingParameterException('You did not specify Memory requirements correctly. Example: -l h_vmem=500MB')
+# Print debugging things
+logging.debug('launching ' + commandsfile)
+# Call the bash process[commandsfile])['bash', commandsfile])