[Dev OpenGP] [76] End of the day

[ Thread Index | Date Index | More opengp.tuxfamily.org/development Archives ]


Revision: 76
Author:   alband85
Date:     2009-03-23 16:47:57 +0100 (Mon, 23 Mar 2009)

Log Message:
-----------
End of the day

Modified Paths:
--------------
    trunk/src/lib/ogp/etree/elementmethods.py
    trunk/src/lib/ogp/etree/ogpxmlconsts.py
    trunk/src/lib/ogp/plugins/plugin.py


Modified: trunk/src/lib/ogp/etree/elementmethods.py
===================================================================
--- trunk/src/lib/ogp/etree/elementmethods.py	2009-03-23 13:53:13 UTC (rev 75)
+++ trunk/src/lib/ogp/etree/elementmethods.py	2009-03-23 15:47:57 UTC (rev 76)
@@ -5,6 +5,11 @@
 from copy import deepcopy
 from ogpxmlconsts import *
 
+def Element(name):
+	OGP_PARSER = XMLParser()
+	OGP_PARSER.set_element_class_lookup(ElementDefaultClassLookup(element=OgpElement))
+	return OGP_PARSER.makeelement(name)
+
 class OgpElement(ElementBase):
 	"""
 		lxml Element class providing redefined secure methods, compliant with the merge algorithm :
@@ -239,6 +244,26 @@
 		else:
 			return str(transform(self), params)
 
+	def __makePlugin(name, fileNames):
+		res = Element(OgpXmlConsts.TAG_PLUGIN)
+		res.set(OgpXmlConsts.ATTR_PLUGIN_NAME, name)
+		res.append(Element(OgpXmlConsts.TAG_CONF))
+		files_e = Element(OgpXmlConsts.TAG_FILES)
+		res.append(files_e)
+		for f in fileNames:
+			f_e = OgpElement.makeFile(f)
+			files_e.append(f_e)
+		return res
+	makePlugin = staticmethod(__makePlugin)
+
+	def __makeFile(name):
+		res = Element(OgpXmlConsts.TAG_FILE)
+		res.set(OgpXmlConsts.ATTR_FILE_NAME, name)
+		res.append(Element(OgpXmlConsts.TAG_CONF))
+		res.append(Element(OgpXmlConsts.TAG_SECURITY))
+		return res
+	makeFile = staticmethod(__makeFile)
+
 class OgpXmlError(Exception):
 	"""
 		OGP XML error class.

Modified: trunk/src/lib/ogp/etree/ogpxmlconsts.py
===================================================================
--- trunk/src/lib/ogp/etree/ogpxmlconsts.py	2009-03-23 13:53:13 UTC (rev 75)
+++ trunk/src/lib/ogp/etree/ogpxmlconsts.py	2009-03-23 15:47:57 UTC (rev 76)
@@ -22,6 +22,7 @@
 	TAG_UID = "uid"
 	TAG_GID = "gid"
 	TAG_SECURITY = "security"
+	TAG_CONF = "conf"
 	TAG_FILE = "file"
 	TAG_FILES = "files"
 	TAG_PLUGIN = "plugin"

Modified: trunk/src/lib/ogp/plugins/plugin.py
===================================================================
--- trunk/src/lib/ogp/plugins/plugin.py	2009-03-23 13:53:13 UTC (rev 75)
+++ trunk/src/lib/ogp/plugins/plugin.py	2009-03-23 15:47:57 UTC (rev 76)
@@ -14,8 +14,8 @@
 		Plugin class and metaclass __setattr__ method
 		Throws an exception when attempting to modify the plugin name.
 	"""
-	if item == "name":
-		raise OgpPluginError('__setattr__: name is readonly.')
+	if item == "name" or item == "files":
+		raise OgpPluginError('__setattr__: ' + item + ' is readonly.')
 	self.__dict__[item] = value
 
 class M_Plugin(type):
@@ -29,23 +29,26 @@
 		Provides plugins' base class and plugin registration mechanism.
 	"""
 	
+	name = None # the plugin name
+	files = []
 	__metaclass__ = M_Plugin
-	__parentDn = None
-	__dn = None
+	parentDn = None
+	dn = None
 	__core = None
+	__registeredPlugins = dict()
 
 	def __init__(self, dn):
 		self.__core = OgpCore.getInstance()
-		self.__dn = dn
-		self.__currentConf = self.__core.pullPluginConf(self.__dn, self.name)
-		self.__parentDn = str2dn(dn)
-		del self.__parentDn[0]
-		self.__parentDn = dn2str(self.__parentDn)
+		self.dn = dn
+		# Dirty but it pleases Michel :-P
+		# Loads RW XML conf from LDAP
+		self.cancel()
+		# Parent DN (to find parent conf)
+		self.parentDn = str2dn(dn)
+		del self.parentDn[0]
+		self.parentDn = dn2str(self.parentDn)
 	
 	__setattr__ = setattr # Plugin name protection
-
-	name = None # the plugin name
-	__registeredPlugins = dict()
 	
 	def __getPluginFromName(name):
 		"""
@@ -78,16 +81,15 @@
 		"""
 			Commit changes to LDAP
 		"""
-		self.__core.pushPluginConf(self.__dn, self.__currentConf)
+		self.__core.pushPluginConf(self.dn, self.currentConf)
 
 	def cancel(self):
 		"""
 			Do not commit and discard changes.
 		"""
-		print "--- CANCEL ---"
-		print self.__currentConf.toString()
-		self.__currentConf = self.__core.pullPluginConf(self.__dn, self.name)
-		print self.__currentConf.toString()
+		self.currentConf = self.__core.pullPluginConf(self.dn, self.name)
+		if self.currentConf is None:
+			self.currentConf = OgpElement.makePlugin(self.name, self.files)
 
 
 	def chown(self, fileName, uid=omitted, gid=omitted, blocking=False):
@@ -95,7 +97,6 @@
 			Changes owner, changes the user and/or group ownership of 
 			the given file
 		"""
-		#print self.__currentConf.toString()
 		file_e = self.__getFile(fileName)
 		sec_e = file_e.xpath(OgpXmlConsts.TAG_SECURITY)[0]
 
@@ -130,12 +131,11 @@
 					sec_e.append(gid_e)
 				gid_e.text = str(gid)
 				gid_e.blocking = blocking
-		#print self.__currentConf.toString()
 
 	def __getFile(self, fileName):
 		arg = '/' + OgpXmlConsts.TAG_PLUGIN + '/' + OgpXmlConsts.TAG_FILES + '/' + OgpXmlConsts.TAG_FILE + '[@' + OgpXmlConsts.ATTR_FILE_NAME + "='" + fileName + "']"
 		try:
-			return self.__currentConf.xpath(arg)[0]
+			return self.currentConf.xpath(arg)[0]
 		except:
 			raise OgpPluginError("__getFile: file '" + fileName + "' does not exist")
 
@@ -144,7 +144,6 @@
 		"""
 			Changes the permissions of the given file according to mode
 		"""
-		print self.__currentConf.toString()
 		file_e = self.__getFile(fileName)
 		sec_e = file_e.xpath(OgpXmlConsts.TAG_SECURITY)[0]
 		for tag in rights:
@@ -165,7 +164,6 @@
 			else:
 				#TODO: log!
 				pass
-		print self.__currentConf.toString()
 
 	# Abstract methods
 	def installConf(self):
@@ -200,12 +198,13 @@
 		"""
 		raise NotImplementedError('This method should be overriden in derived classes.')
 
-	def pushFile(self, file, content):
+	def pushFile(self, file, content, blocking=False):
 		"""
 			Builds XML configuration from a string content and loads it in the corresponding <file> Element
 			Arguments:
-				file   : the logical name of the targeted file
-				content: the content of the file
+				file    : the logical name of the targeted file
+				content : the content of the file
+				blocking: sets the block attribute on the targeted file
 		"""
 		raise NotImplementedError('This method should be overriden in derived classes.')
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/