Last active
December 18, 2015 16:49
-
-
Save to0ms/5813873 to your computer and use it in GitHub Desktop.
Launcher used to send jobs with DrQueue from a configuration file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ffmpeg] | |
bin = /usr/bin/ffmpeg | |
lib = /my/first/lib | |
/my/second/lib | |
[ls] | |
bin = /bin/ls | |
[directories] | |
dir_1 = /home/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage : python launcher.py %ls% %dir_1%