reguire gnupg1 on f>=31; sense the system to use gpg1 when installed
[nodemanager.git] / curlwrapper.py
index bed1b3c..a877b07 100644 (file)
@@ -7,28 +7,35 @@
 
 from subprocess import PIPE, Popen
 from select import select
-import xmlrpclib
+import xmlrpc.client
 import signal
 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) 
@@ -38,6 +45,6 @@ def retrieve(url, cacert=None, postdata=None, timeout=90):
     if rc != 0: 
         # when this triggers, the error sometimes doesn't get printed
         logger.log ("curlwrapper: retrieve, got stderr <%s>"%err)
-        raise xmlrpclib.ProtocolError(url, rc, err, postdata)
+        raise xmlrpc.client.ProtocolError(url, rc, err, postdata)
     else: 
         return data