[Dev OpenGP] [49] New directory structure (ain't that cleaner?)

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


Revision: 49
Author:   alband85
Date:     2009-03-18 13:07:37 +0100 (Wed, 18 Mar 2009)

Log Message:
-----------
New directory structure (ain't that cleaner?)

Added Paths:
-----------
    trunk/src/bin/
    trunk/src/bin/ogpconsole
    trunk/src/lib/
    trunk/src/lib/ogp/
    trunk/src/lib/ogp/__init__.py
    trunk/src/lib/ogp/core/
    trunk/src/lib/ogp/core/__init__.py
    trunk/src/lib/ogp/core/ogpcore.py
    trunk/src/lib/ogp/core/ogpldapconsts.py
    trunk/src/tests/
    trunk/src/tests/etree-test.py
    trunk/src/tests/merge-test.py
    trunk/src/tests/ogp-test.py
    trunk/src/tests/text.py


Added: trunk/src/bin/ogpconsole
===================================================================
--- trunk/src/bin/ogpconsole	                        (rev 0)
+++ trunk/src/bin/ogpconsole	2009-03-18 12:07:37 UTC (rev 49)
@@ -0,0 +1,3 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*
+


Property changes on: trunk/src/bin/ogpconsole
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/lib/ogp/__init__.py
===================================================================
--- trunk/src/lib/ogp/__init__.py	                        (rev 0)
+++ trunk/src/lib/ogp/__init__.py	2009-03-18 12:07:37 UTC (rev 49)
@@ -0,0 +1,2 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*

Added: trunk/src/lib/ogp/core/__init__.py
===================================================================
--- trunk/src/lib/ogp/core/__init__.py	                        (rev 0)
+++ trunk/src/lib/ogp/core/__init__.py	2009-03-18 12:07:37 UTC (rev 49)
@@ -0,0 +1,2 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*

Added: trunk/src/lib/ogp/core/ogpcore.py
===================================================================
--- trunk/src/lib/ogp/core/ogpcore.py	                        (rev 0)
+++ trunk/src/lib/ogp/core/ogpcore.py	2009-03-18 12:07:37 UTC (rev 49)
@@ -0,0 +1,94 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*
+
+import ldap
+import ldap.modlist as modlist
+from ogpldapconsts import *
+
+class OgpCore(object):
+
+	__instance = None
+
+	def __init__(self, uri, dn=None, passwd=None, certs=None):
+		""" Create singleton instance """
+		# Check whether we already have an instance
+		if OgpCore.__instance is None:
+			# Create and remember instance
+			OgpCore.__instance = OgpCore.__ogpcore(uri, dn, passwd, certs)
+		# Store instance reference as the only member in the handle
+		self.__dict__['OgpCore__instance'] = OgpCore.__instance
+
+	def __getattr__(self, attr):
+		""" Delegate access to implementation """
+		return getattr(self.__instance, attr)
+
+	def __setattr__(self, attr, value):
+		""" Delegate access to implementation """
+		return setattr(self.__instance, attr, value)
+
+	def getInstance():
+		return OgpCore.__instance
+	getInstance = staticmethod(getInstance)
+	
+	class __ogpcore:
+
+		def	__init__(self, uri, dn=None, passwd=None, certs=None):
+			"""
+				Initlialize connection to LDAP server. 
+				uri: ldap://host:port
+				dn: usdr dn
+				passwd: user password
+				certs: path to cert file (.pem)
+			"""
+			self.l = ldap.initialize(uri)
+			self.l.simple_bind_s(dn, passwd)
+
+		def __del__(self):
+			self.l.unbind_s()
+
+		def createOU(self, dn, description=None):
+			attrs = {}
+			attrs['objectclass'] = OgpLDAPConsts.OBJECTCLASS_OU
+			attrs[OgpLDAPConsts.ATTR_OGPSOA] = OgpLDAPConsts.VALUE_OGPSOA
+			attrs[OgpLDAPConsts.ATTR_DESCRIPTION] = description
+			attrs[OgpLDAPConsts.ATTR_CONFIG] = OgpLDAPConsts.VALUE_CONFIG
+			self.__add(dn, attrs) 
+
+		def deleteDN(self, dn):
+			#self.__delete(dn)
+			pass
+
+
+		def __add(self, dn, attrs):
+			ldif = modlist.addModlist(attrs)
+			self.l.add_s(dn,ldif)
+
+		def __delete(self, dn):
+			self.l.delete_s(dn)
+
+		def createMachine(self, dn, others={}):
+			attrs = others
+			attrs['objectClass'] = OgpLDAPConsts.OBJECTCLASS_MACHINE
+			attrs[OgpLDAPConsts.ATTR_OGPSOA] = OgpLDAPConsts.VALUE_OGPSOA
+			try:
+				attrs[OgpLDAPConsts.ATTR_SAMACCOUNTNAME]
+			except:
+				attrs[OgpLDAPConsts.ATTR_SAMACCOUNTNAME] = OgpLDAPConsts.VALUE_SAMACCOUNTNAME
+			try:
+				attrs[OgpLDAPConsts.ATTR_OBJECTSID]
+			except:
+				attrs[OgpLDAPConsts.ATTR_OBJECTSID] = OgpLDAPConsts.VALUE_OBJECTSID
+			attrs[OgpLDAPConsts.ATTR_CONFIG] = OgpLDAPConsts.VALUE_CONFIG
+			self.__add(dn, attrs)
+
+		def merge(self, parent, child):
+			pass
+
+		def xml2conf(self, xml, xslt):
+			return # TODO
+
+		def pullPluginConf(self, dn, pluginName, fullTree=False):
+			pass
+
+		def pushPluginConf(self, dn, conf):
+			pass

Added: trunk/src/lib/ogp/core/ogpldapconsts.py
===================================================================
--- trunk/src/lib/ogp/core/ogpldapconsts.py	                        (rev 0)
+++ trunk/src/lib/ogp/core/ogpldapconsts.py	2009-03-18 12:07:37 UTC (rev 49)
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*
+
+class OgpLDAPConsts:
+
+	OBJECTCLASS_OU 			= "oGPOrganizationalUnit"
+	OBJECTCLASS_MACHINE 	= "oGPComputer"
+
+	ATTR_DESCRIPTION 		= "description"
+	ATTR_CONFIG 			= "oGPXMLConfig"
+	ATTR_SAMACCOUNTNAME		= "sAMAccountName"
+	ATTR_OBJECTSID			= "objectSid"
+	ATTR_OGPSOA				= "oGPSOA"
+	ATTR_MACHINECERTIFICATE	= "oGPMachineCertificate"
+
+	VALUE_CONFIG			= "<conf></conf>"
+	VALUE_SAMACCOUNTNAME	= "N/A"
+	VALUE_OBJECTSID			= "\0"
+	VALUE_OGPSOA			= "0"

Added: trunk/src/tests/etree-test.py
===================================================================
--- trunk/src/tests/etree-test.py	                        (rev 0)
+++ trunk/src/tests/etree-test.py	2009-03-18 12:07:37 UTC (rev 49)
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*
+from lxml.etree import *
+from DomElementMethods import *
+
+obj = Element("rootelement")
+obj2 = Element("rootelement")
+
+print "------ BLOCKING ------"
+print obj.toString()
+obj.blocking = True
+print obj.toString()
+obj.blocking = False
+print obj.toString()
+print "------- ADD --------"
+elt = Element("inserted")
+elt2 = Element("inserted")
+obj.append(elt)
+try:
+	obj.append(elt2)
+except OgpXmlError:
+	print "crash"
+
+print obj.toString()
+
+print "------ DEL -------"
+print obj.toString()
+obj.delElements()
+print obj.toString()
+
+print "------ EXTEND -------"
+print obj.toString()
+try:
+	obj.extend([elt, elt2])
+except:
+	print "crash"
+print obj.toString()
+obj.delElements()
+elt3 = Element("pouet3")
+obj.extend([elt, elt3])
+print obj.toString()
+
+print "--------- MERGE ----------"
+print (obj.text is None)
+print (obj2.text is None)
+obj.delElements()
+obj2.delElements()
+obj.append(elt)
+obj2.append(elt3)
+print obj.toString()
+print obj2.toString()
+obj2.merge(obj)
+print tostring(obj2)
+
+print "   Avec du texte maintenant"
+obj3 = Element("AAA")
+obj4 = Element("AAA")
+obj3.text = "pouet"
+obj4.text = "I'm not dead"
+print tostring(obj3)
+print tostring(obj4)
+obj4.merge(obj3)
+print tostring(obj3)
+print tostring(obj4)
+
+print " -------SETTEXT----------"
+obj.delElements()
+obj.append(elt)
+print obj.toString()
+obj.text = "toto"
+print obj.text
+print obj.toString()
+
+


Property changes on: trunk/src/tests/etree-test.py
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/tests/merge-test.py
===================================================================
--- trunk/src/tests/merge-test.py	                        (rev 0)
+++ trunk/src/tests/merge-test.py	2009-03-18 12:07:37 UTC (rev 49)
@@ -0,0 +1,13 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*
+
+from lxml.etree import *
+from ogp import etree
+
+parent=fromstring('<ogp><a>parent</a><b block="True">parent</b><c><parent/></c></ogp>', etree.OGP_PARSER)
+child=fromstring('<ogp><a>child</a><b>child</b><c><child/></c></ogp>', etree.OGP_PARSER)
+
+print "parent :\n" + parent.toString()
+print "child :\n" + child.toString()
+parent.merge(child)
+print "merge :\n" + parent.toString()


Property changes on: trunk/src/tests/merge-test.py
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/tests/ogp-test.py
===================================================================
--- trunk/src/tests/ogp-test.py	                        (rev 0)
+++ trunk/src/tests/ogp-test.py	2009-03-18 12:07:37 UTC (rev 49)
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*
+
+from OgpCore import *
+
+uri = "ldap://localhost:389";
+dn = "cn=admin,dc=ogp"
+passwd = "toor"
+
+# Connection
+ogp = OgpCore(uri, dn, passwd)
+
+# Create OU
+#ogp.createOU("ou=titi322,ou=tutu,dc=ogp","Bonjour, je teste en direct")
+#ogp.createMachine('cn=la,ou=titi322,ou=tutu,dc=ogp')
+
+#toto = "<file>Ceci est un test</file>"
+
+#ogp.push(toto, 'cn=mac2,ou=titi,ou=tutu,dc=ogp')
+
+#ogp.deleteOU("cn=la,ou=titi322,ou=tutu,dc=ogp")
+
+toto = OgpCore.getInstance()
+
+toto.createOU("ou=titi3227,ou=tutu,dc=ogp","Bonjour, je teste en en 2kkcjd")


Property changes on: trunk/src/tests/ogp-test.py
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/tests/text.py
===================================================================
--- trunk/src/tests/text.py	                        (rev 0)
+++ trunk/src/tests/text.py	2009-03-18 12:07:37 UTC (rev 49)
@@ -0,0 +1,9 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*
+from DomElementMethods import *
+
+obj = Element("AAA")
+obj.text = "pouet"
+print obj.text
+obj.tail = "test"
+print tostring(obj)


Property changes on: trunk/src/tests/text.py
___________________________________________________________________
Name: svn:executable
   + *


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