summaryrefslogtreecommitdiff
path: root/optik_ext.py
diff options
context:
space:
mode:
authorSylvain <syt@logilab.fr>2006-08-25 15:06:44 +0200
committerSylvain <syt@logilab.fr>2006-08-25 15:06:44 +0200
commit99cad9add0aaedb17a1c52537a002afdab3290b9 (patch)
tree584f62d6ec526fca34a762ca7c85fdf4cffcdf0f /optik_ext.py
parent759be5c7f00e7be9390e4b668978cc682a10582e (diff)
downloadlogilab-common-99cad9add0aaedb17a1c52537a002afdab3290b9.tar.gz
see changelog
Diffstat (limited to 'optik_ext.py')
-rw-r--r--optik_ext.py41
1 files changed, 27 insertions, 14 deletions
diff --git a/optik_ext.py b/optik_ext.py
index fdaf9fd..17f0513 100644
--- a/optik_ext.py
+++ b/optik_ext.py
@@ -1,7 +1,7 @@
-# This program is free software; you can redistribute it and/or modify it under
-# the terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
@@ -50,6 +50,8 @@ except ImportError:
except:
NO_DEFAULT = []
+from mx import DateTime
+
OPTPARSE_FORMAT_DEFAULT = sys.version_info >= (2, 4)
from logilab.common.textutils import get_csv
@@ -121,6 +123,16 @@ def check_file(option, opt, value):
msg = "option %s: file %r does not exist"
raise OptionValueError(msg % (opt, value))
+def check_date(option, opt, value):
+ """check a file value
+ return the filepath
+ """
+ try:
+ return DateTime.strptime(value, "%Y/%m/%d")
+ except DateTime.Error :
+ raise OptionValueError(
+ "expected format of %s is yyyy/mm/dd" % opt)
+
def check_color(option, opt, value):
"""check a color value and returns it
/!\ does *not* check color labels (like 'red', 'green'), only
@@ -142,17 +154,18 @@ import types
class Option(BaseOption):
"""override optik.Option to add some new option types
"""
- TYPES = BaseOption.TYPES + ("regexp", "csv", 'yn', 'named', "password",
- "multiple_choice", "file", "font", "color")
+ TYPES = BaseOption.TYPES + ('regexp', 'csv', 'yn', 'date', 'named', 'password',
+ 'multiple_choice', 'file', 'font', 'color')
TYPE_CHECKER = copy(BaseOption.TYPE_CHECKER)
- TYPE_CHECKER["regexp"] = check_regexp
- TYPE_CHECKER["csv"] = check_csv
- TYPE_CHECKER["yn"] = check_yn
- TYPE_CHECKER["named"] = check_named
- TYPE_CHECKER["multiple_choice"] = check_csv
- TYPE_CHECKER["file"] = check_file
- TYPE_CHECKER["color"] = check_color
- TYPE_CHECKER["password"] = check_password
+ TYPE_CHECKER['regexp'] = check_regexp
+ TYPE_CHECKER['csv'] = check_csv
+ TYPE_CHECKER['yn'] = check_yn
+ TYPE_CHECKER['named'] = check_named
+ TYPE_CHECKER['multiple_choice'] = check_csv
+ TYPE_CHECKER['file'] = check_file
+ TYPE_CHECKER['color'] = check_color
+ TYPE_CHECKER['password'] = check_password
+ TYPE_CHECKER['date'] = check_date
def _check_choice(self):
"""FIXME: need to override this due to optik misdesign"""