summaryrefslogtreecommitdiff
path: root/patchtracker/Patch.py
diff options
context:
space:
mode:
authorSean Finney <seanius@debian.org>2008-06-05 21:17:32 +0200
committerSean Finney <seanius@debian.org>2008-06-05 21:17:32 +0200
commitbcbce74ac8e9f689a621c5fd4e50ee61d1a65520 (patch)
treeb810cb9448bbbbd265e62e92d64865e6b0519b92 /patchtracker/Patch.py
parent6ddac31cb2e5848d79f82d4fbf7e91161f98fbff (diff)
downloadpatch-tracker-bcbce74ac8e9f689a621c5fd4e50ee61d1a65520.tar.gz
new classes for diff/diff.gz handling
DiffGzHandler should be an extensible interface to getting whatever info is needed from a diff.gz file. Patch (and PatchSeries from the same module) should be an extensible interface for whatever mangling we need to with patches.
Diffstat (limited to 'patchtracker/Patch.py')
-rw-r--r--patchtracker/Patch.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/patchtracker/Patch.py b/patchtracker/Patch.py
new file mode 100644
index 0000000..8a1dbd0
--- /dev/null
+++ b/patchtracker/Patch.py
@@ -0,0 +1,66 @@
+import sys
+import os
+import errno
+from glob import glob
+
+class Patch:
+ p = []
+
+ def __init__(self, fh):
+ self.p = fh.readlines()
+
+ def __str__(self):
+ return "".join(self.p)
+
+ def lines(self):
+ return len(self.p)
+
+class PatchSeries (list):
+ style = "simple"
+ names = []
+ patches = {}
+
+ def __init__(self, dir):
+ fd = None
+ try:
+ fd = file(os.sep.join([dir, "00list"]))
+ self.style = "dpatch"
+ except IOError, e:
+ if e.errno != errno.ENOENT:
+ raise e
+ try:
+ fd = file(os.sep.join([dir, "series"]))
+ self.style = "quilt"
+ except IOError, e:
+ if e.errno != errno.ENOENT:
+ raise e
+
+ if fd:
+ self.names = [n.rstrip() for n in fd.readlines()]
+ else:
+ self.names = os.listdir(dir)
+ self.names.sort()
+
+ for p in self.names:
+ self.patches[p] = Patch(file(os.sep.join([dir, 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)
+
+if __name__ == "__main__":
+ print "Patch.py testing"
+ try:
+ p = Patch(file(sys.argv[1]))
+ print "patch contents:"
+ print p
+ except IndexError:
+ print "usage: %s <patch>"