X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=curlwrapper.py;h=e2595789ac0304b28203fbe69c5b3c234b150e8d;hb=refs%2Fheads%2F1.5;hp=ce273a304968ec9683ab3f75ced80641a9a5c8e8;hpb=191f762aee7f7412e3d3b3840de914b9326aa888;p=nodemanager.git diff --git a/curlwrapper.py b/curlwrapper.py index ce273a3..e259578 100644 --- a/curlwrapper.py +++ b/curlwrapper.py @@ -3,10 +3,12 @@ from subprocess import PIPE, Popen class CurlException(Exception): pass -def retrieve(url, postdata=None): - options = ('/usr/bin/curl', '--cacert', '/usr/boot/cacert.pem') +def retrieve(url, cacert=None, postdata=None, timeout=300): + options = ('/usr/bin/curl', '--fail', '--silent') + if cacert: options += ('--cacert', cacert) if postdata: options += ('--data', '@-') - p = Popen(options + (url,), stdin=PIPE, stdout=PIPE, stderr=PIPE) + if timeout: options += ('--max-time', str(timeout)) + p = Popen(options + (url,), stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) if postdata: p.stdin.write(postdata) p.stdin.close() data = p.stdout.read()