3 # 'Fix' stable to make debian-cd and dpkg -BORGiE users happy
4 # Copyright (C) 2000, 2001, 2002, 2003, 2006 James Troup <james@nocrew.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ################################################################################
25 # | |\ | |_) | This has been obsoleted since the release of woody.
29 ################################################################################
31 import os, pg, re, sys
33 import daklib.database
36 ################################################################################
38 re_strip_section_prefix = re.compile(r'.*/')
43 ################################################################################
45 def usage (exit_code=0):
46 print """Usage: dak symlink-dists [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 = daklib.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 if section == "main" or section == "contrib" or section == "non-free":
67 return (component, section)
69 ################################################################################
71 def find_dislocated_stable(Conf, DBConn):
74 codename = Conf["Suite::Stable::Codename"]
78 SELECT DISTINCT ON (f.id) c.name, sec.section, l.path, f.filename, f.id
79 FROM component c, override o, section sec, source s, files f, location l,
80 dsc_files df, suite su, src_associations sa, files f2, location l2
81 WHERE su.suite_name = 'stable' AND sa.suite = su.id AND sa.source = s.id
82 AND f2.id = s.file AND f2.location = l2.id AND df.source = s.id
83 AND f.id = df.file AND f.location = l.id AND o.package = s.source
84 AND sec.id = o.section AND NOT (f.filename ~ '^%s/')
85 AND l.component = c.id AND o.suite = su.id
87 # Only needed if you have files in legacy-mixed locations
88 # UNION SELECT DISTINCT ON (f.id) null, sec.section, l.path, f.filename, f.id
89 # FROM component c, override o, section sec, source s, files f, location l,
90 # dsc_files df, suite su, src_associations sa, files f2, location l2
91 # WHERE su.suite_name = 'stable' AND sa.suite = su.id AND sa.source = s.id
92 # AND f2.id = s.file AND f2.location = l2.id AND df.source = s.id
93 # AND f.id = df.file AND f.location = l.id AND o.package = s.source
94 # AND sec.id = o.section AND NOT (f.filename ~ '^%s/') AND o.suite = su.id
95 # AND NOT EXISTS (SELECT 1 FROM location l WHERE l.component IS NOT NULL AND f.location = l.id)
96 for i in q.getresult():
97 (component, section) = fix_component_section(i[0], i[1])
98 if Conf.FindB("Dinstall::LegacyStableHasNoSections"):
100 dest = "%sdists/%s/%s/source/%s%s" % (Conf["Dir::Root"], codename, component, section, os.path.basename(i[3]))
101 if not os.path.exists(dest):
103 src = daklib.utils.clean_symlink(src, dest, Conf["Dir::Root"])
104 if Conf.Find("Symlink-Dists::Options::Verbose"):
105 print src+' -> '+dest
106 os.symlink(src, dest)
107 dislocated_files[i[4]] = dest
110 architectures = filter(daklib.utils.real_arch, Conf.ValueList("Suite::Stable::Architectures"))
112 SELECT DISTINCT ON (f.id) c.name, a.arch_string, sec.section, b.package,
113 b.version, l.path, f.filename, f.id
114 FROM architecture a, bin_associations ba, binaries b, component c, files f,
115 location l, override o, section sec, suite su
116 WHERE su.suite_name = 'stable' AND ba.suite = su.id AND ba.bin = b.id
117 AND f.id = b.file AND f.location = l.id AND o.package = b.package
118 AND sec.id = o.section AND NOT (f.filename ~ '^%s/')
119 AND b.architecture = a.id AND l.component = c.id AND o.suite = su.id""" %
121 # Only needed if you have files in legacy-mixed locations
122 # UNION SELECT DISTINCT ON (f.id) null, a.arch_string, sec.section, b.package,
123 # b.version, l.path, f.filename, f.id
124 # FROM architecture a, bin_associations ba, binaries b, component c, files f,
125 # location l, override o, section sec, suite su
126 # WHERE su.suite_name = 'stable' AND ba.suite = su.id AND ba.bin = b.id
127 # AND f.id = b.file AND f.location = l.id AND o.package = b.package
128 # AND sec.id = o.section AND NOT (f.filename ~ '^%s/')
129 # AND b.architecture = a.id AND o.suite = su.id AND NOT EXISTS
130 # (SELECT 1 FROM location l WHERE l.component IS NOT NULL AND f.location = l.id)
131 for i in q.getresult():
132 (component, section) = fix_component_section(i[0], i[2])
133 if Conf.FindB("Dinstall::LegacyStableHasNoSections"):
137 version = daklib.utils.re_no_epoch.sub('', i[4])
140 dest = "%sdists/%s/%s/binary-%s/%s%s_%s.deb" % (Conf["Dir::Root"], codename, component, architecture, section, package, version)
141 src = daklib.utils.clean_symlink(src, dest, Conf["Dir::Root"])
142 if not os.path.exists(dest):
143 if Conf.Find("Symlink-Dists::Options::Verbose"):
144 print src+' -> '+dest
145 os.symlink(src, dest)
146 dislocated_files[i[7]] = dest
147 # Add per-arch symlinks for arch: all debs
148 if architecture == "all":
149 for arch in architectures:
150 dest = "%sdists/%s/%s/binary-%s/%s%s_%s.deb" % (Conf["Dir::Root"], codename, component, arch, section, package, version)
151 if not os.path.exists(dest):
152 if Conf.Find("Symlink-Dists::Options::Verbose"):
153 print src+' -> '+dest
154 os.symlink(src, dest)
156 return dislocated_files
158 ################################################################################
163 Cnf = daklib.utils.get_conf()
165 Arguments = [('h',"help","Symlink-Dists::Options::Help"),
166 ('v',"verbose","Symlink-Dists::Options::Verbose")]
167 for i in ["help", "verbose" ]:
168 if not Cnf.has_key("Symlink-Dists::Options::%s" % (i)):
169 Cnf["Symlink-Dists::Options::%s" % (i)] = ""
171 apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
172 Options = Cnf.SubTree("Symlink-Dists::Options")
177 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
179 daklib.database.init(Cnf, projectB)
181 find_dislocated_stable(Cnf, projectB)
183 #######################################################################################
185 if __name__ == '__main__':