X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=curlwrapper.py;h=4383a70fbafa64370be94e5e3e9ab5e5a531acea;hb=570d234b7d7b40416b296de71225f28c826ee991;hp=bed1b3cad95e4458748dd3656305c20e1a190e0e;hpb=3f01a8df5899602098c79b61b46ff54b48b1ae75;p=nodemanager.git diff --git a/curlwrapper.py b/curlwrapper.py index bed1b3c..4383a70 100644 --- a/curlwrapper.py +++ b/curlwrapper.py @@ -13,22 +13,29 @@ import os import logger +verbose=False +#verbose=True + class Sopen(Popen): def kill(self, signal = signal.SIGTERM): os.kill(self.pid, signal) def retrieve(url, cacert=None, postdata=None, timeout=90): -# options = ('/usr/bin/curl', '--fail', '--silent') - options = ('/usr/bin/curl', '--fail', ) - if cacert: options += ('--cacert', cacert) - if postdata: options += ('--data', '@-') +# command = ('/usr/bin/curl', '--fail', '--silent') + command = ('/usr/bin/curl', '--fail', ) + if cacert: command += ('--cacert', cacert) + if postdata: command += ('--data', '@-') if timeout: - options += ('--max-time', str(timeout)) - options += ('--connect-timeout', str(timeout)) - p = Sopen(options + (url,), stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) + command += ('--max-time', str(timeout)) + command += ('--connect-timeout', str(timeout)) + command += (url, ) + if verbose: + print 'Invoking ', command + if postdata: print 'with postdata=', postdata + p = Sopen(command , stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) if postdata: p.stdin.write(postdata) p.stdin.close() - sout, sin, serr = select([p.stdout,p.stderr],[],[], timeout) + sout, sin, serr = select([p.stdout, p.stderr], [], [], timeout) if len(sout) == 0 and len(sin) == 0 and len(serr) == 0: logger.verbose("curlwrapper: timed out after %s" % timeout) p.kill(signal.SIGKILL)