diff options
Diffstat (limited to 'patchtracker')
-rw-r--r-- | patchtracker/DiffGzHandler.py | 11 | ||||
-rw-r--r-- | patchtracker/Patch.py | 79 |
2 files changed, 75 insertions, 15 deletions
diff --git a/patchtracker/DiffGzHandler.py b/patchtracker/DiffGzHandler.py index 21509e7..1f1c1de 100644 --- a/patchtracker/DiffGzHandler.py +++ b/patchtracker/DiffGzHandler.py @@ -34,6 +34,7 @@ class DiffGzHandler: patches = None embedded = self.filterdiff(include='debian/patches*') + # XXX *cough* cache *cough* if embedded.lines(): td = tempfile.mkdtemp() i,o,e=os.popen3("patch -d %s -p3"%(td)) @@ -56,12 +57,12 @@ if __name__ == "__main__": sys.exit(1) print "debian dir:" - print dh.debiandir() + print dh.debiandir().diffstat() print "nondebian dir:" - print dh.nondebiandir() + print dh.nondebiandir().diffstat() print "series:" s = dh.series() print s - if len(s): - print "1st patch in series:" - print s[0] + for name,patch in s.iterpatches(): + print "patch:",name + print patch.diffstat() diff --git a/patchtracker/Patch.py b/patchtracker/Patch.py index 8a1dbd0..64cf9c9 100644 --- a/patchtracker/Patch.py +++ b/patchtracker/Patch.py @@ -4,10 +4,9 @@ import errno from glob import glob class Patch: - p = [] - - def __init__(self, fh): + def __init__(self, fh, level=1): self.p = fh.readlines() + self.lvl = level def __str__(self): return "".join(self.p) @@ -15,34 +14,94 @@ class Patch: def lines(self): return len(self.p) + def diffstat(self): + i,o = os.popen2("diffstat") + i.write(str(self)) + i.close() + return o.read() + + +# XXX this entire __init__ stuff is way to ugly class PatchSeries (list): - style = "simple" - names = [] - patches = {} def __init__(self, dir): fd = None + self.blank() + self.style = "simple" try: fd = file(os.sep.join([dir, "00list"])) self.style = "dpatch" except IOError, e: if e.errno != errno.ENOENT: - raise e + print "ERROR: unable to open dpatch list..." + self.blank() + return try: fd = file(os.sep.join([dir, "series"])) self.style = "quilt" except IOError, e: if e.errno != errno.ENOENT: - raise e + print "ERROR: series file is a directory..." + self.blank() + return if fd: - self.names = [n.rstrip() for n in fd.readlines()] + # remove blank lines + for line in filter(None, [n.strip() for n in fd.readlines()]): + stuff = line.split(' ') + # skip comments + if stuff[0][0] == "#": + continue + # here's the name + name = stuff[0] + print "\t\t\t%s: %s"%(self.style,name) + self.names.append(name) + # anything else are either patch args or comments + self.patchargs[name] = [] + for rest in filter(None, stuff[1:]): + if rest[0][0] == "#": + break + else: + self.patchargs[name].append(rest) + else: self.names = os.listdir(dir) self.names.sort() + for n in self.names: + self.patchargs[n] = [] + + # XXX this code is too ugly + removelater=[] + for p in self.names: + try: + self.patches[p] = Patch(file(os.sep.join([dir, p]))) + except IOError, e: + if e.errno == errno.ENOENT and self.style == "dpatch": + try: + self.patches[p] = Patch(file(os.sep.join([dir, p+".dpatch"]))) + except: + print "ERROR: could not find patch",p + self.blank() + return + elif e.errno == errno.EISDIR: + print "WARNING: directory %s in patch dir, patch list incomplete"%(p) + removelater.append(p) + else: + print "ERROR: could not find patch",p + self.blank() + return + for p in removelater: + self.names.remove(p) + + def blank(self): + self.names = [] + self.style = "unknown" + self.patches = {} + self.patchargs = {} + def iterpatches(self): for p in self.names: - self.patches[p] = Patch(file(os.sep.join([dir, p]))) + yield (p, self.patches[p]) def __getitem__(self, y): return self.patches[self.names[y]] |