backport stable branch
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 08 Dec 2009 08:46:15 +0100
changeset 4012 f6c65e04704c
parent 4011 394f853bb653 (current diff)
parent 4002 4edff8bce44b (diff)
child 4013 f0d1038e5059
backport stable branch
entities/wfobjs.py
utils.py
--- a/.hgtags	Mon Dec 07 19:14:49 2009 +0100
+++ b/.hgtags	Tue Dec 08 08:46:15 2009 +0100
@@ -92,3 +92,5 @@
 7a96c0544c138a0c5f452e5b2428ce6e2b7cb378 cubicweb-debian-version-3.5.7-1
 1677312fd8a3e8c0a5ae083e3104ca62b7c9a5bb cubicweb-version-3.5.9
 d7f2d32340fb59753548ef29cbc1958ef3a55fc6 cubicweb-debian-version-3.5.9-1
+9b52725d8c534ba40877457b413077a10173bf88 cubicweb-version-3.5.10
+dfe2f245248c97bea3a29c8ecc6d293e25ff708e cubicweb-debian-version-3.5.10-1
--- a/cwconfig.py	Mon Dec 07 19:14:49 2009 +0100
+++ b/cwconfig.py	Tue Dec 08 08:46:15 2009 +0100
@@ -331,6 +331,10 @@
     def available_cubes(cls):
         cubes = set()
         for directory in cls.cubes_search_path():
+            if not os.path.exists(directory):
+                self.error('unexistant directory in cubes search path: %s'
+                           % directory)
+                continue
             for cube in os.listdir(directory):
                 if isdir(join(directory, cube)) and not cube == 'shared':
                     cubes.add(cube)
--- a/entities/wfobjs.py	Mon Dec 07 19:14:49 2009 +0100
+++ b/entities/wfobjs.py	Tue Dec 08 08:46:15 2009 +0100
@@ -152,6 +152,20 @@
             tr.add_exit_point(fromstate, tostate)
         return tr
 
+    def replace_state(self, todelstate, replacement):
+        """migration convenience method"""
+        if not hasattr(todelstate, 'eid'):
+            todelstate = self.state_by_name(todelstate)
+        if not hasattr(replacement, 'eid'):
+            replacement = self.state_by_name(replacement)
+        execute = self._cw.unsafe_execute
+        execute('SET X in_state S WHERE S eid %(s)s', {'s': todelstate.eid}, 's')
+        execute('SET X from_state NS WHERE X to_state OS, OS eid %(os)s, NS eid %(ns)s',
+                {'os': todelstate.eid, 'ns': newstate.eid}, 's')
+        execute('SET X to_state NS WHERE X to_state OS, OS eid %(os)s, NS eid %(ns)s',
+                {'os': todelstate.eid, 'ns': newstate.eid}, 's')
+        todelstate.delete()
+
 
 class BaseTransition(AnyEntity):
     """customized class for abstract transition
--- a/utils.py	Mon Dec 07 19:14:49 2009 +0100
+++ b/utils.py	Tue Dec 08 08:46:15 2009 +0100
@@ -411,7 +411,7 @@
             elif isinstance(obj, pydatetime.time):
                 return obj.strftime('%H:%M:%S')
             elif isinstance(obj, pydatetime.timedelta):
-                return '%10d.%s' % (obj.days, obj.seconds)
+                return (obj.days * 24 * 60 * 60) + obj.seconds
             elif isinstance(obj, decimal.Decimal):
                 return float(obj)
             try: