[doc] Integration of card http://intranet.logilab.fr/intra/card/eid/3355 to the book.
authorSandrine Ribeau <sandrine.ribeau@logilab.fr>
Mon, 05 Jan 2009 10:40:22 -0800
changeset 335 643db91242b1
parent 329 903eb8c4ebd6
child 336 abb7ea9bed71
[doc] Integration of card http://intranet.logilab.fr/intra/card/eid/3355 to the book.
doc/book/en/C040-rql.en.txt
doc/book/en/D010-faq.en.txt
--- a/doc/book/en/C040-rql.en.txt	Mon Jan 05 17:05:38 2009 +0100
+++ b/doc/book/en/C040-rql.en.txt	Mon Jan 05 10:40:22 2009 -0800
@@ -533,6 +533,17 @@
 
    is not.
 
+RQL logs
+--------
+
+You can configure the `CubicWeb` application so that you keep a log
+of the queries executed against your database. To do so, you want to
+edit the configuration file of your application 
+``.../etc/cubicweb.d/myapp/all-in-one.conf`` and uncomment the
+variable ``query-log-file``: ::
+
+  # web application query log file
+  query-log-file=/tmp/rql-myapp.log
 
 
 Conclusion
--- a/doc/book/en/D010-faq.en.txt	Mon Jan 05 17:05:38 2009 +0100
+++ b/doc/book/en/D010-faq.en.txt	Mon Jan 05 10:40:22 2009 -0800
@@ -134,5 +134,59 @@
 
      where DATADIR is ``mycubes/data``.
 
+* How to import LDAP users in `CubicWeb`?
+
+  Here is a very usefull script which enables you to import LDAP users
+  into your `CubicWeb` application by runing the following: ::
+  
+
+    import os
+    import pwd
+    import sys
+
+    from logilab.common.db import get_connection
+
+    def getlogin():
+        """avoid usinng os.getlogin() because of strange tty / stdin problems
+        (man 3 getlogin)
+        Another solution would be to use $LOGNAME, $USER or $USERNAME
+        """
+        return pwd.getpwuid(os.getuid())[0]
+
+
+    try:
+        database = sys.argv[1]
+    except IndexError:
+        print 'USAGE: python ldap2system.py <database>'
+        sys.exit(1)
+
+    if raw_input('update %s db ? [y/n]: ' % database).strip().lower().startswith('y'):
+        cnx = get_connection(user=getlogin(), database=database)
+        cursor = cnx.cursor()
+
+        insert = ('INSERT INTO euser (creation_date, eid, modification_date, login, firstname, surname, last_login_time, upassword) '
+                  "VALUES (%(mtime)s, %(eid)s, %(mtime)s, %(login)s, %(firstname)s, %(surname)s, %(mtime)s, './fqEz5LeZnT6');")
+        update = "UPDATE entities SET source='system' WHERE eid=%(eid)s;"
+        cursor.execute("SELECT eid,type,source,extid,mtime FROM entities WHERE source!='system'")
+        for eid, type, source, extid, mtime in cursor.fetchall():
+            if type != 'EUser':
+                print "don't know what to do with entity type", type
+                continue
+            if source != 'ldapuser':
+                print "don't know what to do with source type", source
+                continue
+            ldapinfos = dict(x.strip().split('=') for x in extid.split(','))
+            login = ldapinfos['uid']
+            firstname = ldapinfos['uid'][0].upper()
+            surname = ldapinfos['uid'][1:].capitalize()
+            if login != 'jcuissinat':
+                args = dict(eid=eid, type=type, source=source, login=login,
+                            firstname=firstname, surname=surname, mtime=mtime)
+                print args
+                cursor.execute(insert, args)
+                cursor.execute(update, args)
+
+        cnx.commit()
+        cnx.close()