3 # Sanity check the database
4 # Copyright (C) 2000, 2001 James Troup <james@nocrew.org>
5 # $Id: tea,v 1.11 2001-06-22 22:53:14 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 ################################################################################
59 print "Building list of Database files...";
61 q = projectB.query("SELECT l.path, f.filename FROM files f, location l WHERE f.location = l.id")
66 filename = os.path.abspath(i[0] + i[1]);
67 db_files[filename] = "";
68 if os.access(filename, os.R_OK) == 0:
69 utils.warn("'%s' doesn't exist." % (filename));
71 file = utils.open_file(Cnf["Dir::OverrideDir"]+'override.unreferenced','r');
72 for filename in file.readlines():
73 filename = filename[:-1];
74 excluded[filename] = "";
76 print "Checking against existent files...";
78 os.path.walk(Cnf["Dir::RootDir"]+'dists/', process_dir, None);
81 print "%s wasted..." % (utils.size_type(waste));
83 ################################################################################
88 for component in Cnf.SubTree("Component").List():
89 if component == "mixed":
91 component = string.lower(component);
92 list_filename = '%s%s_%s_source.list' % (Cnf["Dir::ListsDir"], suite, component);
93 list_file = utils.open_file(list_filename, 'r');
94 for line in list_file.readlines():
97 utils.parse_changes(file, 1);
98 except utils.invalid_dsc_format_exc, line:
99 utils.warn("syntax error in .dsc file '%s', line %s." % (file, line));
103 utils.warn("Found %s invalid .dsc files." % (count));
105 ################################################################################
107 def check_override():
108 for suite in [ "stable", "unstable" ]:
110 print "-------------"
112 suite_id = db_access.get_suite_id(suite);
113 q = projectB.query("""
114 SELECT DISTINCT b.package FROM binaries b, bin_associations ba
115 WHERE b.id = ba.bin AND ba.suite = %s AND NOT EXISTS
116 (SELECT * FROM override o WHERE o.suite = %s AND o.package = b.package)"""
117 % (suite_id, suite_id));
119 q = projectB.query("""
120 SELECT DISTINCT s.source FROM source s, src_associations sa
121 WHERE s.id = sa.source AND sa.suite = %s AND NOT EXISTS
122 (SELECT * FROM override o WHERE o.suite = %s and o.package = s.source)"""
123 % (suite_id, suite_id));
126 ################################################################################
128 # Ensure that the source files for any given package is all in one
129 # directory so that 'apt-get source' works...
131 def check_source_in_one_dir():
132 # Not the most enterprising method, but hey...
134 q = projectB.query("SELECT id FROM source;");
135 for i in q.getresult():
137 q2 = projectB.query("""
138 SELECT l.path, f.filename FROM files f, dsc_files df, location l WHERE df.source = %s AND f.id = df.file AND l.id = f.location"""
143 for j in q2.getresult():
144 filename = j[0]+j[1];
145 path = os.path.dirname(filename);
148 first_filename = filename;
149 elif first_path != path:
150 symlink = path + '/' + os.path.basename(first_filename);
151 if not os.path.exists(symlink):
153 print "WOAH, we got a live one here... %s [%s] {%s}" % (filename, source_id, symlink);
155 broken_count = broken_count + 1;
156 print "Found %d source packages where the source is not all in one directory." % (broken_count);
158 ################################################################################
161 print "Getting file information from database...";
162 q = projectB.query("SELECT l.path, f.filename, f.md5sum, f.size FROM files f, location l WHERE f.location = l.id")
165 print "Checking file md5sums & sizes...";
167 filename = os.path.abspath(i[0] + i[1]);
171 file = utils.open_file(filename, 'r');
173 utils.warn("can't open '%s'." % (filename));
175 md5sum = apt_pkg.md5sum(file);
176 size = os.stat(filename)[stat.ST_SIZE];
177 if md5sum != db_md5sum:
178 utils.warn("**WARNING** md5sum mismatch for '%s' ('%s' [current] vs. '%s' [db])." % (filename, md5sum, db_md5sum));
180 utils.warn("**WARNING** size mismatch for '%s' ('%s' [current] vs. '%s' [db])." % (filename, size, db_size));
184 ################################################################################
187 global Cnf, projectB, db_files, waste, excluded;
191 Cnf = apt_pkg.newConfiguration();
192 apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
194 Arguments = [('d',"debug","Tea::Options::Debug", "IntVal"),
195 ('h',"help","Tea::Options::Help"),
196 ('v',"version","Tea::Options::Version")];
198 apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
199 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
200 db_access.init(Cnf, projectB);
203 check_source_in_one_dir();
208 #######################################################################################
210 if __name__ == '__main__':