[Da-tools-commits] ./da-tools/userdir-ldap-cgi-python r13: adding a libformat to handle the [[, ]], *, -, ~ crap. It would be wonderfull

Robin Wittler real at geek-at-work.org
Thu Jan 22 21:50:03 UTC 2009


------------------------------------------------------------
revno: 13
committer: Robin Wittler <real at geek-at-work.org>
branch nick: userdir-ldap-cgi-python
timestamp: Thu 2009-01-22 22:50:03 +0100
message:
  adding a libformat to handle the [[, ]], *, -, ~ crap. It would be wonderfull
  if i can have a spec what special chars exists!
  
  adding default_value to some method in libldap
  
  changing machines template to call libformat.
  The formating stuff is totaly wrong. it is only a prototype.
added:
  ud_ldap_ng/lib/libformat.py
modified:
  ud_ldap_ng/controllers/udldapng.py
  ud_ldap_ng/lib/libldap.py
  ud_ldap_ng/templates/machines.html
-------------- next part --------------
=== modified file 'ud_ldap_ng/controllers/udldapng.py'
--- a/ud_ldap_ng/controllers/udldapng.py	2009-01-22 20:02:28 +0000
+++ b/ud_ldap_ng/controllers/udldapng.py	2009-01-22 21:50:03 +0000
@@ -1,3 +1,9 @@
+#!/usr/bin/env python
+# -*- coding: utf8 -*-
+__version__ = '0.0.3'
+__author__ = 'Robin Wittler <real at geek-at-work.org>'
+__license__ = 'GPL3'
+
 import logging
 
 from pylons import request, response, session, tmpl_context as c
@@ -13,23 +19,6 @@
 class UdldapngController(BaseController):
 	def index(self):
 		con = AnonymousDebianLDAP()
-		c.result = con.getDebianHosts(attrlist=['hostname', 'architecture', 'purpose', 'status', 'sponsor'], adjust=True)
-		#c.result = dict()
+		c.attributes = ['hostname', 'architecture', 'purpose', 'sponsor', 'status']
+		c.result = con.getDebianHosts(attrlist=c.attributes, adjust=True, default_value='')
 		return render('/machines.html')
-	
-	def lala(self):
-		con = connectLDAP('db.debian.org')
-		bindLDAP(con)
-		user = request.params['uid']
-		results = searchUser(con, user)
-		return repr(results)
-        #result_set = []
-        #result_type, result_data = con.result(results, 0)
-        #if result_type == ldap.RES_SEARCH_ENTRY:
-        #     result_set.append(result_data)
-        #return render('/developer.html')
-#        return "hello world"
-#        #return repr(searchHosts(con))
-#        return 'Hello World'
-
-# ((la), {})

=== added file 'ud_ldap_ng/lib/libformat.py'
--- a/ud_ldap_ng/lib/libformat.py	1970-01-01 00:00:00 +0000
+++ b/ud_ldap_ng/lib/libformat.py	2009-01-22 21:50:03 +0000
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+# -*- coding: utf8 -*-
+__version__ = '0.0.1'
+__author__ = 'Robin Wittler <real at geek-at-work.org>'
+__license__ = 'GPL3'
+
+def formattxt(value):
+	for i in ('*', '@'):
+		value = value.replace (i, '')
+	if '[[' in value:
+		value = value.replace('[[', '')
+		if '|' in value:
+			value = value.split('|')
+			value.extend([i for i in value.pop().split(']]') if i])
+		else:
+			value = [i for i in value.split(']]') if i]
+	return value
+
+if __name__ == '__main__':
+		pass

=== modified file 'ud_ldap_ng/lib/libldap.py'
--- a/ud_ldap_ng/lib/libldap.py	2009-01-22 20:02:28 +0000
+++ b/ud_ldap_ng/lib/libldap.py	2009-01-22 21:50:03 +0000
@@ -38,7 +38,7 @@
 		@param adjust				If True, the class adds automatic any missing attribute
 		@type adjust				bool		
 		'''
-	def __new__(cls, results, adjust=False):
+	def __new__(cls, results, adjust=False, default_value=['Unknown',]):
 		cls.isRawLDAPResult(results)
 		if not type(adjust) == bool:
 			raise TypeError('adjust must be typ bool')
@@ -46,7 +46,7 @@
 		cls.__results = cls.alterDNFromResults(results)
 		if adjust:
 			cls.adjusted = True
-			cls.__results = cls.adjustResults(cls.__results)
+			cls.__results = cls.adjustResults(cls.__results, default_value=default_value)
 		else:
 			cls.adjusted = False
 		return object.__new__(cls)
@@ -380,7 +380,7 @@
 		return DebianLDAPResult(self.ldapSearch(dn, scope, attrlist=attrlist))
 
 	
-	def getDebianHosts(self, attrlist=None, adjust=False):
+	def getDebianHosts(self, attrlist=None, adjust=False, default_value=['Unknown',]):
 		'''getDebianHosts returns recursive all hosts and all hosts attributes from debian ldap.
 		Optional you can submit a list of attributes in which you are only interested.
 		If you set adjust to True, then every result will automaticly have all the same count of
@@ -398,7 +398,7 @@
 			raise TypeError('adjust must be type bool')
 		dn = 'ou=hosts,dc=debian,dc=org'
 		scope = ldap.SCOPE_SUBTREE
-		return DebianLDAPResult(self.ldapSearch(dn, scope, attrlist=attrlist), adjust=adjust)
+		return DebianLDAPResult(self.ldapSearch(dn, scope, attrlist=attrlist), adjust=adjust, default_value=default_value)
 
 __all__ = ['MyLDAP', 'DebianLDAPResult', 'AnonymousDebianLDAP']
 

=== modified file 'ud_ldap_ng/templates/machines.html'
--- a/ud_ldap_ng/templates/machines.html	2009-01-13 21:13:30 +0000
+++ b/ud_ldap_ng/templates/machines.html	2009-01-22 21:50:03 +0000
@@ -55,11 +55,21 @@
 									${hostname}
 								% endfor
 							</td>
-							% for key in ['architecture', 'purpose', 'sponsor', 'status']:
+							<%! from ud_ldap_ng.lib.libformat import formattxt %>
+							% for key in c.attributes[1:]:
 								<td>
 									<ul>
 										% for value in result.get(key, ['Unknown',]):
-											<li>${value}</li>
+											<% value = formattxt(value)	%>
+											% if type(value) == str:											
+												<li>${value}</li>
+											% elif len(value) == 1:
+												<li><a href="http://${value[0]}">${value[0]}</a></li>
+											% elif len(value) == 2:
+												<li><a href="http://${value[0]}">${value[1]}</a></li>
+											% else:
+												<li><a href="http://${value[0]}">${value[1]}</a>${value[2]}</li>
+											% endif
 										% endfor
 									</ul>
 								</td>



More information about the Da-tools-commits mailing list