]> git.decadent.org.uk Git - dak.git/blobdiff - dak/find_null_maintainers.py
Merge branch 'master' into rm
[dak.git] / dak / find_null_maintainers.py
index d133064a322ef8abba4799886b54d3a2f8a359f0..730b277008a976f09af12a343b99cd555193ac5a 100755 (executable)
@@ -1,8 +1,7 @@
 #!/usr/bin/env python
 
-# Check for users with no packages in the archive
-# Copyright (C) 2003  James Troup <james@nocrew.org>
-# $Id: rosamund,v 1.1 2003-09-07 13:48:51 troup Exp $
+""" Check for users with no packages in the archive """
+# Copyright (C) 2003, 2006  James Troup <james@nocrew.org>
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 
 ################################################################################
 
-import ldap, pg, sys, time;
-import apt_pkg;
-import utils;
+import ldap, sys, time
+import apt_pkg
 
-################################################################################
-
-Cnf = None;
-projectB = None;
+from daklib.dbconn import *
+from daklib.config import Config
+from daklib.utils import fubar
 
 ################################################################################
 
 def usage(exit_code=0):
-    print """Usage: rosamund
+    print """Usage: dak find-null-maintainers
 Checks for users with no packages in the archive
 
   -h, --help                show this help and exit."""
@@ -41,94 +38,93 @@ Checks for users with no packages in the archive
 ################################################################################
 
 def get_ldap_value(entry, value):
-    ret = entry.get(value);
+    ret = entry.get(value)
     if not ret:
-        return "";
+        return ""
     else:
         # FIXME: what about > 0 ?
-        return ret[0];
+        return ret[0]
 
 def main():
-    global Cnf, projectB;
+    cnf = Config()
 
-    Cnf = utils.get_conf()
-    Arguments = [('h',"help","Rosamund::Options::Help")];
+    Arguments = [('h',"help","Find-Null-Maintainers::Options::Help")]
     for i in [ "help" ]:
-       if not Cnf.has_key("Rosamund::Options::%s" % (i)):
-           Cnf["Rosamund::Options::%s" % (i)] = "";
+        if not cnf.has_key("Find-Null-Maintainers::Options::%s" % (i)):
+            cnf["Find-Null-Maintainers::Options::%s" % (i)] = ""
 
-    apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv);
+    apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
 
-    Options = Cnf.SubTree("Rosamund::Options")
+    Options = cnf.SubTree("Find-Null-Maintainers::Options")
     if Options["Help"]:
-       usage();
+        usage()
+
+    if not cnf.has_key('Import-LDAP-Fingerprints::LDAPServer'):
+        fubar("Import-LDAP-Fingerprints::LDAPServer not configured")
+
+    if not cnf.has_key('Import-LDAP-Fingerprints::LDAPDn'):
+        fubar("Import-LDAP-Fingerprints::LDAPDn not configured")
 
-    projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
+    session = DBConn().session()
 
-    before = time.time();
-    sys.stderr.write("[Getting info from the LDAP server...");
-    LDAPDn = Cnf["Emilie::LDAPDn"];
-    LDAPServer = Cnf["Emilie::LDAPServer"];
-    l = ldap.open(LDAPServer);
-    l.simple_bind_s("","");
+    print "Getting info from the LDAP server..."
+    LDAPDn = cnf["Import-LDAP-Fingerprints::LDAPDn"]
+    LDAPServer = cnf["Import-LDAP-Fingerprints::LDAPServer"]
+    l = ldap.open(LDAPServer)
+    l.simple_bind_s("","")
     Attrs = l.search_s(LDAPDn, ldap.SCOPE_ONELEVEL,
-                       "(&(keyfingerprint=*)(gidnumber=%s))" % (Cnf["Julia::ValidGID"]),
-                       ["uid", "cn", "mn", "sn", "createtimestamp"]);
-    sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before)));
+                       "(&(keyfingerprint=*)(gidnumber=%s))" % (cnf["Import-Users-From-Passwd::ValidGID"]),
+                       ["uid", "cn", "mn", "sn", "createTimestamp"])
 
 
-    db_uid = {};
-    db_unstable_uid = {};
+    db_uid = {}
+    db_unstable_uid = {}
 
-    before = time.time();
-    sys.stderr.write("[Getting UID info for entire archive...");
-    q = projectB.query("SELECT DISTINCT u.uid FROM uid u, fingerprint f WHERE f.uid = u.id;");
-    sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before)));
-    for i in q.getresult():
-        db_uid[i[0]] = "";
+    print "Getting UID info for entire archive..."
+    q = session.execute("SELECT DISTINCT u.uid FROM uid u, fingerprint f WHERE f.uid = u.id")
+    for i in q.fetchall():
+        db_uid[i[0]] = ""
 
-    before = time.time();
-    sys.stderr.write("[Getting UID info for unstable...");
-    q = projectB.query("""
+    print "Getting UID info for unstable..."
+    q = session.execute("""
 SELECT DISTINCT u.uid FROM suite su, src_associations sa, source s, fingerprint f, uid u
  WHERE f.uid = u.id AND sa.source = s.id AND sa.suite = su.id
    AND su.suite_name = 'unstable' AND s.sig_fpr = f.id
 UNION
 SELECT DISTINCT u.uid FROM suite su, bin_associations ba, binaries b, fingerprint f, uid u
  WHERE f.uid = u.id AND ba.bin = b.id AND ba.suite = su.id
-   AND su.suite_name = 'unstable' AND b.sig_fpr = f.id""");
-    sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before)));
-    for i in q.getresult():
-        db_unstable_uid[i[0]] = "";
+   AND su.suite_name = 'unstable' AND b.sig_fpr = f.id""")
+    for i in q.fetchall():
+        db_unstable_uid[i[0]] = ""
 
-    now = time.time();
+    now = time.time()
 
     for i in Attrs:
-        entry = i[1];
-        uid = entry["uid"][0];
-        created = time.mktime(time.strptime(entry["createtimestamp"][0][:8], '%Y%m%d'));
-        diff = now - created;
+        entry = i[1]
+        uid = entry["uid"][0]
+        created = time.mktime(time.strptime(entry["createTimestamp"][0][:8], '%Y%m%d'))
+        diff = now - created
         # 31536000 is 1 year in seconds, i.e. 60 * 60 * 24 * 365
         if diff < 31536000 / 2:
-            when = "Less than 6 months ago";
+            when = "Less than 6 months ago"
         elif diff < 31536000:
-            when = "Less than 1 year ago";
+            when = "Less than 1 year ago"
         elif diff < 31536000 * 1.5:
-            when = "Less than 18 months ago";
+            when = "Less than 18 months ago"
         elif diff < 31536000 * 2:
-            when = "Less than 2 years ago";
+            when = "Less than 2 years ago"
         elif diff < 31536000 * 3:
-            when = "Less than 3 years ago";
+            when = "Less than 3 years ago"
         else:
-            when = "More than 3 years ago";
+            when = "More than 3 years ago"
         name = " ".join([get_ldap_value(entry, "cn"),
                          get_ldap_value(entry, "mn"),
-                         get_ldap_value(entry, "sn")]);
+                         get_ldap_value(entry, "sn")])
         if not db_uid.has_key(uid):
-            print "NONE %s (%s) %s" % (uid, name, when);
+            print "NONE %s (%s) %s" % (uid, name, when)
         else:
             if not db_unstable_uid.has_key(uid):
-                print "NOT_UNSTABLE %s (%s) %s" % (uid, name, when);
+                print "NOT_UNSTABLE %s (%s) %s" % (uid, name, when)
 
 ############################################################