Mercurial > odfcast
comparison mergeclient.py @ 21:a8c628466a9d
Add an example client for MergeView based on requests
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Mon, 29 Sep 2014 16:00:19 +0200 |
parents | |
children | 3918c3c69485 |
comparison
equal
deleted
inserted
replaced
20:c289263e1b24 | 21:a8c628466a9d |
---|---|
1 #!/usr/bin/env python | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 import optparse | |
5 import sys | |
6 | |
7 import requests | |
8 | |
9 | |
10 def main(): | |
11 usage = "usage: %prog [options] file1 file2 [ file3, ...]" | |
12 parser = optparse.OptionParser(usage=usage) | |
13 parser.add_option("-s", "--host", default="localhost") | |
14 parser.add_option("-p", "--port", default="5000") | |
15 parser.add_option("-o", "--out", default="merged.pdf", dest="out") | |
16 (options, args) = parser.parse_args() | |
17 | |
18 if len(args) < 2: | |
19 parser.print_usage() | |
20 sys.exit(1) | |
21 | |
22 service = "merge" | |
23 url = "http://%s:%s/%s/" % (options.host, options.port, service) | |
24 | |
25 files = [] | |
26 | |
27 for filename in args: | |
28 files.append(('files', open(filename, 'rb'))) | |
29 | |
30 r = requests.post(url, files=files) | |
31 | |
32 if r.status_code == 200: | |
33 with open(options.out, "wb") as f: | |
34 f.write(r.content) | |
35 print "OK" | |
36 else: | |
37 print "An error has occured" | |
38 print r.status_code, r.headers | |
39 print r.text | |
40 sys.exit(2) | |
41 | |
42 if __name__ == "__main__": | |
43 main() |