]> git.donarmstrong.com Git - wannabuild.git/blob - bin/filter-nonfree
Auto-committed schema changes.
[wannabuild.git] / bin / filter-nonfree
1 #! /usr/bin/python
2
3
4 import sys, os.path, gzip, subprocess
5 #from debian_bundle import deb822
6 import apt_pkg
7
8
9 def check_source(ok, srcs, fw):
10     ret=[]
11     for f in srcs:
12         #f = open(f, 'r')
13         f = subprocess.Popen("zcat %s" % (f), shell=True, stdout=subprocess.PIPE).stdout
14         pkg = apt_pkg.ParseTagFile(f)
15         while pkg.Step():
16             if not pkg.Section.get('Package'): continue
17             if pkg.Section.get('Section','').startswith('non-free'):
18                 if pkg.Section.get('Autobuild') != 'yes': continue
19                 if pkg.Section['Package'] not in ok: continue
20             ret += [pkg.Section['Package']]
21             fw.write(str(pkg.Section))
22             fw.write("\n")
23         f.close()
24     fw.close()
25     return ret
26
27 def check_binary(ok, bins, fw):
28     for f in bins:
29         f = subprocess.Popen("zcat %s" % (f), shell=True, stdout=subprocess.PIPE).stdout
30         pkg = apt_pkg.ParseTagFile(f)
31         while pkg.Step():
32             if pkg.Section.get('Source', pkg.Section.get('Package')).split(" ")[0] not in ok: continue
33             fw.write(str(pkg.Section))
34             fw.write("\n")
35         f.close()
36     fw.close()
37
38 def outfile(name, file):
39     #return open(dir + "/" + os.path.basename(file), "w")
40     #return open(file + name, "w")
41     if file.endswith(name): return open(file[:-len(name)], "w")
42
43 def replarch(arch, pkgs):
44     return [ x.replace('%ARCH%', arch) for x in pkgs ]
45
46 def main():
47     # call me:
48     # /org/wanna-build/etc/non-free-include-list "arch1 arch2" write-sources write-packages Sources* . Packages*
49     if len(sys.argv) <= 4:
50         print "Error - too few args"
51         return
52
53     oklist = [ x[:-1].split(' ')[0] for x in open(sys.argv[1]) ]
54     #outsrcs = open(sys.argv[3], "w")
55     #outpkgs = open(sys
56     rem = sys.argv[5:]
57     if '.' not in rem:
58         print "need both Sources and Packages"
59         return
60     src = rem[:rem.index('.')]
61     bin = rem[rem.index('.')+1:]
62     if not src or not bin:
63         print "need non-empty Sources and Packages"
64         return
65     okpkgs = check_source(oklist, src, open(sys.argv[3], "w"))
66     print okpkgs
67     for arch in sys.argv[2].split(" "):
68         check_binary(okpkgs, replarch(arch, bin), open(replarch(arch, [sys.argv[4]])[0], "w"))
69
70 if __name__ == '__main__':
71         main()