Skip to content

Instantly share code, notes, and snippets.

@to0ms
Last active December 18, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save to0ms/5813873 to your computer and use it in GitHub Desktop.
Save to0ms/5813873 to your computer and use it in GitHub Desktop.
Launcher used to send jobs with DrQueue from a configuration file.
[ffmpeg]
bin = /usr/bin/ffmpeg
lib = /my/first/lib
/my/second/lib
[ls]
bin = /bin/ls
[directories]
dir_1 = /home/
#! /usr/bin/python
import ConfigParser, argparse, subprocess, sys, os
def configParser_on_file(configFile):
config = ConfigParser.RawConfigParser()
config.read(configFile)
return config
def parse_config_file(configFile = 'drqueue.conf'):
config = configParser_on_file(configFile)
sectionsDict = dict()
for section in config.sections():
sectionsDict[section] = dict(config.items(section))
return sectionsDict
def add_to_libs_path(lib):
if lib != None and lib != '':
platform = sys.platform
libs_path = 'PATH'
if 'linux' in platform:
libs_path = 'LD_LIBRARY_PATH'
elif 'darwin' == platform:
libs_path = 'DYLD_LIBRARY_PATH'
try:
os.environ[libs_path] = os.environ[libs_path] + os.pathsep + lib
except KeyError:
os.environ[libs_path] = lib
def cmd_analyse(cmd, configFile = "drqueue.conf"):
config = parse_config_file(configFile)
i = 0
while i < len(cmd):
section = cmd[i][1:-1].lower() # remove % %
if section != 'directories' and config.has_key(section):
tmp = config[section]
if tmp.has_key('bin'):
cmd[i] = tmp['bin']
if tmp.has_key('lib'):
add_to_libs_path(tmp['lib'].replace(os.linesep, os.pathsep))
elif config.has_key('directories'):
tmp = config['directories']
for j in tmp:
if ('%' + j + '%') in cmd[i]:
cmd[i] = cmd[i].replace('%' + j + '%', tmp[j])
cmd[i] = os.path.abspath(cmd[i])
i += 1
return cmd
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('cmd', help="The complete command you would use", nargs='+')
args = parser.parse_args()
cmd = cmd_analyse(args.cmd)
try:
subprocess.check_call(cmd)
except OSError as e:
print >>sys.stderr, "Execution failed:", e
sys.exit(1)
except subprocess.CalledProcessError as e:
sys.exit(e.returncode)
sys.exit(0)
@to0ms
Copy link
Author

to0ms commented Jun 24, 2013

Usage : python launcher.py %ls% %dir_1%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment