3 # 'Fix' stable to make debian-cd and dpkg -BORGiE users happy
4 # Copyright (C) 2000 James Troup <james@nocrew.org>
5 # $Id: claire.py,v 1.3 2001-01-25 07:27:08 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 # "Look around... leaves are brown... and the sky's a hazy shade of winter,
22 # Look around... leaves are brown... there's a patch of snow on the ground."
23 # -- Simon & Garfunkel / 'A Hazy Shade'
25 ################################################################################
27 import os, pg, re, string, sys
28 import utils, db_access
31 ################################################################################
33 re_strip_section_prefix = re.compile(r'.*/');
38 ################################################################################
40 # Relativize an absolute symlink from 'src' -> 'dest' relative to 'root'.
42 def clean_symlink (src, dest, root):
43 src = string.replace(src, root, '', 1);
44 dest = string.replace(dest, root, '', 1);
45 dest = os.path.dirname(dest);
47 for i in xrange(len(string.split(dest, '/'))):
48 new_src = new_src + '../';
51 ################################################################################
53 def fix_component_section (component, section):
55 (None, component) = utils.extract_component_from_section(section);
57 # FIXME: ugly hacks to work around override brain damage
58 section = re_strip_section_prefix.sub('', section);
59 section = string.replace(string.lower(section), 'non-us', '');
60 if section == "main" or section == "contrib" or section == "non-free":
63 section = section + '/';
65 return (component, section);
67 ################################################################################
69 def find_dislocated_stable(Cnf, projectB):
73 q = projectB.query("""
74 SELECT DISTINCT ON (f.id) c.name, sec.section, l.path, f.filename, f.id
75 FROM component c, override o, section sec, source s, files f, location l,
76 dsc_files df, suite su, src_associations sa, files f2, location l2
77 WHERE su.suite_name = 'stable' AND sa.suite = su.id AND sa.source = s.id
78 AND f2.id = s.file AND f2.location = l2.id AND df.source = s.id
79 AND f.id = df.file AND f.location = l.id AND o.package = s.source
80 AND sec.id = o.section AND NOT (f.filename ~ '^potato/')
81 AND l.component = c.id
82 UNION SELECT DISTINCT ON (f.id) null, sec.section, l.path, f.filename, f.id
83 FROM component c, override o, section sec, source s, files f, location l,
84 dsc_files df, suite su, src_associations sa, files f2, location l2
85 WHERE su.suite_name = 'stable' AND sa.suite = su.id AND sa.source = s.id
86 AND f2.id = s.file AND f2.location = l2.id AND df.source = s.id
87 AND f.id = df.file AND f.location = l.id AND o.package = s.source
88 AND sec.id = o.section AND NOT (f.filename ~ '^potato/')
89 AND NOT EXISTS (SELECT l.path FROM location l WHERE l.component IS NOT NULL AND f.location = l.id);
91 for i in q.getresult():
93 (component, section) = fix_component_section(i[0], i[1]);
94 dest = "%sdists/stable/%s/source/%s%s" % (Cnf["Dir::RootDir"], component, section, os.path.basename(i[3]));
95 src = clean_symlink(src, dest, Cnf["Dir::RootDir"]);
96 if not os.path.exists(dest):
97 if Cnf.Find("Claire::Options::Verbose"):
99 os.symlink(src, dest);
100 dislocated_files[i[4]] = dest;
102 #return dislocated_files;
104 # TODO later when there's something to test it with!
106 q = projectB.query("""
107 SELECT DISTINCT ON (f.id) c.name, a.arch_string, sec.section, b.package,
108 b.version, l.path, f.filename, f.id
109 FROM architecture a, bin_associations ba, binaries b, component c, files f,
110 location l, override o, section sec, suite su
111 WHERE su.suite_name = 'stable' AND ba.suite = su.id AND ba.bin = b.id
112 AND f.id = b.file AND f.location = l.id AND o.package = b.package
113 AND sec.id = o.section AND NOT (f.filename ~ '^potato/')
114 AND b.architecture = a.id AND l.component = c.id
115 UNION SELECT DISTINCT ON (f.id) null, a.arch_string, sec.section, b.package,
116 b.version, l.path, f.filename, f.id
117 FROM architecture a, bin_associations ba, binaries b, component c, files f,
118 location l, override o, section sec, suite su
119 WHERE su.suite_name = 'stable' AND ba.suite = su.id AND ba.bin = b.id
120 AND f.id = b.file AND f.location = l.id AND o.package = b.package
121 AND sec.id = o.section AND NOT (f.filename ~ '^potato/')
122 AND b.architecture = a.id AND NOT EXISTS
123 (SELECT l.path FROM location l WHERE l.component IS NOT NULL AND f.location = l.id);
125 for i in q.getresult():
126 (component, section) = fix_component_section(i[0], i[2]);
129 version = utils.re_no_epoch.sub('', i[4]);
132 dest = "%sdists/stable/%s/binary-%s/%s%s_%s.deb" % (Cnf["Dir::RootDir"], component, architecture, section, package, version);
133 src = clean_symlink(src, dest, Cnf["Dir::RootDir"]);
134 if not os.path.exists(dest):
135 if Cnf.Find("Claire::Options::Verbose"):
136 print src+' -> '+dest
137 os.symlink(src, dest);
138 dislocated_files[i[7]] = dest;
140 return dislocated_files
142 ################################################################################
145 global Cnf, projectB;
149 Cnf = apt_pkg.newConfiguration();
150 apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
152 Arguments = [('d',"debug","Claire::Options::Debug", "IntVal"),
153 ('h',"help","Claire::Options::Help"),
154 ('v',"verbose","Claire::Options::Verbose"),
155 ('V',"version","Claire::Options::Version")];
157 apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
159 projectB = pg.connect('projectb', 'localhost');
161 db_access.init(Cnf, projectB);
163 find_dislocated_stable(Cnf, projectB);
165 #######################################################################################
167 if __name__ == '__main__':