本文整理汇总了Python中optparse.Option.take_action方法的典型用法代码示例。如果您正苦于以下问题:Python Option.take_action方法的具体用法?Python Option.take_action怎么用?Python Option.take_action使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类optparse.Option
的用法示例。
在下文中一共展示了Option.take_action方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: take_action
# 需要导入模块: from optparse import Option [as 别名]
# 或者: from optparse.Option import take_action [as 别名]
def take_action(self, action, dest, opt, value, values, parser):
if action == 'extend':
split_value = value.split(',')
ensure_value(qconfig, dest, []).extend(split_value)
else:
Option.take_action(
self, action, dest, opt, value, qconfig, parser)
示例2: take_action
# 需要导入模块: from optparse import Option [as 别名]
# 或者: from optparse.Option import take_action [as 别名]
def take_action(self, action, dest, opt, value, values, parser):
if action == "extend":
lvalue = value.split(",")
values.ensure_value(dest, []).extend(lvalue)
else:
Option.take_action(
self, action, dest, opt, value, values, parser)
示例3: take_action
# 需要导入模块: from optparse import Option [as 别名]
# 或者: from optparse.Option import take_action [as 别名]
def take_action(self, action, dest, opt, value, values, parser):
if action == "pubsub":
# read the subscriber and publisher arguments
value += " "
for arg in parser.rargs:
if arg[:2] == "--" and len(arg) > 2: break
if arg[:1] == "-" and len(arg) > 1: break
value += arg + " "
subpubArray = [ x.strip() for x in value.split(",") if x.strip() ]
# verify that argument meets requirements
if len(subpubArray) == 2:
values.ensure_value(dest, []).append({"name": subpubArray[0], "type": subpubArray[1]})
else:
if opt == '-s': exitWithError(ERROR_OPT.SUBSCRIBER_MISSING, len(subpubArray))
if opt == '-p': exitWithError(ERROR_OPT.PUBLISHER_MISING, len(subpubArray))
elif action == "strspaces":
# read the subscriber and publisher arguments
for arg in parser.rargs:
if arg[:2] == "--" and len( arg ) > 2: break
if arg[:1] == "-" and len( arg ) > 1: break
value += " " + arg
setattr(values, dest, value )
else:
Option.take_action(self, action, dest, opt, value, values, parser)
示例4: take_action
# 需要导入模块: from optparse import Option [as 别名]
# 或者: from optparse.Option import take_action [as 别名]
def take_action(self, action, dest, opt, value, values, parser):
if action == "map":
values.ensure_value(dest, parser.map[opt.lstrip('-')])
elif action == "map_extend":
values.ensure_value(dest, []).extend(parser.map[opt.lstrip('-')])
else:
Option.take_action(self, action, dest, opt, value, values, parser)
示例5: take_action
# 需要导入模块: from optparse import Option [as 别名]
# 或者: from optparse.Option import take_action [as 别名]
def take_action(self,action,dest,opt,value,values,parser):
log.debug('take_action: %s',action)
if action in custom_actions:
custom_actions.get(action)(dest,value,values)
else:
Option.take_action(self,action,dest,opt,value,values,parser)
log.debug('values: %s',values)
示例6: take_action
# 需要导入模块: from optparse import Option [as 别名]
# 或者: from optparse.Option import take_action [as 别名]
def take_action(self, action, dest, opt, value, values, parser):
"Extended to handle generation a config file"
if action == "generate_config":
parser.generate_and_print_config_file()
parser.exit()
Option.take_action(self, action, dest, opt, value, values, parser)
示例7: take_action
# 需要导入模块: from optparse import Option [as 别名]
# 或者: from optparse.Option import take_action [as 别名]
def take_action(self, action, dest, opt, value, values, parser):
"""
This function is a wrapper to take certain options passed on command
prompt and wrap them into an Array.
@param action: The type of action that will be taken. For example:
"store_true", "store_false", "extend".
@type action: String
@param dest: The name of the variable that will be used to store the
option.
@type dest: String/Boolean/Array
@param opt: The option string that triggered the action.
@type opt: String
@param value: The value of opt(option) if it takes a
value, if not then None.
@type value:
@param values: All the opt(options) in a dictionary.
@type values: Dictionary
@param parser: The option parser that was orginally called.
@type parser: OptionParser
"""
if (action == "extend") :
value_list = []
try:
for v in value.split(","):
# Need to add code for dealing with paths if there is option for paths.
new_value = value.strip().rstrip()
if (len(new_value) > 0):
value_list.append(new_value)
except:
pass
else:
values.ensure_value(dest, []).extend(value_list)
else:
Option.take_action(self, action, dest, opt, value, values, parser)
示例8: take_action
# 需要导入模块: from optparse import Option [as 别名]
# 或者: from optparse.Option import take_action [as 别名]
def take_action(self, action, dest, opt, val, vals, parser):
if action == 'setitem':
key = opt.strip('-')
vals.ensure_value(dest, {})[key] = val
elif action == 'setitem2':
key, val = val
vals.ensure_value(dest, {})[key] = val
else:
Opt.take_action(self, action, dest, opt, val, vals, parser)
示例9: take_action
# 需要导入模块: from optparse import Option [as 别名]
# 或者: from optparse.Option import take_action [as 别名]
def take_action(self, action, dest, opt, value, values, parser):
if action == "extend":
lvalue = value.split(",")
for token in lvalue:
token = token.strip()
if token:
values.ensure_value(dest, []).append(token)
else:
Option.take_action(
self, action, dest, opt, value, values, parser)
示例10: take_action
# 需要导入模块: from optparse import Option [as 别名]
# 或者: from optparse.Option import take_action [as 别名]
def take_action(self,action,dest,opt,value,values,parser):
if action=="dic":
vals=value.split(",")
d={}
for val in vals:
p=val.split("]")
k=p[0][1:]
v=p[1]
d[k]=v
setattr(values,dest,d)
else: Option.take_action(self, action, dest, opt, value, values, parser)
示例11: take_action
# 需要导入模块: from optparse import Option [as 别名]
# 或者: from optparse.Option import take_action [as 别名]
def take_action(self, action, dest, opt, value, values, parser):
""" Performs list extension on plugins """
if action == "extend":
try:
lvalue = value.split(",")
except:
pass
else:
values.ensure_value(dest, deque()).extend(lvalue)
else:
Option.take_action(self, action, dest, opt, value, values, parser)
示例12: take_action
# 需要导入模块: from optparse import Option [as 别名]
# 或者: from optparse.Option import take_action [as 别名]
def take_action(self, action, dest, opt, value, values, parser):
if action == "extend":
values.ensure_value(dest, []).append(value)
else:
Option.take_action(
self,
action,
dest,
opt,
value,
values,
parser)
示例13: take_action
# 需要导入模块: from optparse import Option [as 别名]
# 或者: from optparse.Option import take_action [as 别名]
def take_action(self, action, dest, opt, value, values, parser):
if action == "store_list":
value = value.strip()
lvalue = value.split(",")
size = len(lvalue)
if size > 0 and lvalue[size - 1] == "":
lvalue.pop()
values.ensure_value(dest, []).extend(lvalue)
else:
Option.take_action(
self, action, dest, opt, value, values, parser)
示例14: take_action
# 需要导入模块: from optparse import Option [as 别名]
# 或者: from optparse.Option import take_action [as 别名]
def take_action(self, action, dest, opt, value, values, parser):
if action == "extend":
values.ensure_value(dest, []).append(value)
for a in parser.rargs[:]:
if a.startswith("-"):
break
else:
values.ensure_value(dest, []).append(a)
parser.rargs.remove(a)
else:
Option.take_action(self, action, dest, opt, value, values, parser)
示例15: take_action
# 需要导入模块: from optparse import Option [as 别名]
# 或者: from optparse.Option import take_action [as 别名]
def take_action(self, action, dest, opt, value, values, parser):
if (action == "extend") :
valueList = []
try:
for v in value.split(","):
newValue = v.strip().rstrip()
if (len(newValue) > 0):
valueList.append(newValue)
except:
pass
else:
values.ensure_value(dest, []).extend(valueList)
else:
Option.take_action(self, action, dest, opt, value, values, parser)