]> git.donarmstrong.com Git - dak.git/blob - dak/find_null_maintainers.py
Merge branch 'merge'
[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 from daklib.utils import fubar
28
29 ################################################################################
30
31 def usage(exit_code=0):
32     print """Usage: dak find-null-maintainers
33 Checks for users with no packages in the archive
34
35   -h, --help                show this help and exit."""
36     sys.exit(exit_code)
37
38 ################################################################################
39
40 def get_ldap_value(entry, value):
41     ret = entry.get(value)
42     if not ret:
43         return ""
44     else:
45         # FIXME: what about > 0 ?
46         return ret[0]
47
48 def main():
49     cnf = Config()
50
51     Arguments = [('h',"help","Find-Null-Maintainers::Options::Help")]
52     for i in [ "help" ]:
53         if not cnf.has_key("Find-Null-Maintainers::Options::%s" % (i)):
54             cnf["Find-Null-Maintainers::Options::%s" % (i)] = ""
55
56     apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
57
58     Options = cnf.subtree("Find-Null-Maintainers::Options")
59     if Options["Help"]:
60         usage()
61
62     if not cnf.has_key('Import-LDAP-Fingerprints::LDAPServer'):
63         fubar("Import-LDAP-Fingerprints::LDAPServer not configured")
64
65     if not cnf.has_key('Import-LDAP-Fingerprints::LDAPDn'):
66         fubar("Import-LDAP-Fingerprints::LDAPDn not configured")
67
68     session = DBConn().session()
69
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"])
78
79
80     db_uid = {}
81     db_unstable_uid = {}
82
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():
86         db_uid[i[0]] = ""
87
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
93 UNION
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]] = ""
99
100     now = time.time()
101
102     for i in Attrs:
103         entry = i[1]
104         uid = entry["uid"][0]
105         created = time.mktime(time.strptime(entry["createTimestamp"][0][:8], '%Y%m%d'))
106         diff = now - created
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"
118         else:
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)
125         else:
126             if not db_unstable_uid.has_key(uid):
127                 print "NOT_UNSTABLE %s (%s) %s" % (uid, name, when)
128
129 ############################################################
130
131 if __name__ == '__main__':
132     main()