]> git.decadent.org.uk Git - dak.git/blob - dak/find_null_maintainers.py
Only log, if there is something to log
[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, sys, time
23 import apt_pkg
24
25 from daklib.dbconn import *
26 from daklib.config import Config
27
28 ################################################################################
29
30 def usage(exit_code=0):
31     print """Usage: dak find-null-maintainers
32 Checks for users with no packages in the archive
33
34   -h, --help                show this help and exit."""
35     sys.exit(exit_code)
36
37 ################################################################################
38
39 def get_ldap_value(entry, value):
40     ret = entry.get(value)
41     if not ret:
42         return ""
43     else:
44         # FIXME: what about > 0 ?
45         return ret[0]
46
47 def main():
48     cnf = Config()
49
50     Arguments = [('h',"help","Find-Null-Maintainers::Options::Help")]
51     for i in [ "help" ]:
52         if not cnf.has_key("Find-Null-Maintainers::Options::%s" % (i)):
53             cnf["Find-Null-Maintainers::Options::%s" % (i)] = ""
54
55     apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
56
57     Options = cnf.SubTree("Find-Null-Maintainers::Options")
58     if Options["Help"]:
59         usage()
60
61     session = DBConn().session()
62
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"])
71
72
73     db_uid = {}
74     db_unstable_uid = {}
75
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():
79         db_uid[i[0]] = ""
80
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
86 UNION
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]] = ""
92
93     now = time.time()
94
95     for i in Attrs:
96         entry = i[1]
97         uid = entry["uid"][0]
98         created = time.mktime(time.strptime(entry["createTimestamp"][0][:8], '%Y%m%d'))
99         diff = now - created
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"
111         else:
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)
118         else:
119             if not db_unstable_uid.has_key(uid):
120                 print "NOT_UNSTABLE %s (%s) %s" % (uid, name, when)
121
122 ############################################################
123
124 if __name__ == '__main__':
125     main()