]> code.delx.au - transcoding/blob - batchrun.py
Better batch encoder
[transcoding] / batchrun.py
1 #!/usr/bin/env python
2
3 import optparse, shlex, subprocess, sys
4
5 def parseArgs():
6 parser = optparse.OptionParser(usage="%prog batchfile1 [batchfile2] ...")
7 opts, args = parser.parse_args(sys.argv[1:])
8 return args
9
10 def run(args):
11 subprocess.Popen(args).wait()
12
13 def batchProcess(fd):
14 opts = [[], []]
15 for line in fd:
16 args = shlex.split(line)
17 if line.startswith("\t\t"):
18 run(opts[0] + opts[1] + args)
19 elif line.startswith("\t"):
20 opts[1] = args
21 else:
22 opts[0] = args
23
24 def main():
25 args = parseArgs()
26 for name in args:
27 batchProcess(open(name))
28
29 if __name__ == "__main__":
30 main()
31