[Frugalware-darcs] darcs-hooks: removed duplicated code, initial plugin system

VMiklos vmiklos at frugalware.org
Thu Jun 7 19:44:11 CEST 2007


Darcsweb-Url: http://darcs.frugalware.org/darcsweb/darcsweb.cgi?r=darcs-hooks;a=darcs_commitdiff;h=20070607165908-e2957-ceb51154452ab255be4424f74750ec0675f13445.gz;

[removed duplicated code, initial plugin system
VMiklos <vmiklos at frugalware.org>**20070607165908] {
move ./cia ./cia.py
adddir ./cia
move ./cia.py ./cia/cia.py
move ./email ./email.py
adddir ./email
move ./email ./sendmail
move ./email.py ./sendmail/sendmail.py
addfile ./darcs-hooks.py
hunk ./cia/cia.py 4
-from xml.dom import minidom
hunk ./cia/cia.py 6
-class Hook:
-	def __init__(self, dir, latestfile, callback):
-		self.dir = dir
-		self.latestfile = latestfile
-		self.callback = callback
-
-		try:
-			os.stat(dir)
-		except OSError:
-			os.makedirs(dir)
-
-		try:
-			sock = open(os.path.join(self.dir, self.latestfile), "r")
-		except IOError:
-			sock = None
-
-		if not sock:
-			xmldoc = self.getxml("darcs chan --last 1 --xml-output")
-
-			hash = xmldoc.getElementsByTagName('patch')[0].attributes['hash'].firstChild.toxml()
-			self.puthash(hash)
-		else:
-			oldhash = sock.read().strip()
-			sock.close()
-
-			xmldoc = self.getxml('darcs chan --from-match "hash %s" --xml-output' % oldhash)
-
-			counter = 0
-			for i in xmldoc.getElementsByTagName('patch'):
-				if counter >= len(xmldoc.getElementsByTagName('patch'))-1:
-					break
-				self.callback(i)
-				counter += 1
-
-			hash = xmldoc.getElementsByTagName('patch')[0].attributes['hash'].firstChild.toxml()
-			self.puthash(hash)
-
-	def getxml(self, cmd):
-		sock = os.popen(cmd)
-		xmldata = "".join(sock.readlines())
-		sock.close()
-		xmldoc = minidom.parseString(xmldata)
-		return xmldoc
-
-	def puthash(self, hash):
-		sock = open(os.path.join(self.dir, self.latestfile), "w")
-		sock.write("%s\n" % hash)
-		sock.close()
-
hunk ./cia/cia.py 26
-def sendpatch(patch):
+def callback(patch):
hunk ./darcs-hooks.py 1
+#!/usr/bin/env python
+
+import os, gzip, time, re, xmlrpclib
+from xml.dom import minidom
+from xml.sax import saxutils
+
+class Hook:
+	def __init__(self, dir, latestfile, callback):
+		self.dir = dir
+		self.latestfile = latestfile
+		self.callback = callback
+
+		try:
+			os.stat(dir)
+		except OSError:
+			os.makedirs(dir)
+
+		try:
+			sock = open(os.path.join(self.dir, self.latestfile), "r")
+		except IOError:
+			sock = None
+
+		if not sock:
+			xmldoc = self.getxml("darcs chan --last 1 --xml-output")
+
+			hash = xmldoc.getElementsByTagName('patch')[0].attributes['hash'].firstChild.toxml()
+			self.puthash(hash)
+		else:
+			oldhash = sock.read().strip()
+			sock.close()
+
+			xmldoc = self.getxml('darcs chan --from-match "hash %s" --xml-output' % oldhash)
+
+			counter = 0
+			for i in xmldoc.getElementsByTagName('patch'):
+				if counter >= len(xmldoc.getElementsByTagName('patch'))-1:
+					break
+				self.callback(i)
+				counter += 1
+
+			hash = xmldoc.getElementsByTagName('patch')[0].attributes['hash'].firstChild.toxml()
+			self.puthash(hash)
+
+	def getxml(self, cmd):
+		sock = os.popen(cmd)
+		xmldata = "".join(sock.readlines())
+		sock.close()
+		xmldoc = minidom.parseString(xmldata)
+		return xmldoc
+
+	def puthash(self, hash):
+		sock = open(os.path.join(self.dir, self.latestfile), "w")
+		sock.write("%s\n" % hash)
+		sock.close()
+
+if __name__ == "__main__":
+	from sendmail.sendmail import config
+	from sendmail.sendmail import callback
+	hook = Hook(config.dir, config.latestfile, callback)
hunk ./sendmail/sendmail.py 7
-class Hook:
-	def __init__(self, dir, latestfile, callback):
-		self.dir = dir
-		self.latestfile = latestfile
-		self.callback = callback
-
-		try:
-			os.stat(dir)
-		except OSError:
-			os.makedirs(dir)
-
-		try:
-			sock = open(os.path.join(self.dir, self.latestfile), "r")
-		except IOError:
-			sock = None
-
-		if not sock:
-			xmldoc = self.getxml("darcs chan --last 1 --xml-output")
-
-			hash = xmldoc.getElementsByTagName('patch')[0].attributes['hash'].firstChild.toxml()
-			self.puthash(hash)
-		else:
-			oldhash = sock.read().strip()
-			sock.close()
-
-			xmldoc = self.getxml('darcs chan --from-match "hash %s" --xml-output' % oldhash)
-
-			counter = 0
-			for i in xmldoc.getElementsByTagName('patch'):
-				if counter >= len(xmldoc.getElementsByTagName('patch'))-1:
-					break
-				self.callback(i)
-				counter += 1
-
-			hash = xmldoc.getElementsByTagName('patch')[0].attributes['hash'].firstChild.toxml()
-			self.puthash(hash)
-
-	def getxml(self, cmd):
-		sock = os.popen(cmd)
-		xmldata = "".join(sock.readlines())
-		sock.close()
-		xmldoc = minidom.parseString(xmldata)
-		return xmldoc
-
-	def puthash(self, hash):
-		sock = open(os.path.join(self.dir, self.latestfile), "w")
-		sock.write("%s\n" % hash)
-		sock.close()
-
hunk ./sendmail/sendmail.py 23
-def sendpatch(patch):
+def callback(patch):
}


More information about the Frugalware-darcs mailing list