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, pg, sys, time
24 from daklib import utils
26 ################################################################################
31 ################################################################################
33 def usage(exit_code=0):
34 print """Usage: dak find-null-maintainers
35 Checks for users with no packages in the archive
37 -h, --help show this help and exit."""
40 ################################################################################
42 def get_ldap_value(entry, value):
43 ret = entry.get(value)
47 # FIXME: what about > 0 ?
53 Cnf = utils.get_conf()
54 Arguments = [('h',"help","Find-Null-Maintainers::Options::Help")]
56 if not Cnf.has_key("Find-Null-Maintainers::Options::%s" % (i)):
57 Cnf["Find-Null-Maintainers::Options::%s" % (i)] = ""
59 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
61 Options = Cnf.SubTree("Find-Null-Maintainers::Options")
65 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
68 sys.stderr.write("[Getting info from the LDAP server...")
69 LDAPDn = Cnf["Import-LDAP-Fingerprints::LDAPDn"]
70 LDAPServer = Cnf["Import-LDAP-Fingerprints::LDAPServer"]
71 l = ldap.open(LDAPServer)
72 l.simple_bind_s("","")
73 Attrs = l.search_s(LDAPDn, ldap.SCOPE_ONELEVEL,
74 "(&(keyfingerprint=*)(gidnumber=%s))" % (Cnf["Import-Users-From-Passwd::ValidGID"]),
75 ["uid", "cn", "mn", "sn", "createTimestamp"])
76 sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before)))
83 sys.stderr.write("[Getting UID info for entire archive...")
84 q = projectB.query("SELECT DISTINCT u.uid FROM uid u, fingerprint f WHERE f.uid = u.id;")
85 sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before)))
86 for i in q.getresult():
90 sys.stderr.write("[Getting UID info for unstable...")
91 q = projectB.query("""
92 SELECT DISTINCT u.uid FROM suite su, src_associations sa, source s, fingerprint f, uid u
93 WHERE f.uid = u.id AND sa.source = s.id AND sa.suite = su.id
94 AND su.suite_name = 'unstable' AND s.sig_fpr = f.id
96 SELECT DISTINCT u.uid FROM suite su, bin_associations ba, binaries b, fingerprint f, uid u
97 WHERE f.uid = u.id AND ba.bin = b.id AND ba.suite = su.id
98 AND su.suite_name = 'unstable' AND b.sig_fpr = f.id""")
99 sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before)))
100 for i in q.getresult():
101 db_unstable_uid[i[0]] = ""
107 uid = entry["uid"][0]
108 created = time.mktime(time.strptime(entry["createTimestamp"][0][:8], '%Y%m%d'))
110 # 31536000 is 1 year in seconds, i.e. 60 * 60 * 24 * 365
111 if diff < 31536000 / 2:
112 when = "Less than 6 months ago"
113 elif diff < 31536000:
114 when = "Less than 1 year ago"
115 elif diff < 31536000 * 1.5:
116 when = "Less than 18 months ago"
117 elif diff < 31536000 * 2:
118 when = "Less than 2 years ago"
119 elif diff < 31536000 * 3:
120 when = "Less than 3 years ago"
122 when = "More than 3 years ago"
123 name = " ".join([get_ldap_value(entry, "cn"),
124 get_ldap_value(entry, "mn"),
125 get_ldap_value(entry, "sn")])
126 if not db_uid.has_key(uid):
127 print "NONE %s (%s) %s" % (uid, name, when)
129 if not db_unstable_uid.has_key(uid):
130 print "NOT_UNSTABLE %s (%s) %s" % (uid, name, when)
132 ############################################################
134 if __name__ == '__main__':