summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>2006-09-21 21:41:35 +0200
committerAlexandre Fayolle <alexandre.fayolle@logilab.fr>2006-09-21 21:41:35 +0200
commitf6c6ea416f4f7707cecbb1771f10a9f972572f98 (patch)
treed6bbc2a6efb8d5900b1888c7fb1277b3534e25b8
parentf8cd4e5d40dc1133da06836e2999ea1e760185c5 (diff)
parent4c46c22d9675eb940a4e8f398242da3f7387bc7b (diff)
downloadlogilab-common-f6c6ea416f4f7707cecbb1771f10a9f972572f98.tar.gz
merge
-rw-r--r--ChangeLog1
-rw-r--r--configuration.py1
-rw-r--r--db.py22
-rw-r--r--optik_ext.py5
-rw-r--r--test/unittest_configuration.py32
-rwxr-xr-xtest/unittest_fileutils.py2
6 files changed, 39 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index bf7fa24..cd4ec1c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@ ChangeLog for logilab.common
--
* db:
- fixed bug when querying boolean on sqlite using python's bool type
+ - fixed time handling and added an adapter for DateTimeDeltaType
- added "drop_on_commit" argument to create_temporary_table on db helper
- added missing implementation of executemany on pysqlite2 wrapper to
support pyargs correctly like execute
diff --git a/configuration.py b/configuration.py
index 1337cd4..4dff336 100644
--- a/configuration.py
+++ b/configuration.py
@@ -73,7 +73,6 @@ config.generate_config()
from __future__ import generators
-__revision__ = "$Id: configuration.py,v 1.40 2005-11-22 13:13:00 syt Exp $"
__docformat__ = "restructuredtext en"
__all__ = ('OptionsManagerMixIn', 'OptionsProviderMixIn',
'ConfigurationMixIn', 'Configuration',
diff --git a/db.py b/db.py
index 75ffbd7..bcf77df 100644
--- a/db.py
+++ b/db.py
@@ -252,27 +252,31 @@ class _PySqlite2Adapter(DBAPIAdapter):
if hasattr(sqlite, '_mx_initialized'):
return
- from mx.DateTime import DateTimeType, strptime
+ from mx.DateTime import DateTimeType, DateTimeDeltaType, strptime
from StringIO import StringIO
def adapt_mxdatetime(mxd):
- return mxd.strftime('%F %H:%M:%S')
+ return mxd.strftime('%Y-%m-%d %H:%M:%S')
sqlite.register_adapter(DateTimeType, adapt_mxdatetime)
+ def adapt_mxdatetimedelta(mxd):
+ return mxd.strftime('%H:%M:%S')
+ sqlite.register_adapter(DateTimeDeltaType, adapt_mxdatetimedelta)
+
def convert_mxdate(ustr):
- return strptime(ustr, '%F %H:%M:%S')
+ return strptime(ustr, '%Y-%m-%d %H:%M:%S')
sqlite.register_converter('date', convert_mxdate)
def convert_mxdatetime(ustr):
- try:
- return strptime(ustr, '%F %H:%M:%S')
- except Exception, ex:
- print ex, ustr
- return ustr
+ return strptime(ustr, '%Y-%m-%d %H:%M:%S')
sqlite.register_converter('timestamp', convert_mxdatetime)
def convert_mxtime(ustr):
- return strptime(ustr, '%H:%M')
+ try:
+ return strptime(ustr, '%H:%M:%S')
+ except:
+ # DateTime used as Time?
+ return strptime(ustr, '%Y-%m-%d %H:%M:%S')
sqlite.register_converter('time', convert_mxtime)
diff --git a/optik_ext.py b/optik_ext.py
index 5ce2dfd..43bdf17 100644
--- a/optik_ext.py
+++ b/optik_ext.py
@@ -190,7 +190,10 @@ class Option(BaseOption):
def process(self, opt, value, values, parser):
# First, convert the value(s) to the right type. Howl if any
# value(s) are bogus.
- value = self.convert_value(opt, value)
+ try:
+ value = self.convert_value(opt, value)
+ except AttributeError: # py < 2.4
+ value = self.check_value(opt, value)
if self.type == 'named':
existant = getattr(values, self.dest)
if existant:
diff --git a/test/unittest_configuration.py b/test/unittest_configuration.py
index bbcdb31..95cbadf 100644
--- a/test/unittest_configuration.py
+++ b/test/unittest_configuration.py
@@ -5,7 +5,7 @@ from sys import version_info
from logilab.common.testlib import TestCase, unittest_main
from logilab.common.configuration import Configuration, OptionValueError, \
- OptionsManagerMixIn, OptionsProviderMixIn
+ OptionsManagerMixIn, OptionsProviderMixIn, Method
options = [('dothis', {'type':'yn', 'default': True, 'metavar': '<y or n>'}),
('value', {'type': 'string', 'metavar': '<string>', 'short': 'v'}),
@@ -18,12 +18,19 @@ options = [('dothis', {'type':'yn', 'default': True, 'metavar': '<y or n>'}),
('multiple-choice', {'type': 'multiple_choice', 'default':('yo', 'ye'),
'choices': ('yo', 'ye', 'yu', 'yi', 'ya'),
'metavar':'<yo|ye>'}),
+ ('named', {'type':'named', 'default':Method('get_named'),
+ 'metavar': '<key=val>'}),
]
+class MyConfiguration(Configuration):
+ """test configuration"""
+ def get_named(self):
+ return {'key': 'val'}
+
class ConfigurationTC(TestCase):
def setUp(self):
- self.cfg = Configuration(name='test', options=options, usage='Just do it ! (tm)')
+ self.cfg = MyConfiguration(name='test', options=options, usage='Just do it ! (tm)')
def test_default(self):
cfg = self.cfg
@@ -33,6 +40,7 @@ class ConfigurationTC(TestCase):
self.assertEquals(cfg['number'], 2)
self.assertEquals(cfg['choice'], 'yo')
self.assertEquals(cfg['multiple-choice'], ('yo', 'ye'))
+ self.assertEquals(cfg['named'], {'key': 'val'})
def test_base(self):
cfg = self.cfg
@@ -80,11 +88,7 @@ class ConfigurationTC(TestCase):
def test_generate_config(self):
stream = StringIO()
self.cfg.generate_config(stream)
- self.assertLinesEquals(stream.getvalue().strip(), """# class for simple configurations which don't need the
-# manager / providers model and prefer delegation to inheritance
-#
-# configuration values are accessible through a dict like interface
-#
+ self.assertLinesEquals(stream.getvalue().strip(), """# test configuration
[TEST]
dothis=yes
@@ -97,17 +101,15 @@ number=2
choice=yo
multiple-choice=yo,ye
+
+named=key:val
""")
def test_generate_config_with_space_string(self):
self.cfg['value'] = ' '
stream = StringIO()
self.cfg.generate_config(stream)
- self.assertLinesEquals(stream.getvalue().strip(), """# class for simple configurations which don't need the
-# manager / providers model and prefer delegation to inheritance
-#
-# configuration values are accessible through a dict like interface
-#
+ self.assertLinesEquals(stream.getvalue().strip(), """# test configuration
[TEST]
dothis=yes
@@ -122,6 +124,8 @@ number=2
choice=yo
multiple-choice=yo,ye
+
+named=key:val
""")
@@ -132,7 +136,7 @@ multiple-choice=yo,ye
try:
cfg.generate_config(stream)
stream.close()
- new_cfg = Configuration(name='testloop', options=options)
+ new_cfg = MyConfiguration(name='testloop', options=options)
new_cfg.load_file_configuration(f)
self.assertEquals(cfg['dothis'], new_cfg['dothis'])
self.assertEquals(cfg['multiple'], new_cfg['multiple'])
@@ -163,6 +167,7 @@ options:
--number=<int>
--choice=<yo|ye>
--multiple-choice=<yo|ye>
+ --named=<key=val>
Bonus:
a nice additional help
@@ -179,6 +184,7 @@ options:
--number=<int>
--choice=<yo|ye>
--multiple-choice=<yo|ye>
+ --named=<key=val>
Bonus:
a nice additional help
diff --git a/test/unittest_fileutils.py b/test/unittest_fileutils.py
index f3ef664..ebe6226 100755
--- a/test/unittest_fileutils.py
+++ b/test/unittest_fileutils.py
@@ -73,6 +73,8 @@ class GetByExtTC(TestCase):
[join('data', f) for f in ['foo.txt',
'newlines.txt',
'normal_file.txt',
+ 'test1.msg',
+ 'test2.msg',
'spam.txt',
join('sub', 'doc.txt'),
'write_protected_file.txt',