|
|
|
@ -26,9 +26,17 @@ tr.setLocalDomain('cl_lib')
|
|
|
|
|
tr.setLanguage(sys.modules[__name__])
|
|
|
|
|
optparse._ = _
|
|
|
|
|
|
|
|
|
|
def check_choice_regignore(option, opt, value):
|
|
|
|
|
"""Check choice with registry independence"""
|
|
|
|
|
if value.lower() in map(lambda x:x.lower(),option.choices):
|
|
|
|
|
return value
|
|
|
|
|
else:
|
|
|
|
|
return optparse.check_choice(option,opt,value)
|
|
|
|
|
|
|
|
|
|
def make_option(shortOption=None, longOption=None,
|
|
|
|
|
optVal=None, help=None, default=None,
|
|
|
|
|
action=None, type=None, choices=None):
|
|
|
|
|
action=None, type=None, choices=None,
|
|
|
|
|
choices_regignore=None):
|
|
|
|
|
"""Make option. Used for processing options parameter in opt __init__.
|
|
|
|
|
|
|
|
|
|
shortOption short option
|
|
|
|
@ -40,6 +48,7 @@ def make_option(shortOption=None, longOption=None,
|
|
|
|
|
action another action (at example append, for creating list)
|
|
|
|
|
type type of value
|
|
|
|
|
choices choice values for type 'choice'
|
|
|
|
|
choices_regignore alsa as choice only registry ignored
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
Simple bool option:
|
|
|
|
@ -60,6 +69,7 @@ def make_option(shortOption=None, longOption=None,
|
|
|
|
|
# create option by arguments
|
|
|
|
|
args = []
|
|
|
|
|
dest = None
|
|
|
|
|
choices = choices or choices_regignore
|
|
|
|
|
if not shortOption is None:
|
|
|
|
|
args.append("-%s"%shortOption)
|
|
|
|
|
dest = shortOption
|
|
|
|
@ -77,10 +87,13 @@ def make_option(shortOption=None, longOption=None,
|
|
|
|
|
action = "store_true"
|
|
|
|
|
default = False
|
|
|
|
|
type = None
|
|
|
|
|
return optparse.make_option(*args, action=action, type=type,
|
|
|
|
|
opt = optparse.make_option(*args, action=action, type=type,
|
|
|
|
|
dest=dest, metavar=optVal,
|
|
|
|
|
help=help, default=default,
|
|
|
|
|
choices=choices)
|
|
|
|
|
if choices_regignore:
|
|
|
|
|
opt.TYPE_CHECKER["choice"] = check_choice_regignore
|
|
|
|
|
return opt
|
|
|
|
|
|
|
|
|
|
class ShareHelpFormatter:
|
|
|
|
|
"""Общие методы форматирования help-а"""
|
|
|
|
|