[Dev OpenGP] [72] Began daemon implementation.

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


Revision: 72
Author:   nicolaf
Date:     2009-03-21 16:18:18 +0100 (Sat, 21 Mar 2009)

Log Message:
-----------
Began daemon implementation.

Modified Paths:
--------------
    trunk/src/lib/ogp/core/ogpcore.py
    trunk/src/lib/ogp/etree/elementmethods.py
    trunk/src/lib/ogp/plugins/plugin.py
    trunk/src/lib/ogp/plugins/test/test.py
    trunk/src/lib/ogp/plugins/test/test.pyc
    trunk/src/tests/ogp-test.py


Modified: trunk/src/lib/ogp/core/ogpcore.py
===================================================================
--- trunk/src/lib/ogp/core/ogpcore.py	2009-03-21 13:11:58 UTC (rev 71)
+++ trunk/src/lib/ogp/core/ogpcore.py	2009-03-21 15:18:18 UTC (rev 72)
@@ -201,13 +201,33 @@
 			loopDn=[]
 			for obj in dn:
 				loopDn.insert(0, obj)
-				print dn2str(loopDn)
 				try:
 					SOAs[dn2str(loopDn)] = self.__pullSOA(dn2str(loopDn))
-					print dn2str(loopDn) + SOAs[dn2str(loopDn)]
 				except:
 					pass
 			return SOAs
+
+		def getRequiredPlugins(self, dn):
+			"""
+				Returns the names of the plugins that should be installed on the client,
+				identified by its DN, to install the configuration store in the LDAP.
+				dn: the distinguished name of the targeted object
+			"""
+			plugins = []
+			dn=str2dn(dn)
+			dn.reverse()
+			loopDn=[]
+			for obj in dn:
+				loopDn.insert(0, obj)
+				try:
+					conf = self.__pullConf(dn2str(loopDn))
+					for plugin in conf:
+						if plugin.get(OgpXmlConsts.ATTR_PLUGIN_NAME) not in plugins:
+							plugins.append(plugin.get(OgpXmlConsts.ATTR_PLUGIN_NAME))
+				except:
+					pass
+			plugins.sort()
+			return plugins
 		
 		def __add(self, dn, attrs):
 			ldif = modlist.addModlist(attrs)

Modified: trunk/src/lib/ogp/etree/elementmethods.py
===================================================================
--- trunk/src/lib/ogp/etree/elementmethods.py	2009-03-21 13:11:58 UTC (rev 71)
+++ trunk/src/lib/ogp/etree/elementmethods.py	2009-03-21 15:18:18 UTC (rev 72)
@@ -31,9 +31,9 @@
 		if item == "text" and value is not None:
 			self.delElements()
 		if item == "tail":
-			raise OgpXmlError('__setattr__: setting tail is forbiden, it must be None')
+			raise OgpXmlError('__setattr__: setting tail is forbiden, it must be None.')
 		if item == "attrib":
-			raise OgpXmlError('__setattr__: setting attributes directly is forbiden, please use self.set(name, value)')
+			raise OgpXmlError('__setattr__: setting attributes directly is forbiden, please use self.set(name, value).')
 		ElementBase.__setattr__(self, item, value)
 
 	def __getattribute__(self, item):
@@ -111,7 +111,7 @@
 			checks unicity before adding, and deletes text
 		"""
 		assert isinstance(newChild, OgpElement)
-		if (not self.__checkUnicity(newChild)):raise OgpXmlError('append: element is not unique')
+		if (not self.__checkUnicity(newChild)):raise OgpXmlError('append: element is not unique.')
 		self.text = None
 		ElementBase.append(self, newChild)
 
@@ -123,7 +123,7 @@
 		assert isinstance(newChild, OgpElement)
 		assert isinstance(index, int)
 
-		if (not self.__checkUnicity(newChild)):raise OgpXmlError('insert: element is not unique')
+		if (not self.__checkUnicity(newChild)):raise OgpXmlError('insert: element is not unique.')
 		self.text = None
 		ElementBase.insert(self, index, element)
 
@@ -134,7 +134,7 @@
 		"""
 		for element in elements:
 			assert isinstance(element, OgpElement)
-			if (not self.__checkUnicity(element)):raise OgpXmlError('extend: element is not unique')
+			if (not self.__checkUnicity(element)):raise OgpXmlError('extend: element is not unique.')
 		self.text = None
 		ElementBase.extend(self, elements) 
 
@@ -154,7 +154,7 @@
 		if parent is not None:
 			for br in parent:
 				if br is not self and br.tag == self.tag and br.attributes == newattrs:
-					raise OgpXmlError('set: element would no more be unique')
+					raise OgpXmlError('set: element would no more be unique.')
 		self.__attrib[name] = value
 
 	def merge(self, peer):
@@ -167,11 +167,11 @@
 		#if self and peer are not exactly the same (i.e. same name and same attributes),
 		#raise OgpXmlError.
 		if self.tag != peer.tag or self.attributes != peer.attributes:
-			raise OgpXmlError('merge: peer has not same name or attributes')
+			raise OgpXmlError('merge: peer has not same name or attributes.')
 		
 		#Nodes must have same content. If not, raise OgpXmlError
-		if (len(self) == 0) ^ (len(peer) == 0):
-			raise OgpXmlError('merge: peer has not same type of content')
+		if ((len(self) == 0) ^ (len(peer) == 0)) or ((self.text is None) ^ (peer.text is None)):
+			raise OgpXmlError('merge: peer has not same type of content.')
 
 		#if blocking, stop here
 		if self.blocking:return

Modified: trunk/src/lib/ogp/plugins/plugin.py
===================================================================
--- trunk/src/lib/ogp/plugins/plugin.py	2009-03-21 13:11:58 UTC (rev 71)
+++ trunk/src/lib/ogp/plugins/plugin.py	2009-03-21 15:18:18 UTC (rev 72)
@@ -14,7 +14,7 @@
 	"""
 		Makes the 'name' __CLASS__ attribute readonly.
 	"""
-	__setattr__ = setattr
+	__setattr__ = setattr # Plugin name protection
 
 class Plugin(object):
 	"""
@@ -26,7 +26,7 @@
 	def __init__(self, dn):
 		self.__dn = dn
 	
-	__setattr__ = setattr
+	__setattr__ = setattr # Plugin name protection
 
 	name = None # the plugin name
 	__registeredPlugins = dict()
@@ -94,7 +94,7 @@
 	
 	def help(self, cmdName=None):
 		"""
-			provides informations about the plugin user interface
+			provides informations about the plugin user interface.
 			plugin.help() should return all available commands as a dict {cmdName: description}
 			plugin.help(cmdName) should return all available arguments as a dict {argName: description}
 		"""
@@ -102,7 +102,7 @@
 
 	def runCommand(self, cmdName, argv):
 		"""
-			runs a command on the conf
+			Runs a command on the conf.
 			Usage:
 				plugin.runCommand(cmdName, argv)
 				where argv is a dict {argName: argVal}
@@ -111,7 +111,7 @@
 	
 	def pullFile(self, file, fullTree=False):
 		"""
-			builds the content of a file from the XML tree, for preview purposes.
+			Builds the content of a file from the XML tree, for preview purposes.
 			Arguments:
 				file          : the logical name of the targeted file
 				fullTree=False: if set to true, merges the conf from the baseDN up to the current DN before building
@@ -120,7 +120,7 @@
 
 	def pushFile(self, file, content):
 		"""
-			builds XML configuration from a string content and loads it in the corresponding <file> Element
+			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

Modified: trunk/src/lib/ogp/plugins/test/test.py
===================================================================
--- trunk/src/lib/ogp/plugins/test/test.py	2009-03-21 13:11:58 UTC (rev 71)
+++ trunk/src/lib/ogp/plugins/test/test.py	2009-03-21 15:18:18 UTC (rev 72)
@@ -5,5 +5,5 @@
 
 class Test(Plugin):
 	name = "test"
-	def test(self):
-		print "toto" + self.name
+	def installConf(self):
+		pass

Modified: trunk/src/lib/ogp/plugins/test/test.pyc
===================================================================
(Binary files differ)

Modified: trunk/src/tests/ogp-test.py
===================================================================
--- trunk/src/tests/ogp-test.py	2009-03-21 13:11:58 UTC (rev 71)
+++ trunk/src/tests/ogp-test.py	2009-03-21 15:18:18 UTC (rev 72)
@@ -5,7 +5,7 @@
 from ogp.etree import *
 
 uri = "ldap://localhost:389";
-dn = "cn=admin,dc=ogp"
+dn = "cn=admin,dc=nodomain"
 passwd = "toor"
 
 # Connection
@@ -23,9 +23,10 @@
 
 toto = OgpCore.getInstance()
 
-#toto.createOU("ou=test,dc=ogp")
-conf = fromstring('<plugin name="test">test pushConf le retour</plugin>', OGP_PARSER)
-toto.pushPluginConf("ou=test,dc=ogp", conf)
+toto.createOU("ou=test2,ou=test,dc=nodomain")
+conf = fromstring('<plugin name="test2">test pushConf le retour</plugin>', OGP_PARSER)
+toto.pushPluginConf("ou=test2,ou=test,dc=nodomain", conf)
 #toto.deleteDN("ou=test,dc=ogp")
-print toto.pushDescription("ou=test,dc=ogp", "test")
-print toto.pullPluginConf("ou=test,dc=ogp", "test", True).toString()
+#print toto.pushDescription("ou=test,dc=ogp", "test")
+#print toto.pullPluginConf("ou=test,dc=nodomain", "test").get('name')
+print toto.getRequiredPlugins("ou=test2,ou=test,dc=nodomain")


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