Mercurial > odfcast
annotate checkclient.py @ 95:4c1a748091d7
Added tag 1.5 for changeset 2ef34abbad8d
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Fri, 28 Apr 2017 21:04:43 +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() |