]> code.delx.au - transcoding/commitdiff
Added rotate_args, fixed permissions on ipod_tomp4.sh
authorGreg Darke <greg+laptop@tsukasa.net.au>
Sun, 12 Oct 2008 02:35:05 +0000 (13:35 +1100)
committerGreg Darke <greg+laptop@tsukasa.net.au>
Sun, 12 Oct 2008 02:35:05 +0000 (13:35 +1100)
rotate_args is a small program that makes it easier to control programs like AtomicParsley from a batch run file. This is because AtomicParsley requires the filename to be the first commandline argument

ipod_tomp4.sh [changed mode: 0644->0755]
rotate_args.py [new file with mode: 0755]

old mode 100644 (file)
new mode 100755 (executable)
diff --git a/rotate_args.py b/rotate_args.py
new file mode 100755 (executable)
index 0000000..f229787
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+
+import optparse, subprocess, sys, os
+
+def parse_args():
+       parser = optparse.OptionParser(usage="%prog [options] -- args")
+       parser.add_option("--program_name",
+               action="store", dest="program_name", default=None,
+               help="The name of the executable to run")
+       parser.add_option("--dump",
+               action="store_true", dest="dump",
+               help="Print command that would be run on stdout")
+       parser.add_option("--count",
+               action="store", type="int", dest="count",
+               help="The number of arguments to rotate")
+
+       opts, args = parser.parse_args(sys.argv[1:])
+       
+       opts.args = args
+       return opts
+
+def run(args, dump):
+       if dump:
+               print "".join(map(commands.mkarg, args))[1:]
+       else:
+               return subprocess.Popen(args).wait()
+
+def main():
+       opts = parse_args()
+
+       newcmdline = [opts.program_name] + opts.args[-opts.count:] + opts.args[:-opts.count]
+
+       run(newcmdline, opts.dump)
+
+if __name__ == "__main__":
+       main()
+