#!/usr/bin/python from debian_bundle import deb822 from gzip import GzipFile from fnmatch import fnmatch import sys import patchtracker.Conf as Conf if __name__ == '__main__': try: (prog,src,dst) = sys.argv except ValueError: print "usage: program " sys.exit(1) inf = sys.argv[1] fh = None slist = [] if fnmatch(inf, "*.gz"): fh = GzipFile(inf) else: fh = file(inf) # temp workaround for #538376 if Conf.use_apt_pkg is not None: slist = deb822.Sources.iter_paragraphs(fh, use_apt_pkg=Conf.use_apt_pkg) else: slist = deb822.Sources.iter_paragraphs(fh) outf = file(sys.argv[2], "w") print "filtering %s for .diff.gz/.dsc files..."%(inf) for ent in slist: for k in ['Files','Checksums-Sha1','Checksums-Sha256']: newfiles = [] if ent.has_key(k): for f in ent[k]: if fnmatch(f['name'], '*.diff.gz') or fnmatch(f['name'], '*.dsc'): newfiles.append(f) ent[k] = newfiles outf.write(str(ent)) outf.write("\n")