[hooks] port to cubicweb 3.19
authorJulien Cristau <julien.cristau@logilab.fr>
Fri, 25 Jul 2014 11:06:29 +0200
changeset 1565 7401cf73d1cc
parent 1561 ea7b1e630c1b
child 1566 ffcd83fb3766
[hooks] port to cubicweb 3.19 Also, stop translating validation error message here, it's handled by the web side of things.
__pkginfo__.py
debian/control
hooks.py
--- a/__pkginfo__.py	Thu Jul 24 14:39:57 2014 +0200
+++ b/__pkginfo__.py	Fri Jul 25 11:06:29 2014 +0200
@@ -19,7 +19,7 @@
     'Programming Language :: JavaScript',
     ]
 
-__depends__ = {'cubicweb': '>= 3.18.0',
+__depends__ = {'cubicweb': '>= 3.19.0',
                'cubicweb-vcsfile': '>= 1.12',
                'cubicweb-file': None,
                'cubicweb-narval': '>= 4.1',
--- a/debian/control	Thu Jul 24 14:39:57 2014 +0200
+++ b/debian/control	Fri Jul 25 11:06:29 2014 +0200
@@ -12,7 +12,7 @@
 Package: cubicweb-apycot
 Architecture: all
 Depends:
- cubicweb-common (>= 3.18),
+ cubicweb-common (>= 3.19),
  cubicweb-vcsfile (>= 1.12),
  cubicweb-file (>= 1.14),
  cubicweb-narval (>= 4.1),
--- a/hooks.py	Thu Jul 24 14:39:57 2014 +0200
+++ b/hooks.py	Fri Jul 25 11:06:29 2014 +0200
@@ -21,8 +21,10 @@
 
 from cubes.vcsfile.entities import _MARKER
 
-def start_period_tests(session, period):
-    rset = session.execute(
+_ = unicode
+
+def start_period_tests(cnx, period):
+    rset = cnx.execute(
         'Any TC,TCN,TCS,S WHERE '
         'TC computed_start_mode %(sm)s, TC in_state S, S name "activated", '
         'TC name TCN, TC start_rev_deps TCS', {'sm': period})
@@ -52,7 +54,7 @@
                     continue
                 # only start test if the config hasn't been executed against
                 # current branch head
-                if session.execute(
+                if cnx.execute(
                     'Any TE WHERE TE using_revision REV, REV eid %(rev)s, '
                     'TE using_config TC, TC eid %(tc)s',
                     {'rev': head.eid, 'tc': tc.eid}):
@@ -80,8 +82,8 @@
                 tc.cw_set(computed_start_mode=tc.config_parent.computed_start_mode)
                 self.update_refinements()
             else:
-                msg = self.session._('Inherited start mode can only be used if the '
-                                     'configuration refines another one')
+                msg = _('Inherited start mode can only be used if the '
+                        'configuration refines another one')
                 raise ValidationError(tc.eid, {'start_mode': msg})
         elif tc.computed_start_mode != tc.start_mode:
             tc.cw_set(computed_start_mode=tc.start_mode)
@@ -90,7 +92,7 @@
     def update_refinements(self):
         for refined in self.tc.reverse_refinement_of:
             if refined.start_mode == u'inherited':
-                ComputeStartModeOp(self.session, tc=refined)
+                ComputeStartModeOp(self.cnx, tc=refined)
 
 
 # automatic test launching #####################################################
@@ -108,20 +110,17 @@
         def check_test_to_start(repo, datetime=datetime,
                                 start_period_tests=start_period_tests):
             now = datetime.now()
-            session = repo.internal_session()
-            try:
+            with repo.internal_cnx() as cnx:
                 # XXX only start task for environment which have changed in the
                 # given interval
-                start_period_tests(session, 'hourly')
+                start_period_tests(cnx, 'hourly')
                 if now.hour == 1:
-                    start_period_tests(session, 'daily')
+                    start_period_tests(cnx, 'daily')
                 if now.isoweekday() == 1:
-                    start_period_tests(session, 'weekly')
+                    start_period_tests(cnx, 'weekly')
                 if now.day == 1:
-                    start_period_tests(session, 'monthly')
-                session.commit()
-            finally:
-                session.close()
+                    start_period_tests(cnx, 'monthly')
+                cnx.commit()
         self.repo.looping_task(60*60, check_test_to_start, self.repo)
 
 
@@ -134,7 +133,7 @@
                     if pe.vcs_path:
                         # start test only if the revision is modifying file under
                         # specified directory.
-                        if not self.session.execute(
+                        if not self.cnx.execute(
                             'Any R LIMIT 1 WHERE R eid %(r)s, VC from_revision R,'
                             'VC content_for VF, VF directory ~= %(path)s',
                             {'r': revision.eid, 'path': pe.vcs_path + '%'}):
@@ -156,7 +155,7 @@
             # object, use it to create the link later when the changeset is
             # imported.
             done = set(x.eid for x in revision.reverse_using_revision) 
-            for cri in self.session.execute(
+            for cri in self.cnx.execute(
                 'Any CRI, X WHERE CRI for_check X, CRI type "revision", '
                 'CRI label ~= %(repo)s, CRI value %(cs)s',
                 {'cs': revision.changeset,