3 # Sanity check the database
4 # Copyright (C) 2000 James Troup <james@nocrew.org>
5 # $Id: tea,v 1.5 2001-02-04 04:27:58 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 # 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*''
26 ################################################################################
28 import pg, sys, os, string, stat
29 import utils, db_access
32 ################################################################################
40 def process_dir (arg, dirname, filenames):
41 global waste, db_files, excluded;
43 if string.find(dirname, '/disks-') != -1 or string.find(dirname, 'upgrade-') != -1:
45 # hack; can't handle .changes files
46 if string.find(dirname, 'proposed-updates') != -1:
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];
54 ################################################################################
58 print "Building list of Database files...";
60 q = projectB.query("SELECT l.path, f.filename FROM files f, location l WHERE f.location = l.id")
65 filename = os.path.abspath(i[0] + i[1]);
66 db_files[filename] = "";
67 if os.access(filename, os.R_OK) == 0:
68 sys.stderr.write("W: '%s' doesn't exist.\n" % (filename));
70 file = utils.open_file(Cnf["Dir::OverrideDir"]+'override.unreferenced','r');
71 for filename in file.readlines():
72 filename = filename[:-1];
73 excluded[filename] = "";
75 print "Checking against existent files...";
77 os.path.walk(Cnf["Dir::RootDir"]+'dists/', process_dir, None);
80 print "%s wasted..." % (utils.size_type(waste));
82 ################################################################################
87 for component in Cnf.SubTree("Component").List():
88 if component == "mixed":
90 component = string.lower(component);
91 list_filename = '%s%s_%s_source.list' % (Cnf["Dir::ListsDir"], suite, component);
92 list_file = utils.open_file(list_filename, 'r');
93 for line in list_file.readlines():
96 utils.parse_changes(file, 1);
97 except utils.invalid_dsc_format_exc, line:
98 sys.stderr.write("E: syntax error in .dsc file '%s', line %s.\n" % (file, line));
102 sys.stderr.write("Found %s invalid .dsc files.\n" % (count));
104 def check_override():
105 for suite in [ "stable", "unstable" ]:
107 print "-------------"
109 suite_id = db_access.get_suite_id(suite);
110 q = projectB.query("""
111 SELECT DISTINCT b.package FROM binaries b, bin_associations ba
112 WHERE b.id = ba.bin AND ba.suite = %s AND NOT EXISTS
113 (SELECT * FROM override o WHERE o.suite = %s AND o.package = b.package)"""
114 % (suite_id, suite_id));
116 q = projectB.query("""
117 SELECT DISTINCT s.source FROM source s, src_associations sa
118 WHERE s.id = sa.source AND sa.suite = %s AND NOT EXISTS
119 (SELECT * FROM override o WHERE o.suite = %s and o.package = s.source)"""
120 % (suite_id, suite_id));
123 ################################################################################
126 global Cnf, projectB, db_files, waste, excluded;
130 Cnf = apt_pkg.newConfiguration();
131 apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
133 Arguments = [('d',"debug","Tea::Options::Debug", "IntVal"),
134 ('h',"help","Tea::Options::Help"),
135 ('v',"version","Tea::Options::Version")];
137 apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
138 projectB = pg.connect('projectb', 'localhost');
139 db_access.init(Cnf, projectB);
145 #######################################################################################
147 if __name__ == '__main__':