From: Zooko O'Whielacronx Date: Thu, 16 Aug 2007 23:30:39 +0000 (-0700) Subject: put now exits after doing its work, and it prints a terse message if 200 or 201,... X-Git-Url: https://git.rkrishnan.org/simplejson/__init__.py.html?a=commitdiff_plain;h=1564987e6c86236c2807f5cbb8975fb9e44e4e8d;p=tahoe-lafs%2Ftahoe-lafs.git put now exits after doing its work, and it prints a terse message if 200 or 201, and a full dump of response elsewise --- diff --git a/src/allmydata/scripts/tahoe_put.py b/src/allmydata/scripts/tahoe_put.py index 49009d95..0bdc8b2b 100644 --- a/src/allmydata/scripts/tahoe_put.py +++ b/src/allmydata/scripts/tahoe_put.py @@ -29,7 +29,7 @@ def put(serverurl, vdrive, vdrive_fname, local_fname, verbosity): so.connect((host, port,)) CHUNKSIZE=2**16 - data = "PUT %s HTTP/1.1\r\nHostname: %s\r\n\r\n" % (url, host,) + data = "PUT %s HTTP/1.1\r\nConnection: close\r\nHostname: %s\r\n\r\n" % (url, host,) while data: try: sent = so.send(data) @@ -45,17 +45,33 @@ def put(serverurl, vdrive, vdrive_fname, local_fname, verbosity): respbuf = [] data = so.recv(CHUNKSIZE) while data: - print "debuggery 1 okay now we've got some more data: %r" % (data,) + # print "debuggery 1 okay now we've got some more data: %r" % (data,) respbuf.append(data) data = so.recv(CHUNKSIZE) so.shutdown(socket.SHUT_WR) + data = so.recv(CHUNKSIZE) while data: - print "debuggery 2 okay now we've got some more data: %r" % (data,) + # print "debuggery 2 okay now we've got some more data: %r" % (data,) respbuf.append(data) data = so.recv(CHUNKSIZE) + respstr = ''.join(respbuf) + + RESP_RE=re.compile("^HTTP/[0-9]\.[0-9] ([0-9]*) *([A-Za-z_]*)") # This regex is soooo ad hoc... --Zooko 2007-08-16 + mo = RESP_RE.match(respstr) + if mo: + code = int(mo.group(1)) + word = mo.group(2) + + if code in (200, 201,): + print "%s %s" % (code, word,) + return 0 + + print respstr + return 1 + def main(): import optparse parser = optparse.OptionParser() @@ -69,7 +85,7 @@ def main(): if len(args) > 1: vdrive_file = args[1] - put(options.server, options.vdrive, vdrive_file, local_file) + return put(options.server, options.vdrive, vdrive_file, local_file) if __name__ == '__main__': main()