comparison checkclient.py @ 74:22ce0dc2e71c

Add client to test demonstrate the check feature
author Frank Koormann <frank.koormann@intevation.de>
date Fri, 06 Mar 2015 15:27:12 +0100
parents
children 3928af61b4ce
comparison
equal deleted inserted replaced
73:02efda1f6919 74:22ce0dc2e71c
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] infile"
12 parser = optparse.OptionParser(usage=usage)
13 parser.add_option("-s", "--host", default="localhost")
14 parser.add_option("-p", "--port", default="5000")
15 (options, args) = parser.parse_args()
16
17 if len(args) < 2:
18 parser.print_usage()
19 sys.exit(1)
20
21 url = "http://%s:%s/check/" % (options.host, options.port)
22 infilename = args[0]
23 format = options.format
24
25 files = {'file': open(infilename, 'rb')}
26
27 r = requests.post(url, data=data, files=files)
28
29 if r.status_code == 200:
30 with open(outfilename, "wb") as f:
31 f.write(r.content)
32 print "OK"
33 else:
34 print "An error has occured"
35 print r.status_code, r.headers
36 print r.text
37 sys.exit(2)
38
39
40 if __name__ == "__main__":
41 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)