diff options
Diffstat (limited to 'patchtracker/Patch.py')
-rw-r--r-- | patchtracker/Patch.py | 65 |
1 files changed, 42 insertions, 23 deletions
diff --git a/patchtracker/Patch.py b/patchtracker/Patch.py index 670f389..e19ad8c 100644 --- a/patchtracker/Patch.py +++ b/patchtracker/Patch.py @@ -2,6 +2,7 @@ import sys import os import errno from glob import glob +import tarfile class Diffstat: def __init__(self, patch): @@ -38,9 +39,35 @@ class Patch: def diffstat(self): return Diffstat(self) -# XXX this entire __init__ stuff is way to ugly -class PatchSeries (list): +class GenericPatchSeries (list): + def blank(self): + self.names = [] + self.style = "unknown" + self.patches = {} + self.patchargs = {} + + # WTF am i doing this for, again? + def iterpatches(self): + for p in self.names: + yield (p, self.patches[p]) + + def __iter__(self): + return self.iterpatches() + + def __getitem__(self, y): + return self.patches[self.names[y]] + + def __len__(self): + return len(self.names) + + def fetch(self, name): + return self.patches[name] + + def __str__(self): + return "\n".join(self.names) +# XXX this entire __init__ stuff is way to ugly +class PatchSeries (GenericPatchSeries): def __init__(self, dir): fd = None self.blank() @@ -110,27 +137,19 @@ class PatchSeries (list): 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: - yield (p, self.patches[p]) - - def __getitem__(self, y): - return self.patches[self.names[y]] - - def __len__(self): - return len(self.names) - - def fetch(self, name): - return self.patches[name] - - def __str__(self): - return "\n".join(self.names) +class Quilt30PatchSeries (GenericPatchSeries): + def __init__(self, tarBall): + self.blank() + self.style = "quilt (3.0)" + self.tarfh = tarfile.open(tarBall, 'r:*') + try: + series_fh = self.tarfh.extractfile("debian/patches/debian.series") + except KeyError: + series_fh = self.tarfh.extractfile("debian/patches/series") + self.names = ["debian/patches/"+fn.strip() for fn in series_fh.readlines()] + # XXX to lazy eval this might be better + for name in self.names: + self.patches[name] = Patch(self.tarfh.extractfile(name)) if __name__ == "__main__": print "Patch.py testing" |