merge stable heads stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 12 Jul 2010 12:28:19 +0200
branchstable
changeset 5958 9bfa823735e0
parent 5957 b30946d1afa1 (current diff)
parent 5954 987086484876 (diff)
child 5959 1ce09206a3a3
child 5975 5120d97e2f7e
merge stable heads
--- a/devtools/testlib.py	Mon Jul 12 12:30:36 2010 +0200
+++ b/devtools/testlib.py	Mon Jul 12 12:28:19 2010 +0200
@@ -518,7 +518,7 @@
 
     def ctrl_publish(self, req, ctrl='edit'):
         """call the publish method of the edit controller"""
-        ctrl = self.vreg['controllers'].select(ctrl, req)
+        ctrl = self.vreg['controllers'].select(ctrl, req, appli=self.app)
         try:
             result = ctrl.publish()
             req.cnx.commit()
--- a/server/checkintegrity.py	Mon Jul 12 12:30:36 2010 +0200
+++ b/server/checkintegrity.py	Mon Jul 12 12:28:19 2010 +0200
@@ -94,11 +94,15 @@
     # to be updated due to the reindexation
     repo = session.repo
     cursor = session.pool['system']
-    if not repo.system_source.dbhelper.has_fti_table(cursor):
+    dbhelper = session.repo.system_source.dbhelper
+    if not dbhelper.has_fti_table(cursor):
         print 'no text index table'
-        repo.system_source.dbhelper.init_fti(cursor)
+        dbhelper.init_fti(cursor)
     repo.system_source.do_fti = True  # ensure full-text indexation is activated
+    if withpb:
+        pb = ProgressBar(len(etypes) + 1)
     if etypes is None:
+        print 'Reindexing entities'
         etypes = set()
         for eschema in schema.entities():
             if eschema.final:
@@ -108,13 +112,16 @@
                 continue
             for container in etype_fti_containers(eschema):
                 etypes.add(container)
-    print 'Reindexing entities of type %s' % \
-          ', '.join(sorted(str(e) for e in etypes))
-    if withpb:
-        pb = ProgressBar(len(etypes) + 1)
-    # first monkey patch Entity.check to disable validation
-    # clear fti table first
-    session.system_sql('DELETE FROM %s' % session.repo.system_source.dbhelper.fti_table)
+        # clear fti table first
+        session.system_sql('DELETE FROM %s' % dbhelper.fti_table)
+    else:
+        print 'Reindexing entities of type %s' % \
+              ', '.join(sorted(str(e) for e in etypes))
+        # clear fti table first. Use subquery for sql compatibility
+        session.system_sql("DELETE FROM %s WHERE EXISTS(SELECT 1 FROM ENTITIES "
+                           "WHERE eid=%s AND type IN (%s))" % (
+                               dbhelper.fti_table, dbhelper.fti_uid_attr,
+                               ','.join("'%s'" % etype for etype in etypes)))
     if withpb:
         pb.update()
     # reindex entities by generating rql queries which set all indexable
--- a/server/test/unittest_checkintegrity.py	Mon Jul 12 12:30:36 2010 +0200
+++ b/server/test/unittest_checkintegrity.py	Mon Jul 12 12:28:19 2010 +0200
@@ -15,28 +15,47 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""
 
-"""
 import sys
 from StringIO import StringIO
 from logilab.common.testlib import TestCase, unittest_main
 from cubicweb.devtools import init_test_database
 
 
-from cubicweb.server.checkintegrity import check
+from cubicweb.server.checkintegrity import check, reindex_entities
 
 class CheckIntegrityTC(TestCase):
-    def test(self):
-        repo, cnx = init_test_database()
+    def setUp(self):
+        self.repo, self.cnx = init_test_database()
+        self.execute = self.cnx.cursor().execute
+        self.session = self.repo._sessions[self.cnx.sessionid]
         sys.stderr = sys.stdout = StringIO()
-        try:
-            check(repo, cnx, ('entities', 'relations', 'text_index', 'metadata'),
-                  reindex=True, fix=True, withpb=False)
-        finally:
-            sys.stderr = sys.__stderr__
-            sys.stdout = sys.__stdout__
-        repo.shutdown()
+
+    def tearDown(self):
+        sys.stderr = sys.__stderr__
+        sys.stdout = sys.__stdout__
+        self.cnx.close()
+        self.repo.shutdown()
+
+    def test_checks(self):
+        check(self.repo, self.cnx, ('entities', 'relations', 'text_index', 'metadata'),
+              reindex=False, fix=True, withpb=False)
+
+    def test_reindex_all(self):
+        self.execute('INSERT Personne X: X nom "toto", X prenom "tutu"')
+        self.session.commit(False)
+        self.failUnless(self.execute('Any X WHERE X has_text "tutu"'))
+        reindex_entities(self.repo.schema, self.session, withpb=False)
+        self.failUnless(self.execute('Any X WHERE X has_text "tutu"'))
+
+    def test_reindex_etype(self):
+        self.execute('INSERT Personne X: X nom "toto", X prenom "tutu"')
+        self.execute('INSERT Affaire X: X ref "toto"')
+        self.session.commit(False)
+        reindex_entities(self.repo.schema, self.session, withpb=False,
+                         etypes=('Personne',))
+        self.failUnless(self.execute('Any X WHERE X has_text "tutu"'))
+        self.failUnless(self.execute('Any X WHERE X has_text "toto"'))
 
 if __name__ == '__main__':
     unittest_main()
--- a/skeleton/setup.py	Mon Jul 12 12:30:36 2010 +0200
+++ b/skeleton/setup.py	Mon Jul 12 12:28:19 2010 +0200
@@ -142,12 +142,9 @@
     # install-layout option was introduced in 2.5.3-1~exp1
     elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv:
         sys.argv.remove('--install-layout=deb')
-    kwargs['package_dir'] = {modname : '.'}
-    packages = [modname] + get_packages(os.getcwd(), modname)
     if USE_SETUPTOOLS and install_requires:
         kwargs['install_requires'] = install_requires
         kwargs['dependency_links'] = dependency_links
-    kwargs['packages'] = packages
     return setup(name = distname,
                  version = version,
                  license = license,