bjoern@21: #!/usr/bin/env python bjoern@21: # -*- coding: utf-8 -*- bjoern@21: bjoern@21: import optparse bjoern@21: import sys bjoern@21: bjoern@21: import requests bjoern@21: bjoern@21: bjoern@21: def main(): bjoern@21: usage = "usage: %prog [options] file1 file2 [ file3, ...]" bjoern@21: parser = optparse.OptionParser(usage=usage) bjoern@21: parser.add_option("-s", "--host", default="localhost") bjoern@21: parser.add_option("-p", "--port", default="5000") bjoern@21: parser.add_option("-o", "--out", default="merged.pdf", dest="out") bjoern@63: parser.add_option("-i", "--ignore-file-errors", action="store_true", bjoern@63: default=False, dest="ignorefileerrors") bjoern@68: parser.add_option("-m", "--multi", action="store_true", bjoern@68: default=False, dest="multi") bjoern@21: (options, args) = parser.parse_args() bjoern@21: bjoern@21: if len(args) < 2: bjoern@21: parser.print_usage() bjoern@21: sys.exit(1) bjoern@21: bjoern@21: service = "merge" bjoern@21: url = "http://%s:%s/%s/" % (options.host, options.port, service) bjoern@21: bjoern@63: if options.ignorefileerrors: bjoern@63: url += "?ignore_file_errors=1" bjoern@63: bjoern@21: files = [] bjoern@21: bjoern@68: if options.multi: bjoern@68: for i, filename in enumerate(args): bjoern@68: files.append(("file%s" % i, open(filename, 'rb'))) bjoern@68: else: bjoern@68: for filename in args: bjoern@68: files.append(('files', open(filename, 'rb'))) bjoern@21: bjoern@21: r = requests.post(url, files=files) bjoern@21: bjoern@21: if r.status_code == 200: bjoern@21: with open(options.out, "wb") as f: bjoern@21: f.write(r.content) mschieder@99: print("OK") bjoern@21: else: mschieder@99: print("An error has occured") mschieder@99: print((r.status_code, r.headers)) mschieder@99: print((r.text)) bjoern@21: sys.exit(2) bjoern@21: bjoern@21: if __name__ == "__main__": bjoern@21: main()