]> git.donarmstrong.com Git - wannabuild.git/blob - triggers/filter-nonfree
add non-free files to quinn-diff (and to wanna-build)
[wannabuild.git] / triggers / filter-nonfree
1 #! /usr/bin/python
2
3
4 import sys, os.path
5 #from debian_bundle import deb822
6 import apt_pkg
7
8
9 def check_source(ok, f, fw):
10     ret=[]
11     pkg = apt_pkg.ParseTagFile(f)
12     while pkg.Step():
13         if pkg.Section['Section'].startswith('non-free'):
14             if pkg.Section.get('Autobuild') != 'yes': continue
15             if pkg.Section['Package'] not in ok: continue
16         ret += [pkg.Section['Package']]
17         fw.write(str(pkg.Section))
18         fw.write("\n")
19     return ret
20     f.close()
21     fw.close()
22
23 def check_binary(ok, f, fw):
24     pkg = apt_pkg.ParseTagFile(f)
25     while pkg.Step():
26         if pkg.Section.get('Source', pkg.Section.get('Package')).split(" ")[0] not in ok: continue
27         fw.write(str(pkg.Section))
28         fw.write("\n")
29     f.close()
30     fw.close()
31
32 def outfile(name, file):
33     #return open(dir + "/" + os.path.basename(file), "w")
34     #return open(file + name, "w")
35     if file.endswith(name): return open(file[:-len(name)], "w")
36
37 def main():
38     if len(sys.argv) <= 4:
39         print "Error - too few args"
40         return
41
42     name = sys.argv[1]
43     oklist = [ x[:-1].split(' ')[0] for x in open(sys.argv[2]) ]
44     okpkgs = check_source(oklist, open(sys.argv[3]), outfile(name, sys.argv[3]))
45     for file in sys.argv[4:]:
46         check_binary(okpkgs, open(file), outfile(name, file))
47
48 if __name__ == '__main__':
49         main()