comparison mergeclient.py @ 68:4645e50539ff

Add support for posting files with own form names for each file Add a multi param to mergeclient to show example of posting each file as its own formular parameter.
author Björn Ricks <bjoern.ricks@intevation.de>
date Tue, 02 Dec 2014 17:06:33 +0100
parents 3918c3c69485
children 349d49bb69f4
comparison
equal deleted inserted replaced
67:5d1e486140ae 68:4645e50539ff
13 parser.add_option("-s", "--host", default="localhost") 13 parser.add_option("-s", "--host", default="localhost")
14 parser.add_option("-p", "--port", default="5000") 14 parser.add_option("-p", "--port", default="5000")
15 parser.add_option("-o", "--out", default="merged.pdf", dest="out") 15 parser.add_option("-o", "--out", default="merged.pdf", dest="out")
16 parser.add_option("-i", "--ignore-file-errors", action="store_true", 16 parser.add_option("-i", "--ignore-file-errors", action="store_true",
17 default=False, dest="ignorefileerrors") 17 default=False, dest="ignorefileerrors")
18 parser.add_option("-m", "--multi", action="store_true",
19 default=False, dest="multi")
18 (options, args) = parser.parse_args() 20 (options, args) = parser.parse_args()
19 21
20 if len(args) < 2: 22 if len(args) < 2:
21 parser.print_usage() 23 parser.print_usage()
22 sys.exit(1) 24 sys.exit(1)
27 if options.ignorefileerrors: 29 if options.ignorefileerrors:
28 url += "?ignore_file_errors=1" 30 url += "?ignore_file_errors=1"
29 31
30 files = [] 32 files = []
31 33
32 for filename in args: 34 if options.multi:
33 files.append(('files', open(filename, 'rb'))) 35 for i, filename in enumerate(args):
36 files.append(("file%s" % i, open(filename, 'rb')))
37 else:
38 for filename in args:
39 files.append(('files', open(filename, 'rb')))
34 40
35 r = requests.post(url, files=files) 41 r = requests.post(url, files=files)
36 42
37 if r.status_code == 200: 43 if r.status_code == 200:
38 with open(options.out, "wb") as f: 44 with open(options.out, "wb") as f:
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)