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