[REF] get rid of the mx.Datetime C dependency, meaning better portability, especially to alternative Python interpreters, better maintainability; implements this blueprint: https://blueprints.launchpad.net/openobject-server/+spec/get-rid-of-mx-datetime-dependency; largely the work of Cristian Salamea (GnuThink)

bzr revid: rvalyi@gmail.com-20091213181601-4k4mhtgnv2qynrjo
This commit is contained in:
Cristian Salamea (GnuThink) 2009-12-13 16:16:01 -02:00 committed by Raphaël Valyi
parent 2156658aef
commit f41e524133
8 changed files with 25 additions and 30 deletions

View File

@ -20,8 +20,9 @@
# #
############################################################################## ##############################################################################
from mx import DateTime
import time import time
import datetime
from dateutil.relativedelta import *
import netsvc import netsvc
import tools import tools
import pooler import pooler
@ -31,12 +32,12 @@ def str2tuple(s):
return eval('tuple(%s)' % (s or '')) return eval('tuple(%s)' % (s or ''))
_intervalTypes = { _intervalTypes = {
'work_days': lambda interval: DateTime.RelativeDateTime(days=interval), 'work_days': lambda interval: relativedelta(days=interval),
'days': lambda interval: DateTime.RelativeDateTime(days=interval), 'days': lambda interval: relativedelta(days=interval),
'hours': lambda interval: DateTime.RelativeDateTime(hours=interval), 'hours': lambda interval: relativedelta(hours=interval),
'weeks': lambda interval: DateTime.RelativeDateTime(days=7*interval), 'weeks': lambda interval: relativedelta(days=7*interval),
'months': lambda interval: DateTime.RelativeDateTime(months=interval), 'months': lambda interval: relativedelta(months=interval),
'minutes': lambda interval: DateTime.RelativeDateTime(minutes=interval), 'minutes': lambda interval: relativedelta(minutes=interval),
} }
class ir_cron(osv.osv, netsvc.Agent): class ir_cron(osv.osv, netsvc.Agent):
@ -100,10 +101,10 @@ class ir_cron(osv.osv, netsvc.Agent):
cr = db.cursor() cr = db.cursor()
try: try:
if not pool._init: 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') cr.execute('select * from ir_cron where numbercall<>0 and active and nextcall<=now() order by priority')
for job in cr.dictfetchall(): 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'] numbercall = job['numbercall']
ok = False ok = False

View File

@ -26,9 +26,6 @@ import ir
from tools.misc import currency from tools.misc import currency
from tools.translate import _ from tools.translate import _
import mx.DateTime
from mx.DateTime import RelativeDateTime, now, DateTime, localtime
class res_currency(osv.osv): class res_currency(osv.osv):
def _current_rate(self, cr, uid, ids, name, arg, context={}): def _current_rate(self, cr, uid, ids, name, arg, context={}):
res={} res={}

View File

@ -79,10 +79,6 @@ for name, value in [('addons_path', tools.config['addons_path']),
import time 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 # init net service
#---------------------------------------------------------- #----------------------------------------------------------

View File

@ -29,7 +29,7 @@ import libxslt
import locale import locale
import time, os import time, os
import mx.DateTime import datetime
class report_printscreen_list(report_int): class report_printscreen_list(report_int):
def __init__(self, name): def __init__(self, name):
@ -178,19 +178,19 @@ class report_printscreen_list(report_int):
if fields[f]['type'] == 'date' and line[f]: if fields[f]['type'] == 'date' and line[f]:
format = str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y')) 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) new_d1 = d1.strftime(format)
line[f] = new_d1 line[f] = new_d1
if fields[f]['type'] == 'time' and line[f]: if fields[f]['type'] == 'time' and line[f]:
format = str(locale.nl_langinfo(locale.T_FMT)) 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) new_d1 = d1.strftime(format)
line[f] = new_d1 line[f] = new_d1
if fields[f]['type'] == 'datetime' and line[f]: 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)) 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) new_d1 = d1.strftime(format)
line[f] = new_d1 line[f] = new_d1

View File

@ -25,7 +25,7 @@ import cStringIO
import base64 import base64
import copy import copy
import locale import locale
import mx.DateTime import datetime
import os import os
import re import re
import time import time
@ -109,7 +109,7 @@ class _date_format(str, _format):
def __str__(self): def __str__(self):
if self.val: if self.val:
if hasattr(self,'name') and (self.name): 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 date.strftime(self.lang_obj.date_format)
return self.val return self.val
@ -121,7 +121,7 @@ class _dttime_format(str, _format):
def __str__(self): def __str__(self):
if self.val: if self.val:
if hasattr(self,'name') and self.name: 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 datetime.strftime(self.lang_obj.date_format+ " " + self.lang_obj.time_format)
return self.val return self.val
@ -262,11 +262,11 @@ class rml_parse(object):
if not isinstance(value, time.struct_time): if not isinstance(value, time.struct_time):
try: 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. except:# sometimes it takes converted values into value, so we dont need conversion.
return str(value) return str(value)
else: else:
date = mx.DateTime.DateTime(*(value.timetuple()[:6])) date = datetime.datetime(*value.timetuple()[:6])
return date.strftime(date_format) return date.strftime(date_format)
return self.lang_dict['lang_obj'].format('%.' + str(digits) + 'f', value, grouping=grouping, monetary=monetary) return self.lang_dict['lang_obj'].format('%.' + str(digits) + 'f', value, grouping=grouping, monetary=monetary)

View File

@ -87,10 +87,10 @@ def _eval_xml(self,node, pool, cr, uid, idref, context=None):
a_eval = node.get('eval','') a_eval = node.get('eval','')
if len(a_eval): if len(a_eval):
import time import time
from mx import DateTime import datetime
idref2 = idref.copy() idref2 = idref.copy()
idref2['time'] = time idref2['time'] = time
idref2['DateTime'] = DateTime idref2['DateTime'] = datetime
import release import release
idref2['version'] = release.major_version idref2['version'] = release.major_version
idref2['ref'] = lambda x: self.id_get(cr, False, x) idref2['ref'] = lambda x: self.id_get(cr, False, x)

View File

@ -20,6 +20,8 @@
############################################################################## ##############################################################################
import os import os
import datetime
from os.path import join from os.path import join
import fnmatch import fnmatch
import csv, re import csv, re
@ -29,7 +31,6 @@ import ir
import netsvc import netsvc
from tools.misc import UpdateableStr from tools.misc import UpdateableStr
import inspect import inspect
import mx.DateTime as mxdt
import tempfile import tempfile
import tarfile import tarfile
import codecs import codecs
@ -279,7 +280,7 @@ class TinyPoFile(object):
'version': release.version, 'version': release.version,
'modules': reduce(lambda s, m: s + "#\t* %s\n" % m, modules, ""), 'modules': reduce(lambda s, m: s + "#\t* %s\n" % m, modules, ""),
'bugmail': release.support_email, 'bugmail': release.support_email,
'now': mxdt.ISO.strUTC(mxdt.ISO.DateTime.utc()), 'now': datetime.datetime.now().isoformat(' '),
} }
) )

View File

@ -184,7 +184,7 @@ options = {
"dist_dir": 'dist', "dist_dir": 'dist',
"packages": ["lxml", "lxml.builder", "lxml._elementpath", "lxml.etree", "packages": ["lxml", "lxml.builder", "lxml._elementpath", "lxml.etree",
"lxml.objectify", "decimal", "xml", "xml.dom", "xml.xpath", "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", "pydot","asyncore","asynchat", "reportlab", "vobject",
"HTMLParser", "select"], "HTMLParser", "select"],
"excludes" : ["Tkconstants","Tkinter","tcl"], "excludes" : ["Tkconstants","Tkinter","tcl"],