Added UTF-8 support to the reprepro filter.
[users/seanius/patch-tracker.git] / reprepro / conf / diffsonly.py
1 #!/usr/bin/python
2
3 from debian_bundle import deb822
4 from gzip import GzipFile
5 from fnmatch import fnmatch
6 import sys
7 import codecs
8
9 import patchtracker.Conf as Conf
10
11 if __name__ == '__main__':
12   try:
13     (prog,src,dst) = sys.argv
14   except ValueError:
15     print "usage: program <src> <dst>"
16     sys.exit(1)
17
18   inf = sys.argv[1]
19   fh = None
20   slist = []
21   if fnmatch(inf, "*.gz") or Conf.archive_lists_compressed:
22     fh = GzipFile(inf)
23   else:
24     fh = file(inf)
25
26   # temp workaround for #538376
27   if Conf.use_apt_pkg is not None:
28     slist = deb822.Sources.iter_paragraphs(fh, use_apt_pkg=Conf.use_apt_pkg)
29   else:
30     slist = deb822.Sources.iter_paragraphs(fh)
31
32   outf = codecs.open(sys.argv[2], mode="w", encoding='utf-8')
33   print "filtering %s for .diff.gz/.dsc files..."%(inf)
34   for ent in slist:
35     for k in ['Files','Checksums-Sha1','Checksums-Sha256']:
36       newfiles = []
37       if ent.has_key(k):
38         for f in ent[k]:
39           for wanted_glob in ['*.diff.gz', '*.dsc', '*.debian.tar.*']:
40             if fnmatch(f['name'], wanted_glob):
41               newfiles.append(f)
42         ent[k] = newfiles
43     outf.write(unicode(ent))
44     outf.write("\n")