cleanup stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 27 May 2009 11:26:03 +0200
branchstable
changeset 1954 9b20f3504af8
parent 1953 8834399f076e
child 1955 6539ce84f043
cleanup
__init__.py
misc/migration/bootstrapmigration_repository.py
server/querier.py
server/repository.py
server/sources/ldapuser.py
server/sources/native.py
server/sources/pyrorql.py
server/sqlutils.py
server/test/unittest_repository.py
--- a/__init__.py	Wed May 27 11:24:58 2009 +0200
+++ b/__init__.py	Wed May 27 11:26:03 2009 +0200
@@ -46,7 +46,7 @@
 
 class Binary(StringIO):
     """customize StringIO to make sure we don't use unicode"""
-    def __init__(self, buf= ''):
+    def __init__(self, buf=''):
         assert isinstance(buf, (str, buffer)), \
                "Binary objects must use raw strings, not %s" % buf.__class__
         StringIO.__init__(self, buf)
--- a/misc/migration/bootstrapmigration_repository.py	Wed May 27 11:24:58 2009 +0200
+++ b/misc/migration/bootstrapmigration_repository.py	Wed May 27 11:26:03 2009 +0200
@@ -33,7 +33,7 @@
     add_relation_type('is_instance_of')
     # fill the relation using an efficient sql query instead of using rql
     sql('INSERT INTO is_instance_of_relation '
-	'  SELECT * from is_relation')
+        '  SELECT * from is_relation')
     checkpoint()
     session.set_shared_data('do-not-insert-is_instance_of', False)
 
--- a/server/querier.py	Wed May 27 11:24:58 2009 +0200
+++ b/server/querier.py	Wed May 27 11:26:03 2009 +0200
@@ -599,7 +599,8 @@
                 except KeyError:
                     raise QueryError('bad cache key %s (no value)' % key)
                 except TypeError:
-                    raise QueryError('bad cache key %s (value: %r)' % (key, args[key]))
+                    raise QueryError('bad cache key %s (value: %r)' % (
+                        key, args[key]))
                 except UnknownEid:
                     # we want queries such as "Any X WHERE X eid 9999"
                     # return an empty result instead of raising UnknownEid
--- a/server/repository.py	Wed May 27 11:24:58 2009 +0200
+++ b/server/repository.py	Wed May 27 11:26:03 2009 +0200
@@ -794,10 +794,10 @@
             raise UnknownEid(eid)
         return extid
 
-    def extid2eid(self, source, lid, etype, session=None, insert=True,
+    def extid2eid(self, source, extid, etype, session=None, insert=True,
                   recreate=False):
         """get eid from a local id. An eid is attributed if no record is found"""
-        cachekey = (str(lid), source.uri)
+        cachekey = (extid, source.uri)
         try:
             return self._extid_cache[cachekey]
         except KeyError:
@@ -806,17 +806,17 @@
         if session is None:
             session = self.internal_session()
             reset_pool = True
-        eid = self.system_source.extid2eid(session, source, lid)
+        eid = self.system_source.extid2eid(session, source, extid)
         if eid is not None:
             self._extid_cache[cachekey] = eid
-            self._type_source_cache[eid] = (etype, source.uri, lid)
+            self._type_source_cache[eid] = (etype, source.uri, extid)
             if recreate:
-                entity = source.before_entity_insertion(session, lid, etype, eid)
+                entity = source.before_entity_insertion(session, extid, etype, eid)
                 entity._cw_recreating = True
                 if source.should_call_hooks:
                     self.hm.call_hooks('before_add_entity', etype, session, entity)
                 # XXX add fti op ?
-                source.after_entity_insertion(session, lid, entity)
+                source.after_entity_insertion(session, extid, entity)
                 if source.should_call_hooks:
                     self.hm.call_hooks('after_add_entity', etype, session, entity)
             if reset_pool:
@@ -824,7 +824,7 @@
             return eid
         if not insert:
             return
-        # no link between lid and eid, create one using an internal session
+        # no link between extid and eid, create one using an internal session
         # since the current session user may not have required permissions to
         # do necessary stuff and we don't want to commit user session.
         #
@@ -836,13 +836,13 @@
         try:
             eid = self.system_source.create_eid(session)
             self._extid_cache[cachekey] = eid
-            self._type_source_cache[eid] = (etype, source.uri, lid)
-            entity = source.before_entity_insertion(session, lid, etype, eid)
+            self._type_source_cache[eid] = (etype, source.uri, extid)
+            entity = source.before_entity_insertion(session, extid, etype, eid)
             if source.should_call_hooks:
                 self.hm.call_hooks('before_add_entity', etype, session, entity)
             # XXX call add_info with complete=False ?
-            self.add_info(session, entity, source, lid)
-            source.after_entity_insertion(session, lid, entity)
+            self.add_info(session, entity, source, extid)
+            source.after_entity_insertion(session, extid, entity)
             if source.should_call_hooks:
                 self.hm.call_hooks('after_add_entity', etype, session, entity)
             else:
--- a/server/sources/ldapuser.py	Wed May 27 11:24:58 2009 +0200
+++ b/server/sources/ldapuser.py	Wed May 27 11:26:03 2009 +0200
@@ -153,7 +153,8 @@
     def init(self):
         """method called by the repository once ready to handle request"""
         self.repo.looping_task(self._interval, self.synchronize)
-        self.repo.looping_task(self._query_cache.ttl.seconds/10, self._query_cache.clear_expired)
+        self.repo.looping_task(self._query_cache.ttl.seconds/10,
+                               self._query_cache.clear_expired)
 
     def synchronize(self):
         """synchronize content known by this repository with content in the
--- a/server/sources/native.py	Wed May 27 11:24:58 2009 +0200
+++ b/server/sources/native.py	Wed May 27 11:26:03 2009 +0200
@@ -241,7 +241,7 @@
                 pwd = rset[0][0]
             except IndexError:
                 raise AuthenticationError('bad login')
-            # passwords are stored using the bytea type, so we get a StringIO
+            # passwords are stored using the Bytes type, so we get a StringIO
             if pwd is not None:
                 args['pwd'] = crypt_password(password, pwd.getvalue()[:2])
         # get eid from login and (crypted) password
@@ -481,8 +481,7 @@
         try:
             result = cursor.fetchone()
             if result:
-                eid = result[0]
-                return eid
+                return result[0]
         except:
             pass
         return None
--- a/server/sources/pyrorql.py	Wed May 27 11:24:58 2009 +0200
+++ b/server/sources/pyrorql.py	Wed May 27 11:26:03 2009 +0200
@@ -8,7 +8,6 @@
 
 import threading
 from os.path import join
-
 from time import mktime
 from datetime import datetime
 from base64 import b64decode
@@ -570,17 +569,15 @@
         except UnknownEid:
             operator = self.current_operator
             if operator is not None and operator != '=':
-                # deal with query like X eid > 12
+                # deal with query like "X eid > 12"
                 #
-                # The problem is
-                # that eid order in the external source may differ from the
-                # local source
+                # The problem is that eid order in the external source may
+                # differ from the local source
                 #
-                # So search for all eids from this
-                # source matching the condition locally and then to replace the
-                # > 12 branch by IN (eids) (XXX we may have to insert a huge
-                # number of eids...)
-                # planner so that
+                # So search for all eids from this source matching the condition
+                # locally and then to replace the "> 12" branch by "IN (eids)"
+                #
+                # XXX we may have to insert a huge number of eids...)
                 sql = "SELECT extid FROM entities WHERE source='%s' AND type IN (%s) AND eid%s%s"
                 etypes = ','.join("'%s'" % etype for etype in self.current_etypes)
                 cu = self._session.system_sql(sql % (self.source.uri, etypes,
--- a/server/sqlutils.py	Wed May 27 11:24:58 2009 +0200
+++ b/server/sqlutils.py	Wed May 27 11:26:03 2009 +0200
@@ -111,7 +111,8 @@
         w(indexer.sql_drop_fti())
         w('')
     w(dropschema2sql(schema, prefix=SQL_PREFIX,
-                     skip_entities=skip_entities, skip_relations=skip_relations))
+                     skip_entities=skip_entities,
+                     skip_relations=skip_relations))
     return '\n'.join(output)
 
 try:
--- a/server/test/unittest_repository.py	Wed May 27 11:24:58 2009 +0200
+++ b/server/test/unittest_repository.py	Wed May 27 11:26:03 2009 +0200
@@ -211,11 +211,8 @@
         t = threading.Thread(target=close_in_a_few_moment)
         t.start()
         try:
-            print 'execute'
             repo.execute(cnxid, 'DELETE CWUser X WHERE X login "toto"')
-            print 'commit'
             repo.commit(cnxid)
-            print 'commited'
         finally:
             t.join()
 
@@ -286,7 +283,8 @@
         repo = self.repo
         cnxid = repo.connect(*self.default_user_password())
         session = repo._get_session(cnxid, setpool=True)
-        self.assertEquals(repo.type_and_source_from_eid(1, session), ('CWGroup', 'system', None))
+        self.assertEquals(repo.type_and_source_from_eid(1, session),
+                          ('CWGroup', 'system', None))
         self.assertEquals(repo.type_from_eid(1, session), 'CWGroup')
         self.assertEquals(repo.source_from_eid(1, session).uri, 'system')
         self.assertEquals(repo.eid2extid(repo.system_source, 1, session), None)