[Dev OpenGP] [60] bugfixes in OgpElement::merge, core implementation in progress |
[ Thread Index |
Date Index
| More opengp.tuxfamily.org/development Archives
]
Revision: 60
Author: nicolaf
Date: 2009-03-18 17:00:40 +0100 (Wed, 18 Mar 2009)
Log Message:
-----------
bugfixes in OgpElement::merge, core implementation in progress
Modified Paths:
--------------
trunk/src/lib/ogp/core/ogpcore.py
trunk/src/lib/ogp/core/ogpldapconsts.py
trunk/src/lib/ogp/etree/__init__.py
trunk/src/lib/ogp/etree/elementmethods.py
trunk/src/tests/ogp-test.py
Added Paths:
-----------
trunk/src/lib/ogp/etree/ogpxmlconsts.py
Modified: trunk/src/lib/ogp/core/ogpcore.py
===================================================================
--- trunk/src/lib/ogp/core/ogpcore.py 2009-03-18 14:22:43 UTC (rev 59)
+++ trunk/src/lib/ogp/core/ogpcore.py 2009-03-18 16:00:40 UTC (rev 60)
@@ -5,7 +5,10 @@
import ldap.modlist as modlist
from ldap.dn import *
from ogpldapconsts import *
+from lxml.etree import *
+from ogp.etree import *
+
class OgpCore(object):
__instance = None
@@ -51,7 +54,8 @@
attrs = {}
attrs['objectclass'] = OgpLDAPConsts.OBJECTCLASS_OU
attrs[OgpLDAPConsts.ATTR_OGPSOA] = OgpLDAPConsts.VALUE_OGPSOA
- attrs[OgpLDAPConsts.ATTR_DESCRIPTION] = description
+ if description is not None:
+ attrs[OgpLDAPConsts.ATTR_DESCRIPTION] = description
attrs[OgpLDAPConsts.ATTR_CONFIG] = OgpLDAPConsts.VALUE_CONFIG
self.__add(dn, attrs)
@@ -73,6 +77,8 @@
attrs = others
attrs['objectClass'] = OgpLDAPConsts.OBJECTCLASS_MACHINE
attrs[OgpLDAPConsts.ATTR_OGPSOA] = OgpLDAPConsts.VALUE_OGPSOA
+
+ #default values for mandatory fields
try:
attrs[OgpLDAPConsts.ATTR_SAMACCOUNTNAME]
except:
@@ -81,12 +87,42 @@
attrs[OgpLDAPConsts.ATTR_OBJECTSID]
except:
attrs[OgpLDAPConsts.ATTR_OBJECTSID] = OgpLDAPConsts.VALUE_OBJECTSID
+
attrs[OgpLDAPConsts.ATTR_CONFIG] = OgpLDAPConsts.VALUE_CONFIG
self.__add(dn, attrs)
+ def __pullConf(self, dn):
+ return fromstring(self.l.search_s(dn, ldap.SCOPE_BASE, attrlist=[OgpLDAPConsts.ATTR_CONFIG])[0][1][OgpLDAPConsts.ATTR_CONFIG][0], OGP_PARSER)
+
def pullPluginConf(self, dn, pluginName, fullTree=False):
- dn = explode_dn(dn)
- print dn
+ pConf = None
+ if fullTree:
+ dn=str2dn(dn)
+ dn.reverse()
+ loopDn=[]
+ for obj in dn:
+ loopDn.insert(0, obj)
+ dnConf = self.pullPluginConf(dn2str(loopDn), pluginName)
+ if pConf is None:
+ pConf = dnConf
+ elif dnConf is not None:
+ pConf.merge(dnConf)
+ else:
+ pass
+ else:
+ try:
+ conf=self.__pullConf(dn)
+ except:
+ return None
+
+ for plugin in conf:
+ if plugin.get(OgpXmlConsts.ATTR_PLUGIN_NAME) == pluginName:
+ pConf = plugin
+ break
+ return pConf
def pushPluginConf(self, dn, conf):
pass
+
+ def pullSOAs(self, dn):
+ pass
Modified: trunk/src/lib/ogp/core/ogpldapconsts.py
===================================================================
--- trunk/src/lib/ogp/core/ogpldapconsts.py 2009-03-18 14:22:43 UTC (rev 59)
+++ trunk/src/lib/ogp/core/ogpldapconsts.py 2009-03-18 16:00:40 UTC (rev 60)
@@ -13,7 +13,7 @@
ATTR_OGPSOA = "oGPSOA"
ATTR_MACHINECERTIFICATE = "oGPMachineCertificate"
- VALUE_CONFIG = "<conf></conf>"
+ VALUE_CONFIG = "<ogp/>"
VALUE_SAMACCOUNTNAME = "N/A"
VALUE_OBJECTSID = "\0"
VALUE_OGPSOA = "0"
Modified: trunk/src/lib/ogp/etree/__init__.py
===================================================================
--- trunk/src/lib/ogp/etree/__init__.py 2009-03-18 14:22:43 UTC (rev 59)
+++ trunk/src/lib/ogp/etree/__init__.py 2009-03-18 16:00:40 UTC (rev 60)
@@ -3,6 +3,7 @@
from lxml.etree import *
from elementmethods import *
+from ogpxmlconsts import *
def parse(source, parser=None):
if not hasattr(source, "read"):
Modified: trunk/src/lib/ogp/etree/elementmethods.py
===================================================================
--- trunk/src/lib/ogp/etree/elementmethods.py 2009-03-18 14:22:43 UTC (rev 59)
+++ trunk/src/lib/ogp/etree/elementmethods.py 2009-03-18 16:00:40 UTC (rev 60)
@@ -3,10 +3,8 @@
from lxml.etree import *
from copy import deepcopy
+from ogpxmlconsts import *
-ATTR_BLOCK = "block"
-ATTR_ID = "id"
-
class OgpElement(ElementBase):
def __setattr__(self, item, value):
@@ -23,7 +21,7 @@
def __getAttributes(self):
res = dict()
for key in self.attrib:
- if key != ATTR_BLOCK:
+ if key != OgpXmlConsts.ATTR_BLOCK:
res[key] = self.attrib[key]
return res
attributes = property(__getAttributes)
@@ -32,7 +30,7 @@
"""
A more convenient way to access the 'block' special attribute.
"""
- b = self.get(ATTR_BLOCK)
+ b = self.get(OgpXmlConsts.ATTR_BLOCK)
if b is None:
return False
else:
@@ -44,10 +42,10 @@
"""
assert isinstance(blocking, bool)
if blocking:
- self.attrib[ATTR_BLOCK] = str(blocking).lower()
+ self.attrib[OgpXmlConsts.ATTR_BLOCK] = str(blocking).lower()
else:
try:
- del self.attrib[ATTR_BLOCK]
+ del self.attrib[OgpXmlConsts.ATTR_BLOCK]
except:
pass
blocking = property(__getBlocking, __setBlocking)
@@ -127,14 +125,14 @@
raise OgpXmlError('merge: peer has not same name or attributes')
#Nodes must have same content. If not, raise OgpXmlError
- if not ((self.text is None) ^ (peer.text is not None)):
+ if (len(self) == 0) ^ (len(peer) == 0):
raise OgpXmlError('merge: peer has not same type of content')
#if blocking, stop here
if self.blocking:return
#First case : nodes contains Text
- if self.text is not None:
+ if self.text is not None or peer.text is not None:
self.text = peer.text
return
else: #Second Case : nodes contains nodes
@@ -173,14 +171,14 @@
peerMaxId = 0
if len(peer) > 0 and len(self) > 0:
for e in peer:
- id = e.get(ATTR_ID)
+ id = e.get(OgpXmlConsts.ATTR_ID)
if id is not None and int(id) > peerMaxId:
peerMaxId = int(id)
for e in self:
- id = e.get(ATTR_ID)
+ id = e.get(OgpXmlConsts.ATTR_ID)
if id is not None:
- e.set(ATTR_ID, str(int(id) + peerMaxId + 1))
+ e.set(OgpXmlConsts.ATTR_ID, str(int(id) + peerMaxId + 1))
def toString(self, xsl=None, params=None):
if xsl is None:
Added: trunk/src/lib/ogp/etree/ogpxmlconsts.py
===================================================================
--- trunk/src/lib/ogp/etree/ogpxmlconsts.py (rev 0)
+++ trunk/src/lib/ogp/etree/ogpxmlconsts.py 2009-03-18 16:00:40 UTC (rev 60)
@@ -0,0 +1,4 @@
+class OgpXmlConsts:
+ ATTR_BLOCK = "block"
+ ATTR_ID = "id"
+ ATTR_PLUGIN_NAME = "name"
Modified: trunk/src/tests/ogp-test.py
===================================================================
--- trunk/src/tests/ogp-test.py 2009-03-18 14:22:43 UTC (rev 59)
+++ trunk/src/tests/ogp-test.py 2009-03-18 16:00:40 UTC (rev 60)
@@ -4,7 +4,7 @@
from ogp.core import *
uri = "ldap://localhost:389"
-dn = "cn=admin,dc=ogp"
+dn = "cn=admin,dc=nodomain"
passwd = "toor"
# Connection
@@ -22,4 +22,5 @@
toto = OgpCore.getInstance()
-toto.createOU("ou=titi3227,ou=tutu,dc=ogp","Bonjour, je teste en en 2kkcjd")
+#toto.createOU("ou=test2,ou=test,dc=nodomain")
+print toto.pullPluginConf("ou=test2,ou=test,dc=nodomain", "test", True).toString()