]> git.decadent.org.uk Git - dak.git/blob - claire.py
sync
[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.1 2000-12-05 04:27:48 troup 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 pg, sys, os, string
28 import utils, db_access
29 import apt_pkg;
30
31 ################################################################################
32
33 Cnf = None;
34 projectB = None;
35
36 # Relativize an absolute symlink from 'src' -> 'dest' relative to 'root'.
37 # Returns fixed 'src'
38 def clean_symlink (src, dest, root):
39     src = string.replace(src, root, '', 1);
40     dest = string.replace(dest, root, '', 1);
41     dest = os.path.dirname(dest);
42     new_src = '';
43     for i in xrange(len(string.split(dest, '/'))):
44         new_src = new_src + '../';
45     return new_src + src
46
47 ################################################################################
48
49 def find_dislocated_stable(Cnf, projectB):
50     dislocated_files = {}
51
52     # Source
53     q = projectB.query("SELECT su.suite_name, c.name, s.id FROM suite su, src_associations sa, source s, files f, component c, location l WHERE su.suite_name = 'stable' AND sa.suite = su.id AND sa.source = s.id AND f.id = s.file AND f.location = l.id AND (l.component = c.id OR (l.component = NULL AND c.name = 'non-US/main')) AND NOT (f.filename ~ '^potato/');")
54     for i in q.getresult():
55         q = projectB.query("SELECT l.path, f.filename, f.id FROM source s, files f, location l, dsc_files df WHERE s.id = %d AND df.source = %d AND f.id = df.file AND f.location = l.id AND NOT (f.filename ~ '^potato/')" % (i[2], i[2]));
56         for j in q.getresult():
57             src = j[0]+j[1]
58             dest = Cnf["Dir::RootDir"]+'dists/'+i[0]+'/'+i[1]+'/source/'+os.path.basename(j[1]);
59             src = clean_symlink(src, dest, Cnf["Dir::RootDir"]);
60             if not os.path.exists(dest):
61                 if Cnf.Find("Claire::Options::Verbose"):
62                     print src+' -> '+dest
63                 os.symlink(src, dest);
64             dislocated_files[j[2]] = dest;
65
66     # Binary
67     q = projectB.query("SELECT su.suite_name, c.name, a.arch_string, b.package, b.version, l.path, f.filename, f.id FROM suite su, bin_associations ba, binaries b, files f, component c, architecture a, location l WHERE ba.suite = su.id AND su.suite_name = 'stable' AND ba.bin = b.id AND f.id = b.file AND f.location = l.id AND (l.component = c.id OR (l.component = NULL and c.name = 'non-US/main')) AND b.architecture = a.id AND NOT (f.filename ~ '^potato/');");
68     for i in q.getresult():
69         src = i[5]+i[6]
70         dest = Cnf["Dir::RootDir"]+'dists/'+i[0]+'/'+i[1]+'/binary-'+i[2]+'/'+i[3]+'_'+utils.re_no_epoch.sub('', i[4])+'.deb'
71         src = clean_symlink(src, dest, Cnf["Dir::RootDir"]);
72         if not os.path.exists(dest):
73             if Cnf.Find("Claire::Options::Verbose"):
74                 print src+' -> '+dest
75             os.symlink(src, dest);
76         dislocated_files[i[7]] = dest;
77
78     return dislocated_files
79
80 ################################################################################
81
82 def main ():
83     global Cnf, projectB;
84
85     apt_pkg.init();
86     
87     Cnf = apt_pkg.newConfiguration();
88     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
89
90     Arguments = [('d',"debug","Claire::Options::Debug", "IntVal"),
91                  ('h',"help","Claire::Options::Help"),
92                  ('v',"verbose","Claire::Options::Verbose"),
93                  ('V',"version","Claire::Options::Version")];
94
95     apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
96
97     projectB = pg.connect('projectb', 'localhost');
98
99     db_access.init(Cnf, projectB);
100
101     find_dislocated_stable(Cnf, projectB);
102
103 #######################################################################################
104
105 if __name__ == '__main__':
106     main()
107