]> git.decadent.org.uk Git - dak.git/blob - contrib/fix.6
Initial revision
[dak.git] / contrib / fix.6
1 #!/usr/bin/env python
2
3 import pg, string, os, shutil
4 import utils
5 import apt_pkg
6
7 def move(src, dest):
8     if os.path.exists(dest):
9         print 'overwrite `'+dest+'\'? ',
10         yn = utils.our_raw_input()
11         if yn != 'Y' and yn != 'y':
12             return
13     print src + ' -> ' + dest
14     shutil.copyfile (src, dest)
15     os.unlink (src)
16
17 def main():
18     projectB = pg.connect('projectb', 'localhost')
19
20     apt_pkg.init();
21     
22     suite = "unstable";
23     architecture = "i386";
24
25 # too slow to run every time
26 # "select b.package from binaries b, architecture a where a.arch_string = 'all' and b.architecture = a.id INTERSECT select b.package from binaries b, architecture a where a.arch_string = 'i386' and b.architecture = a.id;"
27
28     borked = utils.open_file('broken', 'r')
29     for line in borked.readlines():
30         package = string.strip(line[:-1])
31
32         #print "========="
33         #print package
34         q = projectB.query("SELECT b.version, a.arch_string, l.path, b.filename FROM bin_associations ba, binaries b, architecture a, suite s, location l WHERE b.package = '%s' AND (a.arch_string = '%s' OR a.arch_string = 'all') AND s.suite_name = '%s' AND ba.bin = b.id AND ba.suite = s.id AND b.architecture = a.id AND l.id = b .location" % (package, architecture, suite))
35         entries = q.getresult()
36         version = {}
37         filename = ""
38         for entry in entries:
39             version[entry[1]] = entry[0]
40             if entry[1] == "all":
41                 filename = entry[2] + entry[3]
42         if not version.has_key(architecture) or not version.has_key("all"):
43             #print "SKIPPING"
44             continue
45         if apt_pkg.VersionCompare(version[architecture], version["all"]) != 1:
46             #print architecture+" too new... SKIPPING"
47             continue
48         #print "  "+repr(version)
49         if os.path.exists(filename):
50             if os.path.islink(filename):
51                 print "FIXING: unlinking %s" % (filename);
52                 os.unlink(filename);
53             else:
54                 print "FIXING: moving %s to /home/troup/removed-from-ftp/foad/" % (filename);
55                 move(filename, "/home/troup/removed-from-ftp/foad/%s" % (os.path.basename(filename)));
56
57 if __name__ == '__main__':
58     main()
59