annotate mergeclient.py @ 65:2926b497c29c

Add a requirements_wheezy.txt for versions near the version in debian wheezy
author Björn Ricks <bjoern.ricks@intevation.de>
date Thu, 20 Nov 2014 14:35:02 +0100
parents 3918c3c69485
children 4645e50539ff
rev   line source
21
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
1 #!/usr/bin/env python
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
3
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
4 import optparse
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
5 import sys
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
6
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
7 import requests
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
8
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
9
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
10 def main():
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
11 usage = "usage: %prog [options] file1 file2 [ file3, ...]"
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
12 parser = optparse.OptionParser(usage=usage)
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
13 parser.add_option("-s", "--host", default="localhost")
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
14 parser.add_option("-p", "--port", default="5000")
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
15 parser.add_option("-o", "--out", default="merged.pdf", dest="out")
63
3918c3c69485 Add ignore_file_errors option to mergeclient
Björn Ricks <bjoern.ricks@intevation.de>
parents: 21
diff changeset
16 parser.add_option("-i", "--ignore-file-errors", action="store_true",
3918c3c69485 Add ignore_file_errors option to mergeclient
Björn Ricks <bjoern.ricks@intevation.de>
parents: 21
diff changeset
17 default=False, dest="ignorefileerrors")
21
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
18 (options, args) = parser.parse_args()
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
19
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
20 if len(args) < 2:
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
21 parser.print_usage()
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
22 sys.exit(1)
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
23
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
24 service = "merge"
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
25 url = "http://%s:%s/%s/" % (options.host, options.port, service)
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
26
63
3918c3c69485 Add ignore_file_errors option to mergeclient
Björn Ricks <bjoern.ricks@intevation.de>
parents: 21
diff changeset
27 if options.ignorefileerrors:
3918c3c69485 Add ignore_file_errors option to mergeclient
Björn Ricks <bjoern.ricks@intevation.de>
parents: 21
diff changeset
28 url += "?ignore_file_errors=1"
3918c3c69485 Add ignore_file_errors option to mergeclient
Björn Ricks <bjoern.ricks@intevation.de>
parents: 21
diff changeset
29
21
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
30 files = []
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
31
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
32 for filename in args:
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
33 files.append(('files', open(filename, 'rb')))
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
34
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
35 r = requests.post(url, files=files)
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
36
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
37 if r.status_code == 200:
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
38 with open(options.out, "wb") as f:
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
39 f.write(r.content)
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
40 print "OK"
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
41 else:
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
42 print "An error has occured"
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
43 print r.status_code, r.headers
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
44 print r.text
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
45 sys.exit(2)
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
46
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
47 if __name__ == "__main__":
a8c628466a9d Add an example client for MergeView based on requests
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
48 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)