3 # 'Fix' stable to make debian-cd and dpkg -BORGiE users happy
4 # Copyright (C) 2000, 2001, 2002 James Troup <james@nocrew.org>
5 # $Id: claire.py,v 1.16 2002-06-05 19:21:18 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 # "Look around... leaves are brown... and the sky's a hazy shade of winter,
24 # Look around... leaves are brown... there's a patch of snow on the ground."
25 # -- Simon & Garfunkel / 'A Hazy Shade'
27 ################################################################################
29 import os, pg, re, string, sys
30 import utils, db_access
33 ################################################################################
35 re_strip_section_prefix = re.compile(r'.*/');
40 ################################################################################
42 def usage (exit_code=0):
43 print """Usage: claire [OPTIONS]
44 Create compatibility symlinks from legacy locations to the pool.
46 -v, --verbose explain what is being done
47 -h, --help show this help and exit"""
51 ################################################################################
53 # Relativize an absolute symlink from 'src' -> 'dest' relative to 'root'.
55 def clean_symlink (src, dest, root):
56 src = string.replace(src, root, '', 1);
57 dest = string.replace(dest, root, '', 1);
58 dest = os.path.dirname(dest);
59 new_src = '../' * len(string.split(dest, '/'));
62 ################################################################################
64 def fix_component_section (component, section):
66 component = utils.extract_component_from_section(section)[1];
68 # FIXME: ugly hacks to work around override brain damage
69 section = re_strip_section_prefix.sub('', section);
70 section = string.replace(string.lower(section), 'non-us', '');
71 if section == "main" or section == "contrib" or section == "non-free":
74 section = section + '/';
76 return (component, section);
78 ################################################################################
80 def find_dislocated_stable(Cnf, projectB):
84 q = projectB.query("""
85 SELECT DISTINCT ON (f.id) c.name, sec.section, l.path, f.filename, f.id
86 FROM component c, override o, section sec, source s, files f, location l,
87 dsc_files df, suite su, src_associations sa, files f2, location l2
88 WHERE su.suite_name = 'stable' AND sa.suite = su.id AND sa.source = s.id
89 AND f2.id = s.file AND f2.location = l2.id AND df.source = s.id
90 AND f.id = df.file AND f.location = l.id AND o.package = s.source
91 AND sec.id = o.section AND NOT (f.filename ~ '^potato/')
92 AND l.component = c.id AND o.suite = su.id
94 # Only needed if you have files in legacy-mixed locations
95 # UNION SELECT DISTINCT ON (f.id) null, sec.section, l.path, f.filename, f.id
96 # FROM component c, override o, section sec, source s, files f, location l,
97 # dsc_files df, suite su, src_associations sa, files f2, location l2
98 # WHERE su.suite_name = 'stable' AND sa.suite = su.id AND sa.source = s.id
99 # AND f2.id = s.file AND f2.location = l2.id AND df.source = s.id
100 # AND f.id = df.file AND f.location = l.id AND o.package = s.source
101 # AND sec.id = o.section AND NOT (f.filename ~ '^potato/') AND o.suite = su.id
102 # AND NOT EXISTS (SELECT l.path FROM location l WHERE l.component IS NOT NULL AND f.location = l.id);
103 for i in q.getresult():
104 (component, section) = fix_component_section(i[0], i[1]);
105 dest = "%sdists/%s/%s/source/%s%s" % (Cnf["Dir::Root"], Cnf.get("Suite::Stable::CodeName", "stable"), component, section, os.path.basename(i[3]));
106 if not os.path.exists(dest):
108 src = clean_symlink(src, dest, Cnf["Dir::Root"]);
109 if Cnf.Find("Claire::Options::Verbose"):
110 print src+' -> '+dest
111 os.symlink(src, dest);
112 dislocated_files[i[4]] = dest;
115 architectures = Cnf.ValueList("Suite::Stable::Architectures");
116 for arch in [ "source", "all" ]:
117 if architectures.count(arch):
118 architectures.remove(arch);
119 q = projectB.query("""
120 SELECT DISTINCT ON (f.id) c.name, a.arch_string, sec.section, b.package,
121 b.version, l.path, f.filename, f.id
122 FROM architecture a, bin_associations ba, binaries b, component c, files f,
123 location l, override o, section sec, suite su
124 WHERE su.suite_name = 'stable' AND ba.suite = su.id AND ba.bin = b.id
125 AND f.id = b.file AND f.location = l.id AND o.package = b.package
126 AND sec.id = o.section AND NOT (f.filename ~ '^potato/')
127 AND b.architecture = a.id AND l.component = c.id AND o.suite = su.id
128 UNION SELECT DISTINCT ON (f.id) null, a.arch_string, sec.section, b.package,
129 b.version, l.path, f.filename, f.id
130 FROM architecture a, bin_associations ba, binaries b, component c, files f,
131 location l, override o, section sec, suite su
132 WHERE su.suite_name = 'stable' AND ba.suite = su.id AND ba.bin = b.id
133 AND f.id = b.file AND f.location = l.id AND o.package = b.package
134 AND sec.id = o.section AND NOT (f.filename ~ '^potato/')
135 AND b.architecture = a.id AND o.suite = su.id AND NOT EXISTS
136 (SELECT l.path FROM location l WHERE l.component IS NOT NULL AND f.location = l.id);
138 for i in q.getresult():
139 (component, section) = fix_component_section(i[0], i[2]);
142 version = utils.re_no_epoch.sub('', i[4]);
145 dest = "%sdists/%s/%s/binary-%s/%s%s_%s.deb" % (Cnf["Dir::Root"], Cnf.get("Suite::Stable::CodeName", "stable"), component, architecture, section, package, version);
146 src = clean_symlink(src, dest, Cnf["Dir::Root"]);
147 if not os.path.exists(dest):
148 if Cnf.Find("Claire::Options::Verbose"):
149 print src+' -> '+dest;
150 os.symlink(src, dest);
151 dislocated_files[i[7]] = dest;
152 # Add per-arch symlinks for arch: all debs
153 if architecture == "all":
154 for arch in architectures:
155 dest = "%sdists/%s/%s/binary-%s/%s%s_%s.deb" % (Cnf["Dir::Root"], Cnf.get("Suite::Stable::CodeName", "stable"), component, arch, section, package, version);
156 if not os.path.exists(dest):
157 if Cnf.Find("Claire::Options::Verbose"):
158 print src+' -> '+dest
159 os.symlink(src, dest);
161 return dislocated_files
163 ################################################################################
166 global Cnf, projectB;
168 Cnf = utils.get_conf()
170 Arguments = [('h',"help","Claire::Options::Help"),
171 ('v',"verbose","Claire::Options::Verbose")];
172 for i in ["help", "verbose" ]:
173 if not Cnf.has_key("Claire::Options::%s" % (i)):
174 Cnf["Claire::Options::%s" % (i)] = "";
176 apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
177 Options = Cnf.SubTree("Claire::Options")
182 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
184 db_access.init(Cnf, projectB);
186 find_dislocated_stable(Cnf, projectB);
188 #######################################################################################
190 if __name__ == '__main__':