summaryrefslogtreecommitdiff
path: root/patchtracker
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
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')
-rw-r--r--patchtracker/DiffGzHandler.py67
-rw-r--r--patchtracker/Patch.py66
2 files changed, 133 insertions, 0 deletions
diff --git a/patchtracker/DiffGzHandler.py b/patchtracker/DiffGzHandler.py
new file mode 100644
index 0000000..21509e7
--- /dev/null
+++ b/patchtracker/DiffGzHandler.py
@@ -0,0 +1,67 @@
+import tempfile
+import sys
+import os
+from Patch import Patch, PatchSeries
+
+class DiffGzHandler:
+ diff = None
+ def __init__(self,fname):
+ self.diff = fname
+
+ def filterdiff(self, include=None, exclude=None):
+ cmd = ["filterdiff","-z","-p","1"]
+ if include:
+ cmd += [ "-i", include]
+ elif exclude:
+ cmd += [ "-x", exclude]
+ else:
+ raise Exception("DiffGzHandler.filterdiff called w/o include/exclude")
+ i,o,e=os.popen3(cmd+[self.diff])
+ i.close()
+ p = Patch(o)
+ err = e.read()
+ if len(err):
+ raise Exception("filterdiff gave errors:",err)
+ return p
+
+ def debiandir(self):
+ return self.filterdiff(include='debian/*')
+
+ def nondebiandir(self):
+ return self.filterdiff(exclude='debian/*')
+
+ def series(self):
+ patches = None
+ embedded = self.filterdiff(include='debian/patches*')
+
+ if embedded.lines():
+ td = tempfile.mkdtemp()
+ i,o,e=os.popen3("patch -d %s -p3"%(td))
+ i.write(str(embedded))
+ i.close()
+ err = e.read()
+ if len(err):
+ raise Exception("unable to extract series patches:\n"+err)
+ patches = PatchSeries(td)
+ os.system("rm -rf %s"%(td))
+
+ return patches
+
+if __name__ == "__main__":
+ print "DiffGzHandler testing"
+ try:
+ dh = DiffGzHandler(sys.argv[1])
+ except IndexError:
+ print "usage: %s <diffgz>"%(sys.argv[0])
+ sys.exit(1)
+
+ print "debian dir:"
+ print dh.debiandir()
+ print "nondebian dir:"
+ print dh.nondebiandir()
+ print "series:"
+ s = dh.series()
+ print s
+ if len(s):
+ print "1st patch in series:"
+ print s[0]
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>"