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
27 from daklib.utils import fubar
29 ################################################################################
31 def usage(exit_code=0):
32 print """Usage: dak find-null-maintainers
33 Checks for users with no packages in the archive
35 -h, --help show this help and exit."""
38 ################################################################################
40 def get_ldap_value(entry, value):
41 ret = entry.get(value)
45 # FIXME: what about > 0 ?
51 Arguments = [('h',"help","Find-Null-Maintainers::Options::Help")]
53 if not cnf.has_key("Find-Null-Maintainers::Options::%s" % (i)):
54 cnf["Find-Null-Maintainers::Options::%s" % (i)] = ""
56 apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
58 Options = cnf.subtree("Find-Null-Maintainers::Options")
62 if not cnf.has_key('Import-LDAP-Fingerprints::LDAPServer'):
63 fubar("Import-LDAP-Fingerprints::LDAPServer not configured")
65 if not cnf.has_key('Import-LDAP-Fingerprints::LDAPDn'):
66 fubar("Import-LDAP-Fingerprints::LDAPDn not configured")
68 session = DBConn().session()
70 print "Getting info from the LDAP server..."
71 LDAPDn = cnf["Import-LDAP-Fingerprints::LDAPDn"]
72 LDAPServer = cnf["Import-LDAP-Fingerprints::LDAPServer"]
73 l = ldap.open(LDAPServer)
74 l.simple_bind_s("","")
75 Attrs = l.search_s(LDAPDn, ldap.SCOPE_ONELEVEL,
76 "(&(keyfingerprint=*)(gidnumber=%s))" % (cnf["Import-Users-From-Passwd::ValidGID"]),
77 ["uid", "cn", "mn", "sn", "createTimestamp"])
83 print "Getting UID info for entire archive..."
84 q = session.execute("SELECT DISTINCT u.uid FROM uid u, fingerprint f WHERE f.uid = u.id")
85 for i in q.fetchall():
88 print "Getting UID info for unstable..."
89 q = session.execute("""
90 SELECT DISTINCT u.uid FROM suite su, src_associations sa, source s, fingerprint f, uid u
91 WHERE f.uid = u.id AND sa.source = s.id AND sa.suite = su.id
92 AND su.suite_name = 'unstable' AND s.sig_fpr = f.id
94 SELECT DISTINCT u.uid FROM suite su, bin_associations ba, binaries b, fingerprint f, uid u
95 WHERE f.uid = u.id AND ba.bin = b.id AND ba.suite = su.id
96 AND su.suite_name = 'unstable' AND b.sig_fpr = f.id""")
97 for i in q.fetchall():
98 db_unstable_uid[i[0]] = ""
104 uid = entry["uid"][0]
105 created = time.mktime(time.strptime(entry["createTimestamp"][0][:8], '%Y%m%d'))
107 # 31536000 is 1 year in seconds, i.e. 60 * 60 * 24 * 365
108 if diff < 31536000 / 2:
109 when = "Less than 6 months ago"
110 elif diff < 31536000:
111 when = "Less than 1 year ago"
112 elif diff < 31536000 * 1.5:
113 when = "Less than 18 months ago"
114 elif diff < 31536000 * 2:
115 when = "Less than 2 years ago"
116 elif diff < 31536000 * 3:
117 when = "Less than 3 years ago"
119 when = "More than 3 years ago"
120 name = " ".join([get_ldap_value(entry, "cn"),
121 get_ldap_value(entry, "mn"),
122 get_ldap_value(entry, "sn")])
123 if not db_uid.has_key(uid):
124 print "NONE %s (%s) %s" % (uid, name, when)
126 if not db_unstable_uid.has_key(uid):
127 print "NOT_UNSTABLE %s (%s) %s" % (uid, name, when)
129 ############################################################
131 if __name__ == '__main__':