]> git.decadent.org.uk Git - dak.git/blob - rosamund
Add new top level directories
[dak.git] / rosamund
1 #!/usr/bin/env python
2
3 # Check for users with no packages in the archive
4 # Copyright (C) 2003  James Troup <james@nocrew.org>
5 # $Id: rosamund,v 1.1 2003-09-07 13:48:51 troup Exp $
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21 ################################################################################
22
23 import ldap, pg, sys, time;
24 import apt_pkg;
25 import utils;
26
27 ################################################################################
28
29 Cnf = None;
30 projectB = None;
31
32 ################################################################################
33
34 def usage(exit_code=0):
35     print """Usage: rosamund
36 Checks for users with no packages in the archive
37
38   -h, --help                show this help and exit."""
39     sys.exit(exit_code)
40
41 ################################################################################
42
43 def get_ldap_value(entry, value):
44     ret = entry.get(value);
45     if not ret:
46         return "";
47     else:
48         # FIXME: what about > 0 ?
49         return ret[0];
50
51 def main():
52     global Cnf, projectB;
53
54     Cnf = utils.get_conf()
55     Arguments = [('h',"help","Rosamund::Options::Help")];
56     for i in [ "help" ]:
57         if not Cnf.has_key("Rosamund::Options::%s" % (i)):
58             Cnf["Rosamund::Options::%s" % (i)] = "";
59
60     apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv);
61
62     Options = Cnf.SubTree("Rosamund::Options")
63     if Options["Help"]:
64         usage();
65
66     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
67
68     before = time.time();
69     sys.stderr.write("[Getting info from the LDAP server...");
70     LDAPDn = Cnf["Emilie::LDAPDn"];
71     LDAPServer = Cnf["Emilie::LDAPServer"];
72     l = ldap.open(LDAPServer);
73     l.simple_bind_s("","");
74     Attrs = l.search_s(LDAPDn, ldap.SCOPE_ONELEVEL,
75                        "(&(keyfingerprint=*)(gidnumber=%s))" % (Cnf["Julia::ValidGID"]),
76                        ["uid", "cn", "mn", "sn", "createtimestamp"]);
77     sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before)));
78
79
80     db_uid = {};
81     db_unstable_uid = {};
82
83     before = time.time();
84     sys.stderr.write("[Getting UID info for entire archive...");
85     q = projectB.query("SELECT DISTINCT u.uid FROM uid u, fingerprint f WHERE f.uid = u.id;");
86     sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before)));
87     for i in q.getresult():
88         db_uid[i[0]] = "";
89
90     before = time.time();
91     sys.stderr.write("[Getting UID info for unstable...");
92     q = projectB.query("""
93 SELECT DISTINCT u.uid FROM suite su, src_associations sa, source s, fingerprint f, uid u
94  WHERE f.uid = u.id AND sa.source = s.id AND sa.suite = su.id
95    AND su.suite_name = 'unstable' AND s.sig_fpr = f.id
96 UNION
97 SELECT DISTINCT u.uid FROM suite su, bin_associations ba, binaries b, fingerprint f, uid u
98  WHERE f.uid = u.id AND ba.bin = b.id AND ba.suite = su.id
99    AND su.suite_name = 'unstable' AND b.sig_fpr = f.id""");
100     sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before)));
101     for i in q.getresult():
102         db_unstable_uid[i[0]] = "";
103
104     now = time.time();
105
106     for i in Attrs:
107         entry = i[1];
108         uid = entry["uid"][0];
109         created = time.mktime(time.strptime(entry["createtimestamp"][0][:8], '%Y%m%d'));
110         diff = now - created;
111         # 31536000 is 1 year in seconds, i.e. 60 * 60 * 24 * 365
112         if diff < 31536000 / 2:
113             when = "Less than 6 months ago";
114         elif diff < 31536000:
115             when = "Less than 1 year ago";
116         elif diff < 31536000 * 1.5:
117             when = "Less than 18 months ago";
118         elif diff < 31536000 * 2:
119             when = "Less than 2 years ago";
120         elif diff < 31536000 * 3:
121             when = "Less than 3 years ago";
122         else:
123             when = "More than 3 years ago";
124         name = " ".join([get_ldap_value(entry, "cn"),
125                          get_ldap_value(entry, "mn"),
126                          get_ldap_value(entry, "sn")]);
127         if not db_uid.has_key(uid):
128             print "NONE %s (%s) %s" % (uid, name, when);
129         else:
130             if not db_unstable_uid.has_key(uid):
131                 print "NOT_UNSTABLE %s (%s) %s" % (uid, name, when);
132
133 ############################################################
134
135 if __name__ == '__main__':
136     main()