[cleanup] style fixes, add nodes, 0.2 cents refactorings stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 30 Mar 2010 11:15:08 +0200
branchstable
changeset 5072 072ae171aeb0
parent 5071 8631bb9f6e73
child 5073 a9697325cffa
[cleanup] style fixes, add nodes, 0.2 cents refactorings
rset.py
server/hook.py
server/querier.py
server/repository.py
server/sources/native.py
--- a/rset.py	Tue Mar 30 11:06:13 2010 +0200
+++ b/rset.py	Tue Mar 30 11:15:08 2010 +0200
@@ -113,7 +113,7 @@
         # but I tend to think that since we have that, we should not need this
         # method anymore (syt)
         rset = ResultSet(self.rows+rset.rows, self.rql, self.args,
-                         self.description +rset.description)
+                         self.description + rset.description)
         rset.req = self.req
         return rset
 
--- a/server/hook.py	Tue Mar 30 11:06:13 2010 +0200
+++ b/server/hook.py	Tue Mar 30 11:15:08 2010 +0200
@@ -464,7 +464,6 @@
     try:
         session.transaction_data[datakey].add(value)
     except KeyError:
-        print 'init', datakey
         opcls(session, *opkwargs)
         session.transaction_data[datakey] = set((value,))
 
--- a/server/querier.py	Tue Mar 30 11:06:13 2010 +0200
+++ b/server/querier.py	Tue Mar 30 11:15:08 2010 +0200
@@ -620,7 +620,7 @@
                 return empty_rset(rql, args, rqlst)
             self._rql_cache[cachekey] = rqlst
         orig_rqlst = rqlst
-        if not rqlst.TYPE == 'select':
+        if rqlst.TYPE != 'select':
             if session.read_security:
                 check_no_password_selected(rqlst)
             # write query, ensure session's mode is 'write' so connections won't
--- a/server/repository.py	Tue Mar 30 11:06:13 2010 +0200
+++ b/server/repository.py	Tue Mar 30 11:15:08 2010 +0200
@@ -504,7 +504,7 @@
                 qname = role_name('login', 'subject')
                 raise ValidationError(None, {qname: errmsg % login})
             # we have to create the user
-            user = self.vreg['etypes'].etype_class('CWUser')(session, None)
+            user = self.vreg['etypes'].etype_class('CWUser')(session)
             if isinstance(password, unicode):
                 # password should *always* be utf8 encoded
                 password = password.encode('UTF8')
@@ -934,10 +934,9 @@
                 if role == 'subject':
                     # don't skip inlined relation so they are regularly
                     # deleted and so hooks are correctly called
-                    selection = 'X %s Y' % rtype
+                    rql = 'DELETE X %s Y WHERE X eid %%(x)s' % rtype
                 else:
-                    selection = 'Y %s X' % rtype
-                rql = 'DELETE %s WHERE X eid %%(x)s' % selection
+                    rql = 'DELETE Y %s X WHERE X eid %%(x)s' % rtype
                 session.execute(rql, {'x': eid}, 'x', build_descr=False)
         self.system_source.delete_info(session, entity, sourceuri, extid)
 
@@ -997,19 +996,19 @@
             entity.__class__ = entity_.__class__
             entity.__dict__.update(entity_.__dict__)
         eschema = entity.e_schema
-        etype = str(eschema)
-        source = self.locate_etype_source(etype)
-        # attribute an eid to the entity before calling hooks
+        source = self.locate_etype_source(entity.__regid__)
+        # allocate an eid to the entity before calling hooks
         entity.set_eid(self.system_source.create_eid(session))
         # set caches asap
         extid = self.init_entity_caches(session, entity, source)
         if server.DEBUG & server.DBG_REPO:
-            print 'ADD entity', etype, entity.eid, dict(entity)
+            print 'ADD entity', entity.__regid__, entity.eid, dict(entity)
         relations = []
         if source.should_call_hooks:
             self.hm.call_hooks('before_add_entity', session, entity=entity)
         # XXX use entity.keys here since edited_attributes is not updated for
-        # inline relations
+        # inline relations XXX not true, right? (see edited_attributes
+        # affectation above)
         for attr in entity.iterkeys():
             rschema = eschema.subjrels[attr]
             if not rschema.final: # inlined relation
@@ -1052,9 +1051,8 @@
         """replace an entity in the repository
         the type and the eid of an entity must not be changed
         """
-        etype = str(entity.e_schema)
         if server.DEBUG & server.DBG_REPO:
-            print 'UPDATE entity', etype, entity.eid, \
+            print 'UPDATE entity', entity.__regid__, entity.eid, \
                   dict(entity), edited_attributes
         entity.edited_attributes = edited_attributes
         if session.is_hook_category_activated('integrity'):
--- a/server/sources/native.py	Tue Mar 30 11:06:13 2010 +0200
+++ b/server/sources/native.py	Tue Mar 30 11:15:08 2010 +0200
@@ -485,6 +485,13 @@
             sql = self.sqlgen.delete(SQL_PREFIX + entity.__regid__, attrs)
             self.doexec(session, sql, attrs)
 
+    def add_relation(self, session, subject, rtype, object, inlined=False):
+        """add a relation to the source"""
+        self._add_relation(session, subject, rtype, object, inlined)
+        if session.undoable_action('A', rtype):
+            self._record_tx_action(session, 'tx_relation_actions', 'A',
+                                   eid_from=subject, rtype=rtype, eid_to=object)
+
     def _add_relation(self, session, subject, rtype, object, inlined=False):
         """add a relation to the source"""
         if inlined is False:
@@ -497,13 +504,6 @@
                                      ['cw_eid'])
         self.doexec(session, sql, attrs)
 
-    def add_relation(self, session, subject, rtype, object, inlined=False):
-        """add a relation to the source"""
-        self._add_relation(session, subject, rtype, object, inlined)
-        if session.undoable_action('A', rtype):
-            self._record_tx_action(session, 'tx_relation_actions', 'A',
-                                   eid_from=subject, rtype=rtype, eid_to=object)
-
     def delete_relation(self, session, subject, rtype, object):
         """delete a relation from the source"""
         rschema = self.schema.rschema(rtype)
@@ -698,7 +698,7 @@
         for etype in etypes:
             if not etype in self.multisources_etypes:
                 self.critical('%s not listed as a multi-sources entity types. '
-                              'Modify your configuration')
+                              'Modify your configuration' % etype)
                 self.multisources_etypes.add(etype)
         modsql = _modified_sql('entities', etypes)
         cursor = self.doexec(session, modsql, {'time': mtime})
@@ -792,6 +792,7 @@
         restr = {'tx_uuid': txuuid}
         if public:
             restr['txa_public'] = True
+        # XXX use generator to avoid loading everything in memory?
         sql = self.sqlgen.select('tx_entity_actions', restr,
                                  ('txa_action', 'txa_public', 'txa_order',
                                   'etype', 'eid', 'changes'))
@@ -911,30 +912,6 @@
                     % {'rtype': rtype, 'eid': eid})
             if not rschema.final:
                 assert value is None
-                    # try:
-                    #     tentity = session.entity_from_eid(eid)
-                    # except UnknownEid:
-                    #     err(_("Can't restore %(role)s relation %(rtype)s to "
-                    #           "entity %(eid)s which doesn't exist anymore.")
-                    #         % {'role': _('subject'),
-                    #            'rtype': _(rtype),
-                    #            'eid': eid})
-                    #     continue
-                    # rdef = rdefs[(eschema, tentity.__regid__)]
-                    # try:
-                    #     _undo_check_relation_target(tentity, rdef, 'object')
-                    # except UndoException, ex:
-                    #     err(unicode(ex))
-                    #     continue
-                    # if rschema.inlined:
-                    #     entity[rtype] = value
-                    # else:
-                    #     # restore relation where inlined changed since the deletion
-                    #     del action.changes[column]
-                    #     self._add_relation(session, subject, rtype, object)
-                    # # set related cache
-                    # session.update_rel_cache_add(eid, rtype, value,
-                    #                              rschema.symmetric)
             elif eschema.destination(rtype) in ('Bytes', 'Password'):
                 action.changes[column] = self._binary(value)
                 entity[rtype] = Binary(value)