Mercurial > odfcast > odfcast
annotate checkclient.py @ 96:f6d87a17ed84 1.5.1
Require a newer version of py3o.template.
Version 0.9.11 is newest one available at the moment. The issue we were
having with some ODT templates might have been fixed in an earlier
version (e.g. 0.9.9) but I've only tested it with 0.9.11.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Fri, 25 Aug 2017 18:36:44 +0200 |
parents | 3928af61b4ce |
children | 349d49bb69f4 |
rev | line source |
---|---|
74
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
3 |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
4 import optparse |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
5 import sys |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
6 |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
7 import requests |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
8 |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
9 |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
10 def main(): |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
11 usage = "usage: %prog [options] infile" |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
12 parser = optparse.OptionParser(usage=usage) |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
13 parser.add_option("-s", "--host", default="localhost") |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
14 parser.add_option("-p", "--port", default="5000") |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
15 (options, args) = parser.parse_args() |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
16 |
75
3928af61b4ce
checkclient final fixes
Frank Koormann <frank@intevation.de>
parents:
74
diff
changeset
|
17 if len(args) < 1: |
74
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
18 parser.print_usage() |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
19 sys.exit(1) |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
20 |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
21 url = "http://%s:%s/check/" % (options.host, options.port) |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
22 infilename = args[0] |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
23 |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
24 files = {'file': open(infilename, 'rb')} |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
25 |
75
3928af61b4ce
checkclient final fixes
Frank Koormann <frank@intevation.de>
parents:
74
diff
changeset
|
26 r = requests.post(url, files=files) |
74
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
27 |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
28 if r.status_code == 200: |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
29 print "OK" |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
30 else: |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
31 print "An error has occured" |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
32 print r.status_code, r.headers |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
33 print r.text |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
34 sys.exit(2) |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
35 |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
36 |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
37 if __name__ == "__main__": |
22ce0dc2e71c
Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff
changeset
|
38 main() |