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 $
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.
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.
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
21 ################################################################################
23 import ldap, pg, sys, time;
27 ################################################################################
32 ################################################################################
34 def usage(exit_code=0):
35 print """Usage: rosamund
36 Checks for users with no packages in the archive
38 -h, --help show this help and exit."""
41 ################################################################################
43 def get_ldap_value(entry, value):
44 ret = entry.get(value);
48 # FIXME: what about > 0 ?
54 Cnf = utils.get_conf()
55 Arguments = [('h',"help","Rosamund::Options::Help")];
57 if not Cnf.has_key("Rosamund::Options::%s" % (i)):
58 Cnf["Rosamund::Options::%s" % (i)] = "";
60 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv);
62 Options = Cnf.SubTree("Rosamund::Options")
66 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
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)));
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():
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
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]] = "";
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";
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);
130 if not db_unstable_uid.has_key(uid):
131 print "NOT_UNSTABLE %s (%s) %s" % (uid, name, when);
133 ############################################################
135 if __name__ == '__main__':