]> git.decadent.org.uk Git - dak.git/blob - dak/find_null_maintainers.py
lotsa files
[dak.git] / dak / find_null_maintainers.py
1 #!/usr/bin/env python
2
3 """ Check for users with no packages in the archive """
4 # Copyright (C) 2003, 2006  James Troup <james@nocrew.org>
5
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.
10
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.
15
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
19
20 ################################################################################
21
22 import ldap, pg, sys, time
23 import apt_pkg
24 from daklib import utils
25
26 ################################################################################
27
28 Cnf = None
29 projectB = None
30
31 ################################################################################
32
33 def usage(exit_code=0):
34     print """Usage: dak find-null-maintainers
35 Checks for users with no packages in the archive
36
37   -h, --help                show this help and exit."""
38     sys.exit(exit_code)
39
40 ################################################################################
41
42 def get_ldap_value(entry, value):
43     ret = entry.get(value)
44     if not ret:
45         return ""
46     else:
47         # FIXME: what about > 0 ?
48         return ret[0]
49
50 def main():
51     global Cnf, projectB
52
53     Cnf = utils.get_conf()
54     Arguments = [('h',"help","Find-Null-Maintainers::Options::Help")]
55     for i in [ "help" ]:
56         if not Cnf.has_key("Find-Null-Maintainers::Options::%s" % (i)):
57             Cnf["Find-Null-Maintainers::Options::%s" % (i)] = ""
58
59     apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
60
61     Options = Cnf.SubTree("Find-Null-Maintainers::Options")
62     if Options["Help"]:
63         usage()
64
65     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
66
67     before = time.time()
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)))
77
78
79     db_uid = {}
80     db_unstable_uid = {}
81
82     before = time.time()
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():
87         db_uid[i[0]] = ""
88
89     before = time.time()
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
95 UNION
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]] = ""
102
103     now = time.time()
104
105     for i in Attrs:
106         entry = i[1]
107         uid = entry["uid"][0]
108         created = time.mktime(time.strptime(entry["createTimestamp"][0][:8], '%Y%m%d'))
109         diff = now - created
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"
121         else:
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)
128         else:
129             if not db_unstable_uid.has_key(uid):
130                 print "NOT_UNSTABLE %s (%s) %s" % (uid, name, when)
131
132 ############################################################
133
134 if __name__ == '__main__':
135     main()