3 """ Check for users with no packages in the archive """
4 # Copyright (C) 2003, 2006 James Troup <james@nocrew.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ################################################################################
22 import ldap, sys, time
25 from daklib.dbconn import *
26 from daklib.config import Config
28 ################################################################################
30 def usage(exit_code=0):
31 print """Usage: dak find-null-maintainers
32 Checks for users with no packages in the archive
34 -h, --help show this help and exit."""
37 ################################################################################
39 def get_ldap_value(entry, value):
40 ret = entry.get(value)
44 # FIXME: what about > 0 ?
50 Arguments = [('h',"help","Find-Null-Maintainers::Options::Help")]
52 if not cnf.has_key("Find-Null-Maintainers::Options::%s" % (i)):
53 cnf["Find-Null-Maintainers::Options::%s" % (i)] = ""
55 apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
57 Options = cnf.SubTree("Find-Null-Maintainers::Options")
61 session = DBConn().session()
63 print "Getting info from the LDAP server..."
64 LDAPDn = cnf["Import-LDAP-Fingerprints::LDAPDn"]
65 LDAPServer = cnf["Import-LDAP-Fingerprints::LDAPServer"]
66 l = ldap.open(LDAPServer)
67 l.simple_bind_s("","")
68 Attrs = l.search_s(LDAPDn, ldap.SCOPE_ONELEVEL,
69 "(&(keyfingerprint=*)(gidnumber=%s))" % (cnf["Import-Users-From-Passwd::ValidGID"]),
70 ["uid", "cn", "mn", "sn", "createTimestamp"])
76 print "Getting UID info for entire archive..."
77 q = session.execute("SELECT DISTINCT u.uid FROM uid u, fingerprint f WHERE f.uid = u.id")
78 for i in q.fetchall():
81 print "Getting UID info for unstable..."
82 q = session.execute("""
83 SELECT DISTINCT u.uid FROM suite su, src_associations sa, source s, fingerprint f, uid u
84 WHERE f.uid = u.id AND sa.source = s.id AND sa.suite = su.id
85 AND su.suite_name = 'unstable' AND s.sig_fpr = f.id
87 SELECT DISTINCT u.uid FROM suite su, bin_associations ba, binaries b, fingerprint f, uid u
88 WHERE f.uid = u.id AND ba.bin = b.id AND ba.suite = su.id
89 AND su.suite_name = 'unstable' AND b.sig_fpr = f.id""")
90 for i in q.fetchall():
91 db_unstable_uid[i[0]] = ""
98 created = time.mktime(time.strptime(entry["createTimestamp"][0][:8], '%Y%m%d'))
100 # 31536000 is 1 year in seconds, i.e. 60 * 60 * 24 * 365
101 if diff < 31536000 / 2:
102 when = "Less than 6 months ago"
103 elif diff < 31536000:
104 when = "Less than 1 year ago"
105 elif diff < 31536000 * 1.5:
106 when = "Less than 18 months ago"
107 elif diff < 31536000 * 2:
108 when = "Less than 2 years ago"
109 elif diff < 31536000 * 3:
110 when = "Less than 3 years ago"
112 when = "More than 3 years ago"
113 name = " ".join([get_ldap_value(entry, "cn"),
114 get_ldap_value(entry, "mn"),
115 get_ldap_value(entry, "sn")])
116 if not db_uid.has_key(uid):
117 print "NONE %s (%s) %s" % (uid, name, when)
119 if not db_unstable_uid.has_key(uid):
120 print "NOT_UNSTABLE %s (%s) %s" % (uid, name, when)
122 ############################################################
124 if __name__ == '__main__':