doc/book/en/annexes/faq.rst
branchstable
changeset 5393 875bdc0fe8ce
parent 5388 9167751463d4
child 5781 a3e60e0fb0f3
equal deleted inserted replaced
5388:9167751463d4 5393:875bdc0fe8ce
   288 Any change applied to configuration file requires to restart your
   288 Any change applied to configuration file requires to restart your
   289 instance.
   289 instance.
   290 
   290 
   291 You can find additional information in the section :ref:`LDAP`.
   291 You can find additional information in the section :ref:`LDAP`.
   292 
   292 
       
   293 How to import LDAP users in |cubicweb| ?
       
   294 ----------------------------------------
       
   295 
       
   296   Here is a useful script which enables you to import LDAP users
       
   297   into your *CubicWeb* instance by running the following:
       
   298 
       
   299 .. sourcecode:: python
       
   300 
       
   301     import os
       
   302     import pwd
       
   303     import sys
       
   304 
       
   305     from logilab.common.db import get_connection
       
   306 
       
   307     def getlogin():
       
   308         """avoid usinng os.getlogin() because of strange tty / stdin problems
       
   309         (man 3 getlogin)
       
   310         Another solution would be to use $LOGNAME, $USER or $USERNAME
       
   311         """
       
   312         return pwd.getpwuid(os.getuid())[0]
       
   313 
       
   314 
       
   315     try:
       
   316         database = sys.argv[1]
       
   317     except IndexError:
       
   318         print 'USAGE: python ldap2system.py <database>'
       
   319         sys.exit(1)
       
   320 
       
   321     if raw_input('update %s db ? [y/n]: ' % database).strip().lower().startswith('y'):
       
   322         cnx = get_connection(user=getlogin(), database=database)
       
   323         cursor = cnx.cursor()
       
   324 
       
   325         insert = ('INSERT INTO euser (creation_date, eid, modification_date, login, '
       
   326                   ' firstname, surname, last_login_time, upassword) '
       
   327                   "VALUES (%(mtime)s, %(eid)s, %(mtime)s, %(login)s, %(firstname)s, "
       
   328                   "%(surname)s, %(mtime)s, './fqEz5LeZnT6');")
       
   329         update = "UPDATE entities SET source='system' WHERE eid=%(eid)s;"
       
   330         cursor.execute("SELECT eid,type,source,extid,mtime FROM entities WHERE source!='system'")
       
   331         for eid, type, source, extid, mtime in cursor.fetchall():
       
   332             if type != 'CWUser':
       
   333                 print "don't know what to do with entity type", type
       
   334                 continue
       
   335             if source != 'ldapuser':
       
   336                 print "don't know what to do with source type", source
       
   337                 continue
       
   338             ldapinfos = dict(x.strip().split('=') for x in extid.split(','))
       
   339             login = ldapinfos['uid']
       
   340             firstname = ldapinfos['uid'][0].upper()
       
   341             surname = ldapinfos['uid'][1:].capitalize()
       
   342             if login != 'jcuissinat':
       
   343                 args = dict(eid=eid, type=type, source=source, login=login,
       
   344                             firstname=firstname, surname=surname, mtime=mtime)
       
   345                 print args
       
   346                 cursor.execute(insert, args)
       
   347                 cursor.execute(update, args)
       
   348 
       
   349         cnx.commit()
       
   350         cnx.close()
       
   351 
       
   352 
   293 I get NoSelectableObject exceptions, how do I debug selectors ?
   353 I get NoSelectableObject exceptions, how do I debug selectors ?
   294 ---------------------------------------------------------------
   354 ---------------------------------------------------------------
   295 
   355 
   296 You just need to put the appropriate context manager around view/component
   356 You just need to put the appropriate context manager around view/component
   297 selection (one standard place in in vreg.py):
   357 selection (one standard place in in vreg.py):