reguire gnupg1 on f>=31; sense the system to use gpg1 when installed
[nodemanager.git] / ticket.py
index c45e865..a52be17 100644 (file)
--- a/ticket.py
+++ b/ticket.py
@@ -5,10 +5,16 @@ You must already have the key in the keyring.
 """
 
 from subprocess import PIPE, Popen
-from xmlrpclib import dumps, loads
+from xmlrpc.client import dumps, loads
 
-GPG = '/usr/bin/gpg'
+# see also myplc/plc.d/gpg
+import os.path
+GPG = '/usr/bin/gpg1' if os.path.exists("/usr/bin/gpg1") else "/usr/bin/gpg"
 
+def _popen_gpg(*args):
+    """Return a Popen object to GPG."""
+    return Popen((GPG, '--batch', '--no-tty') + args,
+                 stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
 
 def sign(data):
     """Return <data> signed with the default GPG key."""
@@ -30,11 +36,8 @@ def verify(signed_msg):
     msg = p.stdout.read()
     p.stdout.close()
     p.stderr.close()
-    if p.wait(): return None  # verification failed
+    if p.wait():
+        return None  # verification failed
     else:
         data, = loads(msg)[0]
         return data
-
-def _popen_gpg(*args):
-    """Return a Popen object to GPG."""
-    return Popen((GPG, '--batch', '--no-tty') + args, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)