]> git.decadent.org.uk Git - dak.git/blob - claire.py
make claire use the codename (potato) in the path to files rather thanthe suite name...
[dak.git] / claire.py
1 #!/usr/bin/env python
2
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.4 2001-02-27 06:10:42 ajt Exp $
6
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.
11
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.
16
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
20
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'
24
25 ################################################################################
26
27 import os, pg, re, string, sys
28 import utils, db_access
29 import apt_pkg;
30
31 ################################################################################
32
33 re_strip_section_prefix = re.compile(r'.*/');
34
35 Cnf = None;
36 projectB = None;
37
38 ################################################################################
39
40 # Relativize an absolute symlink from 'src' -> 'dest' relative to 'root'.
41 # Returns fixed 'src'
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);
46     new_src = '';
47     for i in xrange(len(string.split(dest, '/'))):
48         new_src = new_src + '../';
49     return new_src + src
50
51 ################################################################################
52
53 def fix_component_section (component, section):
54     if component == "":
55         (None, component) = utils.extract_component_from_section(section);
56
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":
61         section = '';
62     if section != '':
63         section = section + '/';
64
65     return (component, section);
66
67 ################################################################################
68
69 def find_dislocated_stable(Cnf, projectB):
70     dislocated_files = {}
71
72     # Source
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);
90 """);
91     for i in q.getresult():
92         src = i[2]+i[3]
93         (component, section) = fix_component_section(i[0], i[1]);
94         dest = "%sdists/%s/%s/source/%s%s" % (Cnf["Dir::RootDir"], Cnf.get("Suite::Stable::CodeName", "stable"), 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"):
98                 print src+' -> '+dest
99             os.symlink(src, dest);
100         dislocated_files[i[4]] = dest;
101
102     #return dislocated_files;
103
104     # TODO later when there's something to test it with!
105     # Binary
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);
124 """);
125     for i in q.getresult():
126         (component, section) = fix_component_section(i[0], i[2]);
127         architecture = i[1];
128         package = i[3]
129         version = utils.re_no_epoch.sub('', i[4]);
130         src = i[5]+i[6]
131        
132         dest = "%sdists/%s/%s/binary-%s/%s%s_%s.deb" % (Cnf["Dir::RootDir"], Cnf.get("Suite::Stable::CodeName", "stable"), 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;
139
140     return dislocated_files
141
142 ################################################################################
143
144 def main ():
145     global Cnf, projectB;
146
147     apt_pkg.init();
148     
149     Cnf = apt_pkg.newConfiguration();
150     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
151
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")];
156
157     apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
158
159     projectB = pg.connect('projectb', 'localhost');
160
161     db_access.init(Cnf, projectB);
162
163     find_dislocated_stable(Cnf, projectB);
164
165 #######################################################################################
166
167 if __name__ == '__main__':
168     main()
169