[REF] get rid of the mx.Datetime C dependency, meaning better portability, especially...
authorCristian Salamea (GnuThink) <>
Sun, 13 Dec 2009 18:16:01 +0000 (16:16 -0200)
committerRaphaël Valyi <rvalyi@gmail.com>
Sun, 13 Dec 2009 18:16:01 +0000 (16:16 -0200)
bzr revid: rvalyi@gmail.com-20091213181601-4k4mhtgnv2qynrjo

bin/addons/base/ir/ir_cron.py
bin/addons/base/res/res_currency.py
bin/openerp-server.py
bin/report/printscreen/ps_list.py
bin/report/report_sxw.py
bin/tools/convert.py
bin/tools/translate.py
setup.py

index 3966a81..c30abbf 100644 (file)
@@ -20,8 +20,9 @@
 #
 ##############################################################################
 
-from mx import DateTime
 import time
+import datetime
+from dateutil.relativedelta import *
 import netsvc
 import tools
 import pooler
@@ -31,12 +32,12 @@ def str2tuple(s):
     return eval('tuple(%s)' % (s or ''))
 
 _intervalTypes = {
-    'work_days': lambda interval: DateTime.RelativeDateTime(days=interval),
-    'days': lambda interval: DateTime.RelativeDateTime(days=interval),
-    'hours': lambda interval: DateTime.RelativeDateTime(hours=interval),
-    'weeks': lambda interval: DateTime.RelativeDateTime(days=7*interval),
-    'months': lambda interval: DateTime.RelativeDateTime(months=interval),
-    'minutes': lambda interval: DateTime.RelativeDateTime(minutes=interval),
+    'work_days': lambda interval: relativedelta(days=interval),
+    'days': lambda interval: relativedelta(days=interval),
+    'hours': lambda interval: relativedelta(hours=interval),
+    'weeks': lambda interval: relativedelta(days=7*interval),
+    'months': lambda interval: relativedelta(months=interval),
+    'minutes': lambda interval: relativedelta(minutes=interval),
 }
 
 class ir_cron(osv.osv, netsvc.Agent):
@@ -100,10 +101,10 @@ class ir_cron(osv.osv, netsvc.Agent):
         cr = db.cursor()
         try:
             if not pool._init:
-                now = DateTime.now()
+                now = datetime.datetime.now()
                 cr.execute('select * from ir_cron where numbercall<>0 and active and nextcall<=now() order by priority')
                 for job in cr.dictfetchall():
-                    nextcall = DateTime.strptime(job['nextcall'], '%Y-%m-%d %H:%M:%S')
+                    nextcall = datetime.datetime.strptime(job['nextcall'], '%Y-%m-%d %H:%M:%S')
                     numbercall = job['numbercall']
                 
                     ok = False
index 0cd80c1..f15566f 100644 (file)
@@ -26,9 +26,6 @@ import ir
 from tools.misc import currency
 from tools.translate import _
 
-import mx.DateTime
-from mx.DateTime import RelativeDateTime, now, DateTime, localtime
-
 class res_currency(osv.osv):
     def _current_rate(self, cr, uid, ids, name, arg, context={}):
         res={}
index 33b5fef..f4f8e1e 100755 (executable)
@@ -79,10 +79,6 @@ for name, value in [('addons_path', tools.config['addons_path']),
 
 import time
 
-if sys.platform == 'win32':
-    import mx.DateTime
-    mx.DateTime.strptime = lambda x, y: mx.DateTime.mktime(time.strptime(x, y))
-
 #----------------------------------------------------------
 # init net service
 #----------------------------------------------------------
index 2d3ee00..1496077 100644 (file)
@@ -29,7 +29,7 @@ import libxslt
 import locale
 
 import time, os
-import mx.DateTime
+import datetime
 
 class report_printscreen_list(report_int):
     def __init__(self, name):
@@ -178,19 +178,19 @@ class report_printscreen_list(report_int):
 
                 if fields[f]['type'] == 'date' and line[f]:
                     format = str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'))
-                    d1= mx.DateTime.strptime(line[f],'%Y-%m-%d')
+                    d1 = datetime.datetime.strptime(line[f],'%y-%m-%d')
                     new_d1 = d1.strftime(format)
                     line[f] = new_d1
                     
                 if fields[f]['type'] == 'time' and line[f]:
                     format = str(locale.nl_langinfo(locale.T_FMT))
-                    d1= mx.DateTime.strptime(line[f],'%H:%M:%S')
+                    d1 = datetime.datetime.strptime(line[f], '%H:%M:%S')
                     new_d1 = d1.strftime(format)
                     line[f] = new_d1
                     
                 if fields[f]['type'] == 'datetime' and line[f]:
                     format = str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'))+' '+str(locale.nl_langinfo(locale.T_FMT))
-                    d1= mx.DateTime.strptime(line[f],'%Y-%m-%d %H:%M:%S')
+                    d1 = datetime.datetime.strptime(line[f], '%Y-%m-%d %H:%M:%S')
                     new_d1 = d1.strftime(format)
                     line[f] = new_d1
                     
index f1df81e..987ec9c 100644 (file)
@@ -25,7 +25,7 @@ import cStringIO
 import base64
 import copy
 import locale
-import mx.DateTime
+import datetime
 import os
 import re
 import time
@@ -109,7 +109,7 @@ class _date_format(str, _format):
     def __str__(self):
         if self.val:
             if hasattr(self,'name') and (self.name):
-                date = mx.DateTime.strptime(self.name,DT_FORMAT)
+                date = datetime.datetime.strptime(self.name, DT_FORMAT)
                 return date.strftime(self.lang_obj.date_format)
         return self.val
 
@@ -121,7 +121,7 @@ class _dttime_format(str, _format):
     def __str__(self):
         if self.val:
             if hasattr(self,'name') and self.name:
-                datetime = mx.DateTime.strptime(self.name,DHM_FORMAT)
+                datetime = datetime.strptime(self.name, DHM_FORMAT)
                 return datetime.strftime(self.lang_obj.date_format+ " " + self.lang_obj.time_format)
         return self.val
 
@@ -262,11 +262,11 @@ class rml_parse(object):
 
             if not isinstance(value, time.struct_time):
                 try:
-                    date = mx.DateTime.strptime(str(value),parse_format)
+                    date = datetime.datetime(str(value), parse_format)
                 except:# sometimes it takes converted values into value, so we dont need conversion.
                     return str(value)
             else:
-                date = mx.DateTime.DateTime(*(value.timetuple()[:6]))
+                date = datetime.datetime(*value.timetuple()[:6])
             return date.strftime(date_format)
         return self.lang_dict['lang_obj'].format('%.' + str(digits) + 'f', value, grouping=grouping, monetary=monetary)
 
index 36eb175..73b4d45 100644 (file)
@@ -87,10 +87,10 @@ def _eval_xml(self,node, pool, cr, uid, idref, context=None):
             a_eval = node.get('eval','')
             if len(a_eval):
                 import time
-                from mx import DateTime
+                import datetime
                 idref2 = idref.copy()
                 idref2['time'] = time
-                idref2['DateTime'] = DateTime
+                idref2['DateTime'] = datetime
                 import release
                 idref2['version'] = release.major_version
                 idref2['ref'] = lambda x: self.id_get(cr, False, x)
index 83e9032..2b1c7a8 100644 (file)
@@ -20,6 +20,8 @@
 ##############################################################################
 
 import os
+import datetime
+
 from os.path import join
 import fnmatch
 import csv, re
@@ -29,7 +31,6 @@ import ir
 import netsvc
 from tools.misc import UpdateableStr
 import inspect
-import mx.DateTime as mxdt
 import tempfile
 import tarfile
 import codecs
@@ -279,7 +280,7 @@ class TinyPoFile(object):
                               'version': release.version,
                               'modules': reduce(lambda s, m: s + "#\t* %s\n" % m, modules, ""),
                               'bugmail': release.support_email,
-                              'now': mxdt.ISO.strUTC(mxdt.ISO.DateTime.utc()),
+                              'now': datetime.datetime.now().isoformat(' '),
                             }
                           )
 
index 1c088b3..ef8eb4b 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -184,7 +184,7 @@ options = {
         "dist_dir": 'dist',
         "packages": ["lxml", "lxml.builder", "lxml._elementpath", "lxml.etree",
                      "lxml.objectify", "decimal", "xml", "xml.dom", "xml.xpath",
-                     "encodings","mx.DateTime","wizard","pychart","PIL", "pyparsing",
+                     "encodings","wizard","pychart","PIL", "pyparsing",
                      "pydot","asyncore","asynchat", "reportlab", "vobject",
                      "HTMLParser", "select"],
         "excludes" : ["Tkconstants","Tkinter","tcl"],