merge stable
authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
Tue, 23 Feb 2010 10:57:51 +0100
branchstable
changeset 4655 573a6451b424
parent 4654 717310b3d576 (current diff)
parent 4653 ca11228a5268 (diff)
child 4656 027bbff3659f
merge
--- a/devtools/fill.py	Tue Feb 23 08:54:04 2010 +0100
+++ b/devtools/fill.py	Tue Feb 23 10:57:51 2010 +0100
@@ -142,7 +142,7 @@
 
     def generate_date(self, entity, attrname, index):
         """generates a random date (format is 'yyyy-mm-dd')"""
-        base = date(randint(2000, 2004), randint(1, 12), randint(1, 28))
+        base = date(randint(2000, 2010), 1, 1) + timedelta(randint(1, 365))
         return self._constrained_generate(entity, attrname, base, timedelta(days=1), index)
 
     def generate_time(self, entity, attrname, index):
--- a/devtools/test/unittest_dbfill.py	Tue Feb 23 08:54:04 2010 +0100
+++ b/devtools/test/unittest_dbfill.py	Tue Feb 23 10:57:51 2010 +0100
@@ -9,6 +9,7 @@
 
 import os.path as osp
 import re
+import datetime
 
 from logilab.common.testlib import TestCase, unittest_main
 
@@ -41,7 +42,6 @@
     def _available_Person_firstname(self, etype, attrname):
         return [f.strip() for f in file(osp.join(DATADIR, 'firstnames.txt'))]
 
-
     def setUp(self):
         config = ApptestConfiguration('data')
         config.bootstrap_cubes()
@@ -52,17 +52,6 @@
         self.bug_valgen = MyValueGenerator(e_schema)
         self.config = config
 
-    def _check_date(self, date):
-        """checks that 'date' is well-formed"""
-        year = date.year
-        month = date.month
-        day = date.day
-        self.failUnless(day in range(1, 29), '%s not in [0;28]' % day)
-        self.failUnless(month in range(1, 13), '%s not in [1;12]' % month)
-        self.failUnless(year in range(2000, 2005),
-                        '%s not in [2000;2004]' % year)
-
-
     def test_string(self):
         """test string generation"""
         surname = self.person_valgen.generate_attribute_value({}, 'surname', 12)
@@ -92,15 +81,14 @@
     def test_date(self):
         """test date generation"""
         # Test for random index
-        for index in range(5):
+        for index in range(10):
             date_value = self.person_valgen.generate_attribute_value({}, 'birthday', index)
-            self._check_date(date_value)
+            self.failUnless(isinstance(date_value, datetime.date))
 
     def test_phone(self):
         """tests make_tel utility"""
         self.assertEquals(make_tel(22030405), '22 03 04 05')
 
-
     def test_customized_generation(self):
         self.assertEquals(self.bug_valgen.generate_attribute_value({}, 'severity', 12),
                           u'dangerous')
@@ -110,7 +98,6 @@
                           u'yo')
 
 
-
 class ConstraintInsertionTC(TestCase):
 
     def test_writeme(self):
--- a/server/migractions.py	Tue Feb 23 08:54:04 2010 +0100
+++ b/server/migractions.py	Tue Feb 23 10:57:51 2010 +0100
@@ -352,7 +352,7 @@
                                             'T eid %%(x)s' % perm, {'x': teid}, 'x',
                                             ask_confirm=False):
                 if not gname in newgroups:
-                    if not confirm or self.confirm('remove %s permission of %s to %s?'
+                    if not confirm or self.confirm('Remove %s permission of %s to %s?'
                                                    % (action, erschema, gname)):
                         self.rqlexec('DELETE T %s G WHERE G eid %%(x)s, T eid %s'
                                      % (perm, teid),
@@ -360,7 +360,7 @@
                 else:
                     newgroups.remove(gname)
             for gname in newgroups:
-                if not confirm or self.confirm('grant %s permission of %s to %s?'
+                if not confirm or self.confirm('Grant %s permission of %s to %s?'
                                                % (action, erschema, gname)):
                     self.rqlexec('SET T %s G WHERE G eid %%(x)s, T eid %s'
                                  % (perm, teid),
@@ -371,7 +371,7 @@
                                                     'T eid %s' % (perm, teid),
                                                     ask_confirm=False):
                 if not expression in newexprs:
-                    if not confirm or self.confirm('remove %s expression for %s permission of %s?'
+                    if not confirm or self.confirm('Remove %s expression for %s permission of %s?'
                                                    % (expression, action, erschema)):
                         # deleting the relation will delete the expression entity
                         self.rqlexec('DELETE T %s E WHERE E eid %%(x)s, T eid %s'
@@ -381,7 +381,7 @@
                     newexprs.pop(expression)
             for expression in newexprs.values():
                 expr = expression.expression
-                if not confirm or self.confirm('add %s expression for %s permission of %s?'
+                if not confirm or self.confirm('Add %s expression for %s permission of %s?'
                                                % (expr, action, erschema)):
                     self.rqlexec('INSERT RQLExpression X: X exprtype %%(exprtype)s, '
                                  'X expression %%(expr)s, X mainvars %%(vars)s, T %s X '
@@ -528,7 +528,7 @@
 
     def checkpoint(self, ask_confirm=True):
         """checkpoint action"""
-        if not ask_confirm or self.confirm('commit now ?', shell=False):
+        if not ask_confirm or self.confirm('Commit now ?', shell=False):
             self.commit()
 
     def cmd_add_cube(self, cube, update_database=True):
@@ -1146,13 +1146,13 @@
         should only be used for low level stuff undoable with existing higher
         level actions
         """
-        if not ask_confirm or self.confirm('execute sql: %s ?' % sql):
+        if not ask_confirm or self.confirm('Execute sql: %s ?' % sql):
             self.session.set_pool() # ensure pool is set
             try:
                 cu = self.session.system_sql(sql, args)
             except:
                 ex = sys.exc_info()[1]
-                if self.confirm('error: %s\nabort?' % ex):
+                if self.confirm('Error: %s\nabort?' % ex):
                     raise
                 return
             try:
@@ -1175,11 +1175,11 @@
                 msg = '%s (%s)' % (rql, kwargs)
             else:
                 msg = rql
-            if not ask_confirm or self.confirm('execute rql: %s ?' % msg):
+            if not ask_confirm or self.confirm('Execute rql: %s ?' % msg):
                 try:
                     res = execute(rql, kwargs, cachekey)
                 except Exception, ex:
-                    if self.confirm('error: %s\nabort?' % ex):
+                    if self.confirm('Error: %s\nabort?' % ex):
                         raise
         return res
 
@@ -1264,12 +1264,12 @@
         else:
             msg = rql
         if self.ask_confirm:
-            if not self._h.confirm('execute rql: %s ?' % msg):
+            if not self._h.confirm('Execute rql: %s ?' % msg):
                 raise StopIteration
         try:
             rset = self._h._cw.execute(rql, kwargs)
         except Exception, ex:
-            if self._h.confirm('error: %s\nabort?' % ex):
+            if self._h.confirm('Error: %s\nabort?' % ex):
                 raise
             else:
                 raise StopIteration
--- a/utils.py	Tue Feb 23 08:54:04 2010 +0100
+++ b/utils.py	Tue Feb 23 10:57:51 2010 +0100
@@ -7,27 +7,33 @@
 """
 __docformat__ = "restructuredtext en"
 
-from logilab.mtconverter import xml_escape
-
-import locale
 import sys
 import decimal
 import datetime
-from md5 import md5
-from time import time
-from random import randint, seed
+import random
+
+from logilab.mtconverter import xml_escape
+from logilab.common.deprecation import deprecated
 
 # initialize random seed from current time
-seed()
+random.seed()
 
 if sys.version_info[:2] < (2, 5):
+
+    from time import time
+    from md5 import md5
+    from random import randint
+
     def make_uid(key):
         """forge a unique identifier
         not that unique on win32"""
         msg = str(key) + "%.10f" % time() + str(randint(0, 1000000))
         return md5(msg).hexdigest()
+
 else:
+
     from uuid import uuid4
+
     def make_uid(key):
         # remove dash, generated uid are used as identifier sometimes (sql table
         # names at least)
@@ -328,3 +334,12 @@
                 # we never ever want to fail because of an unknown type,
                 # just return None in those cases.
                 return None
+
+from logilab.common import date
+_THIS_MOD_NS = globals()
+for funcname in ('date_range', 'todate', 'todatetime', 'datetime2ticks',
+                 'days_in_month', 'days_in_year', 'previous_month',
+                 'next_month', 'first_day', 'last_day', 'ustrftime',
+                 'strptime'):
+    msg = '[3.6] %s has been moved to logilab.common.date' % funcname
+    _THIS_MOD_NS[funcname] = deprecated(msg)(getattr(date, funcname))