3 # 'Fix' stable to make debian-cd and dpkg -BORGiE users happy
4 # Copyright (C) 2000, 2001, 2002, 2003 James Troup <james@nocrew.org>
5 # $Id: claire.py,v 1.19 2003-09-07 13:52:11 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 ################################################################################
26 # | |\ | |_) | This has been obsoleted since the release of woody.
30 ################################################################################
32 import os, pg, re, sys;
33 import utils, db_access;
36 ################################################################################
38 re_strip_section_prefix = re.compile(r'.*/');
43 ################################################################################
45 def usage (exit_code=0):
46 print """Usage: claire [OPTIONS]
47 Create compatibility symlinks from legacy locations to the pool.
49 -v, --verbose explain what is being done
50 -h, --help show this help and exit"""
54 ################################################################################
56 def fix_component_section (component, section):
58 component = utils.extract_component_from_section(section)[1];
60 # FIXME: ugly hacks to work around override brain damage
61 section = re_strip_section_prefix.sub('', section);
62 section = section.lower().replace('non-us', '');
63 if section == "main" or section == "contrib" or section == "non-free":
68 return (component, section);
70 ################################################################################
72 def find_dislocated_stable(Cnf, projectB):
75 codename = Cnf["Suite::Stable::Codename"];
78 q = projectB.query("""
79 SELECT DISTINCT ON (f.id) c.name, sec.section, l.path, f.filename, f.id
80 FROM component c, override o, section sec, source s, files f, location l,
81 dsc_files df, suite su, src_associations sa, files f2, location l2
82 WHERE su.suite_name = 'stable' AND sa.suite = su.id AND sa.source = s.id
83 AND f2.id = s.file AND f2.location = l2.id AND df.source = s.id
84 AND f.id = df.file AND f.location = l.id AND o.package = s.source
85 AND sec.id = o.section AND NOT (f.filename ~ '^%s/')
86 AND l.component = c.id AND o.suite = su.id
88 # Only needed if you have files in legacy-mixed locations
89 # UNION SELECT DISTINCT ON (f.id) null, sec.section, l.path, f.filename, f.id
90 # FROM component c, override o, section sec, source s, files f, location l,
91 # dsc_files df, suite su, src_associations sa, files f2, location l2
92 # WHERE su.suite_name = 'stable' AND sa.suite = su.id AND sa.source = s.id
93 # AND f2.id = s.file AND f2.location = l2.id AND df.source = s.id
94 # AND f.id = df.file AND f.location = l.id AND o.package = s.source
95 # AND sec.id = o.section AND NOT (f.filename ~ '^%s/') AND o.suite = su.id
96 # AND NOT EXISTS (SELECT 1 FROM location l WHERE l.component IS NOT NULL AND f.location = l.id);
97 for i in q.getresult():
98 (component, section) = fix_component_section(i[0], i[1]);
99 if Cnf.FindB("Dinstall::LegacyStableHasNoSections"):
101 dest = "%sdists/%s/%s/source/%s%s" % (Cnf["Dir::Root"], codename, component, section, os.path.basename(i[3]));
102 if not os.path.exists(dest):
104 src = utils.clean_symlink(src, dest, Cnf["Dir::Root"]);
105 if Cnf.Find("Claire::Options::Verbose"):
106 print src+' -> '+dest
107 os.symlink(src, dest);
108 dislocated_files[i[4]] = dest;
111 architectures = filter(utils.real_arch, Cnf.ValueList("Suite::Stable::Architectures"));
112 q = projectB.query("""
113 SELECT DISTINCT ON (f.id) c.name, a.arch_string, sec.section, b.package,
114 b.version, l.path, f.filename, f.id
115 FROM architecture a, bin_associations ba, binaries b, component c, files f,
116 location l, override o, section sec, suite su
117 WHERE su.suite_name = 'stable' AND ba.suite = su.id AND ba.bin = b.id
118 AND f.id = b.file AND f.location = l.id AND o.package = b.package
119 AND sec.id = o.section AND NOT (f.filename ~ '^%s/')
120 AND b.architecture = a.id AND l.component = c.id AND o.suite = su.id""" %
122 # Only needed if you have files in legacy-mixed locations
123 # UNION SELECT DISTINCT ON (f.id) null, a.arch_string, sec.section, b.package,
124 # b.version, l.path, f.filename, f.id
125 # FROM architecture a, bin_associations ba, binaries b, component c, files f,
126 # location l, override o, section sec, suite su
127 # WHERE su.suite_name = 'stable' AND ba.suite = su.id AND ba.bin = b.id
128 # AND f.id = b.file AND f.location = l.id AND o.package = b.package
129 # AND sec.id = o.section AND NOT (f.filename ~ '^%s/')
130 # AND b.architecture = a.id AND o.suite = su.id AND NOT EXISTS
131 # (SELECT 1 FROM location l WHERE l.component IS NOT NULL AND f.location = l.id);
132 for i in q.getresult():
133 (component, section) = fix_component_section(i[0], i[2]);
134 if Cnf.FindB("Dinstall::LegacyStableHasNoSections"):
138 version = utils.re_no_epoch.sub('', i[4]);
141 dest = "%sdists/%s/%s/binary-%s/%s%s_%s.deb" % (Cnf["Dir::Root"], codename, component, architecture, section, package, version);
142 src = utils.clean_symlink(src, dest, Cnf["Dir::Root"]);
143 if not os.path.exists(dest):
144 if Cnf.Find("Claire::Options::Verbose"):
145 print src+' -> '+dest;
146 os.symlink(src, dest);
147 dislocated_files[i[7]] = dest;
148 # Add per-arch symlinks for arch: all debs
149 if architecture == "all":
150 for arch in architectures:
151 dest = "%sdists/%s/%s/binary-%s/%s%s_%s.deb" % (Cnf["Dir::Root"], codename, component, arch, section, package, version);
152 if not os.path.exists(dest):
153 if Cnf.Find("Claire::Options::Verbose"):
154 print src+' -> '+dest
155 os.symlink(src, dest);
157 return dislocated_files
159 ################################################################################
162 global Cnf, projectB;
164 Cnf = utils.get_conf()
166 Arguments = [('h',"help","Claire::Options::Help"),
167 ('v',"verbose","Claire::Options::Verbose")];
168 for i in ["help", "verbose" ]:
169 if not Cnf.has_key("Claire::Options::%s" % (i)):
170 Cnf["Claire::Options::%s" % (i)] = "";
172 apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
173 Options = Cnf.SubTree("Claire::Options")
178 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
180 db_access.init(Cnf, projectB);
182 find_dislocated_stable(Cnf, projectB);
184 #######################################################################################
186 if __name__ == '__main__':