]> git.decadent.org.uk Git - dak.git/blobdiff - daklib/utils.py
Merge mainline
[dak.git] / daklib / utils.py
index f2024b98efef662f25ecdf7411f2352c92607431..0d22bd1d236ec11b6ccf88c9632f5dd72d95bd68 100755 (executable)
@@ -41,6 +41,7 @@ re_multi_line_field = re.compile(r"^\s(.*)")
 re_taint_free = re.compile(r"^[-+~/\.\w]+$")
 
 re_parse_maintainer = re.compile(r"^\s*(\S.*\S)\s*\<([^\>]+)\>")
+re_gpg_uid = re.compile('^uid.*<([^>]*)>')
 
 re_srchasver = re.compile(r"^(\S+)\s+\((\S+)\)$")
 re_verwithext = re.compile(r"^(\d+)(?:\.(\d+))(?:\s+\((\S+)\))?$")
@@ -59,6 +60,9 @@ tried_too_hard_exc = "Tried too hard to find a free filename."
 default_config = "/etc/dak/dak.conf"
 default_apt_config = "/etc/dak/apt.conf"
 
+alias_cache = None
+key_uid_email_cache = {}
+
 ################################################################################
 
 class Error(Exception):
@@ -1089,6 +1093,25 @@ used."""
 
 ################################################################################
 
+def gpg_get_key_addresses(fingerprint):
+  """retreive email addresses from gpg key uids for a given fingerprint"""
+  addresses = key_uid_email_cache.get(fingerprint)
+  if addresses != None:
+      return addresses
+  addresses = set()
+  cmd = "gpg --no-default-keyring %s --fingerprint %s" \
+              % (gpg_keyring_args(), fingerprint)
+  (result, output) = commands.getstatusoutput(cmd)
+  if result == 0:
+    for l in output.split('\n'):
+      m = re_gpg_uid.match(l)
+      if m:
+        addresses.add(m.group(1))
+  key_uid_email_cache[fingerprint] = addresses
+  return addresses
+
+################################################################################
+
 # Inspired(tm) by http://www.zopelabs.com/cookbook/1022242603
 
 def wrap(paragraph, max_length, prefix=""):
@@ -1159,14 +1182,15 @@ If 'dotprefix' is non-null, the filename will be prefixed with a '.'."""
 # checks if the user part of the email is listed in the alias file
 
 def is_email_alias(email):
-  aliasfn = which_alias_file()
-  uid = email.split('@')[0]
-  if not aliasfn:
-      return False
-  for l in open(aliasfn):
-      if l.startswith(uid+': '):
-          return True
-  return False
+    global alias_cache
+    if alias_cache == None:
+        aliasfn = which_alias_file()
+        alias_cache = set()
+        if aliasfn:
+            for l in open(aliasfn):
+                alias_cache.add(l.split(':')[0])
+    uid = email.split('@')[0]
+    return uid in alias_cache
 
 ################################################################################