]> git.decadent.org.uk Git - dak.git/blob - tea
sync
[dak.git] / tea
1 #!/usr/bin/env python
2
3 # Sanity check the database
4 # Copyright (C) 2000  James Troup <james@nocrew.org>
5 # $Id: tea,v 1.3 2001-01-16 21:52:37 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 #   And, lo, a great and menacing voice rose from the depths, and with
22 #   great wrath and vehemence it's voice boomed across the
23 #   land... ``hehehehehehe... that *tickles*''
24 #                                                       -- aj on IRC
25
26 ################################################################################
27
28 import pg, sys, os, string, stat
29 import utils, db_access
30 import apt_pkg;
31
32 ################################################################################
33
34 Cnf = None;
35 projectB = None;
36 db_files = {};
37 waste = 0.0;
38 excluded = {};
39
40 def process_dir (arg, dirname, filenames):
41     global waste, db_files, excluded;
42     
43     if string.find(dirname, '/disks-') != -1 or string.find(dirname, 'upgrade-') != -1: 
44         return;
45     # hack; can't handle .changes files
46     if string.find(dirname, 'proposed-updates') != -1:
47         return;
48     for name in filenames:
49         filename = os.path.abspath(dirname+'/'+name);
50         filename = string.replace(filename, 'potato-proposed-updates', 'proposed-updates');
51         if os.path.isfile(filename) and not os.path.islink(filename) and not db_files.has_key(filename) and not excluded.has_key(filename):
52             waste = waste + os.stat(filename)[stat.ST_SIZE];
53             print filename
54
55 ################################################################################
56
57 def main ():
58     global Cnf, projectB, db_files, waste, excluded;
59
60     apt_pkg.init();
61     
62     Cnf = apt_pkg.newConfiguration();
63     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
64
65     Arguments = [('d',"debug","Tea::Options::Debug", "IntVal"),
66                  ('h',"help","Tea::Options::Help"),
67                  ('v',"version","Tea::Options::Version")];
68
69     apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
70     projectB = pg.connect('projectb', 'localhost');
71     db_access.init(Cnf, projectB);
72
73     print "Building list of Database files...";
74
75     q = projectB.query("SELECT l.path, f.filename FROM files f, location l WHERE f.location = l.id")
76     ql = q.getresult();
77
78     db_files = {};
79     for i in ql:
80         filename = os.path.abspath(i[0] + i[1]);
81         db_files[filename] = "";
82         if os.access(filename, os.R_OK) == 0:
83             sys.stderr.write("W: '%s' doesn't exist.\n" % (filename));
84
85     file = utils.open_file(Cnf["Dir::OverrideDir"]+'override.unreferenced','r');
86     for filename in file.readlines():
87         filename = filename[:-1];
88         excluded[filename] = "";
89
90     print "Checking against existent files...";
91
92     os.path.walk(Cnf["Dir::RootDir"]+'dists/', process_dir, None);
93
94     print
95     print "%s wasted..." % (utils.size_type(waste));
96
97 #######################################################################################
98
99 if __name__ == '__main__':
100     main()
101