lib/bpgpg.py: add simple gpg helper for gpg signing
authorLuis R. Rodriguez <mcgrof@do-not-panic.com>
Mon, 21 Oct 2013 09:08:30 +0000 (11:08 +0200)
committerHauke Mehrtens <hauke@hauke-m.de>
Mon, 21 Oct 2013 19:50:38 +0000 (21:50 +0200)
Note that kup expects --armor --detach-sign, we'll pass that
as part of our extra_args. The python gpg lib doesn't provide
support for random arguments as this one, so just add our
own little helper and carry it over.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
lib/bpgpg.py [new file with mode: 0644]

diff --git a/lib/bpgpg.py b/lib/bpgpg.py
new file mode 100644 (file)
index 0000000..3b5ec78
--- /dev/null
@@ -0,0 +1,22 @@
+import subprocess, os
+
+class GpgError(Exception):
+    pass
+class ExecutionError(GpgError):
+    def __init__(self, errcode):
+        self.error_code = errcode
+
+def sign(input_file, extra_args=[]):
+    cmd = ['gpg', '--sign']
+
+    cmd.extend(extra_args)
+    cmd.append(input_file)
+
+    process = subprocess.Popen(cmd,
+                               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+                               close_fds=True, universal_newlines=True)
+    stdout = process.communicate()[0]
+    process.wait()
+    if process.returncode != 0:
+        raise ExecutionError(process.returncode)
+    return stdout