#!/usr/bin/env python import os import sys from optparse import OptionParser def build_parser(): p = OptionParser() return p def main(): parser = build_parser() opts, args = parser.parse_args() if len(args) == 0: print >> sys.stderr, 'Expected 1 argument' raise SystemExit(1) dstdir = args[0] try: os.mkdir(dstdir) except OSError: if os.path.isfile(dstdir): print >> sys.stderr, ('A file already exists with the target dir ' 'name.') raise SystemExit(1) for arg in sys.stdin: srcfile = arg.strip() srcpath, srcname = os.path.split(srcfile) dstfile = os.path.join(dstdir, srcname) prog = 'convert' action = '-scale 1200x800' cmd = '%s %s %s %s' % (prog, action, srcfile, dstfile) print cmd os.system(cmd) #print repr(cmd) if __name__ == '__main__': main()