本文整理汇总了Python中translator.toscalib.utils.gettextutils._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: properties
def properties(self):
props = []
properties = self.node_type.get_value(PROPERTIES, self.node_template)
requiredprop = []
for p in self.node_type.properties_def:
if p.required:
requiredprop.append(p.name)
if properties:
#make sure it's not missing any property required by a node type
missingprop = []
for r in requiredprop:
if r not in properties.keys():
missingprop.append(r)
if missingprop:
raise ValueError(_("Node template %(tpl)s is missing "
"one or more required properties %(prop)s")
% {'tpl': self.name, 'prop': missingprop})
for name, value in properties.items():
for p in self.node_type.properties_def:
if p.name == name:
prop = Property(name, value, p.schema)
props.append(prop)
else:
if requiredprop:
raise ValueError(_("Node template %(tpl)s is missing"
"one or more required properties %(prop)s")
% {'tpl': self.name, 'prop': requiredprop})
return props
开发者ID:s-mukai,项目名称:heat-translator,代码行数:28,代码来源:nodetemplate.py
示例2: _get_capability_property
def _get_capability_property(self,
node_template,
capability_name,
property_name):
"""Gets a node template capability property."""
caps = node_template.get_capabilities()
if caps and capability_name in caps.keys():
cap = caps[capability_name]
property = None
props = cap.get_properties()
if props and property_name in props.keys():
property = props[property_name].value
if not property:
raise KeyError(_(
"Property '{0}' not found in capability '{1}' of node"
" template '{2}' referenced from node template"
" '{3}'.").format(property_name,
capability_name,
node_template.name,
self.context.name))
return property
msg = _("Requirement/Capability '{0}' referenced from '{1}' node "
"template not found in '{2}' node template.").format(
capability_name,
self.context.name,
node_template.name)
raise KeyError(msg)
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:27,代码来源:functions.py
示例3: __init__
def __init__(self, property_name, property_type, constraint):
super(InRange, self).__init__(property_name, property_type, constraint)
if not isinstance(self.constraint_value, collections.Sequence) or (len(constraint[self.IN_RANGE]) != 2):
raise InvalidSchemaError(message=_("in_range must be a list."))
for value in self.constraint_value:
if not isinstance(value, self.valid_types):
raise InvalidSchemaError(_("in_range value must " "be comparable."))
self.min = self.constraint_value[0]
self.max = self.constraint_value[1]
开发者ID:ckauf,项目名称:heat-translator,代码行数:11,代码来源:constraints.py
示例4: validate_scalar_unit
def validate_scalar_unit(self):
regex = re.compile('([0-9.]+)\s*(\w+)')
try:
result = regex.match(str(self.value)).groups()
validateutils.str_to_num(result[0])
except Exception:
raise ValueError(_('"%s" is not a valid scalar-unit')
% self.value)
if result[1].upper() in self.SCALAR_UNIT_DICT.keys():
return self.value
raise ValueError(_('"%s" is not a valid scalar-unit') % self.value)
开发者ID:micafer,项目名称:heat-translator,代码行数:11,代码来源:scalarunit.py
示例5: __new__
def __new__(cls, property_name, property_type, constraint):
if cls is not Constraint:
return super(Constraint, cls).__new__(cls)
if not isinstance(constraint, collections.Mapping) or len(constraint) != 1:
raise InvalidSchemaError(message=_("Invalid constraint schema."))
for type in constraint.keys():
ConstraintClass = get_constraint_class(type)
if not ConstraintClass:
msg = _('Invalid constraint type "%s".') % type
raise InvalidSchemaError(message=msg)
return ConstraintClass(property_name, property_type, constraint)
开发者ID:ckauf,项目名称:heat-translator,代码行数:14,代码来源:constraints.py
示例6: get_scalarunit_value
def get_scalarunit_value(type, value, unit=None):
if type in ScalarUnit.SCALAR_UNIT_TYPES:
ScalarUnit_Class = get_scalarunit_class(type)
return (ScalarUnit_Class(value).
get_num_from_scalar_unit(unit))
else:
raise TypeError(_('"%s" is not a valid scalar-unit type') % type)
开发者ID:micafer,项目名称:heat-translator,代码行数:7,代码来源:scalarunit.py
示例7: _err_msg
def _err_msg(self, value):
allowed = '[%s]' % ', '.join(str(a) for a in self.constraint_value)
return (_('%(pname)s: %(pvalue)s is not an valid '
'value "%(cvalue)s".') %
dict(pname=self.property_name,
pvalue=value,
cvalue=allowed))
开发者ID:micafer,项目名称:heat-translator,代码行数:7,代码来源:constraints.py
示例8: _translate_inputs
def _translate_inputs(self):
hot_inputs = []
hot_default = None
for input in self.inputs:
hot_input_type = TOSCA_TO_HOT_INPUT_TYPES[input.type]
if input.name in self.parsed_params:
DataEntity.validate_datatype(hot_input_type,
self.parsed_params[input.name])
hot_default = self.parsed_params[input.name]
elif input.default is not None:
hot_default = input.default
else:
raise Exception(_("Need to specify a value "
"for input {0}").format(input.name))
hot_constraints = []
if input.constraints:
for constraint in input.constraints:
constraint.validate(
int(hot_default) if hot_input_type == "number"
else hot_default)
hc, hvalue = self._translate_constraints(
constraint.constraint_key, constraint.constraint_value)
hot_constraints.append({hc: hvalue})
hot_inputs.append(HotParameter(name=input.name,
type=hot_input_type,
description=input.description,
default=hot_default,
constraints=hot_constraints))
return hot_inputs
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:31,代码来源:translate_inputs.py
示例9: _err_msg
def _err_msg(self, value):
return _("%(pname)s: %(pvalue)s is out of range " "(min:%(vmin)s, max:%(vmax)s).") % dict(
pname=self.property_name,
pvalue=self.value_msg,
vmin=self.constraint_value_msg[0],
vmax=self.constraint_value_msg[1],
)
开发者ID:ckauf,项目名称:heat-translator,代码行数:7,代码来源:constraints.py
示例10: validate
def validate(self):
if len(self.args) < 2 or len(self.args) > 3:
raise ValueError(_(
'Expected arguments: [node-template-name, req-or-cap '
'(optional), property name.'))
if len(self.args) == 2:
prop = self._find_property(self.args[1]).value
if not isinstance(prop, Function):
get_function(self.tosca_tpl, self.context, prop)
elif len(self.args) == 3:
get_function(self.tosca_tpl,
self.context,
self._find_req_or_cap_property(self.args[1],
self.args[2]))
else:
raise NotImplementedError(_(
'Nested properties are not supported.'))
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:17,代码来源:functions.py
示例11: _find_node_template
def _find_node_template(self, node_template_name):
if node_template_name == SELF:
return self.context
for node_template in self.tosca_tpl.nodetemplates:
if node_template.name == node_template_name:
return node_template
raise KeyError(_(
'No such node template: {0}.').format(node_template_name))
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:8,代码来源:functions.py
示例12: __init__
def __init__(self, ntype):
super(NodeType, self).__init__()
if ntype not in list(self.TOSCA_DEF.keys()):
raise ValueError(_('Node type %(ntype)s is not a valid type.')
% {'ntype': ntype})
self.defs = self.TOSCA_DEF[ntype]
self.type = ntype
self.related = {}
开发者ID:s-mukai,项目名称:heat-translator,代码行数:8,代码来源:nodetype.py
示例13: _find_property
def _find_property(self, property_name):
node_tpl = self._find_node_template(self.args[0])
props = node_tpl.get_properties()
found = [props[property_name]] if property_name in props else []
if len(found) == 0:
raise KeyError(_(
"Property: '{0}' not found in node template: {1}.").format(
property_name, node_tpl.name))
return found[0]
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:9,代码来源:functions.py
示例14: validate_boolean
def validate_boolean(value):
if isinstance(value, bool):
return value
if isinstance(value, str):
normalised = value.lower()
if normalised in ["true", "false"]:
return normalised == "true"
raise ValueError(_('"%s" is not a boolean') % value)
开发者ID:ckauf,项目名称:heat-translator,代码行数:9,代码来源:constraints.py
示例15: __init__
def __init__(self, **kwargs):
try:
self.message = self.msg_fmt % kwargs
except KeyError:
exc_info = sys.exc_info()
log.exception(_('Exception in string format operation: %s')
% exc_info[1])
if TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS:
raise exc_info[0]
开发者ID:hurf,项目名称:heat-translator,代码行数:10,代码来源:exception.py
示例16: parse_parameters
def parse_parameters(parameter_list):
parsed_inputs = {}
if parameter_list.startswith('--parameters'):
inputs = parameter_list.split('--parameters=')[1].\
replace('"', '').split(';')
for param in inputs:
keyvalue = param.split('=')
parsed_inputs[keyvalue[0]] = keyvalue[1]
else:
raise ValueError(_("%(param) is not a valid parameter.")
% parameter_list)
return parsed_inputs
开发者ID:micafer,项目名称:heat-translator,代码行数:12,代码来源:heat_translator.py
示例17: handle_hosting
def handle_hosting(self):
# handle hosting server for the OS:HEAT::SoftwareDeployment
# from the TOSCA nodetemplate, traverse the relationship chain
# down to the server
if self.type == "OS::Heat::SoftwareDeployment":
# skip if already have hosting
# If type is NodeTemplate, look up corresponding HotResrouce
host_server = self.properties.get("server")
if host_server is None or not host_server["get_resource"]:
raise Exception(_("Internal Error: expecting host " "in software deployment"))
elif isinstance(host_server["get_resource"], NodeTemplate):
self.properties["server"]["get_resource"] = host_server["get_resource"].name
开发者ID:ckauf,项目名称:heat-translator,代码行数:12,代码来源:hot_resource.py
示例18: main
def main():
if len(sys.argv) < 3:
msg = _("The program requires minimum two arguments. "
"Please refer to the usage documentation.")
raise ValueError(msg)
if "--template-file=" not in sys.argv[1]:
msg = _("The program expects --template-file as first argument. "
"Please refer to the usage documentation.")
raise ValueError(msg)
if "--template-type=" not in sys.argv[2]:
msg = _("The program expects --template-type as second argument. "
"Please refer to the usage documentation.")
raise ValueError(msg)
path = sys.argv[1].split('--template-file=')[1]
# e.g. --template_file=translator/toscalib/tests/data/tosca_helloworld.yaml
template_type = sys.argv[2].split('--template-type=')[1]
# e.g. --template_type=tosca
supported_types = ['tosca']
if not template_type:
raise ValueError(_("Template type is needed. For example, 'tosca'"))
elif template_type not in supported_types:
raise ValueError(_("%(value)s is not a valid template type.")
% {'value': template_type})
parsed_params = {}
if len(sys.argv) > 3:
parsed_params = parse_parameters(sys.argv[3])
if os.path.isfile(path):
heat_tpl = translate(template_type, path, parsed_params)
if heat_tpl:
write_output(heat_tpl)
else:
raise ValueError(_("%(path)s is not a valid file.") % {'path': path})
开发者ID:micafer,项目名称:heat-translator,代码行数:32,代码来源:heat_translator.py
示例19: _find_node_template_containing_attribute
def _find_node_template_containing_attribute(self):
if self.node_template_name == HOST:
# Currently this is the only way to tell whether the function
# is used within the outputs section of the TOSCA template.
if isinstance(self.context, list):
raise ValueError(_(
"get_attribute HOST keyword is not allowed within the "
"outputs section of the TOSCA template"))
node_tpl = self._find_host_containing_attribute()
if not node_tpl:
raise ValueError(_(
"get_attribute HOST keyword is used in '{0}' node "
"template but {1} was not found "
"in relationship chain").format(self.context.name,
HOSTED_ON))
else:
node_tpl = self._find_node_template(self.args[0])
if not self._attribute_exists_in_type(node_tpl.type_definition):
raise KeyError(_(
"Attribute '{0}' not found in node template: {1}.").format(
self.attribute_name, node_tpl.name))
return node_tpl
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:22,代码来源:functions.py
示例20: __init__
def __init__(self, property_name, property_type, constraint):
self.property_name = property_name
self.property_type = property_type
self.constraint_value = constraint[self.constraint_key]
self.constraint_value_msg = self.constraint_value
if self.property_type in scalarunit.ScalarUnit.SCALAR_UNIT_TYPES:
self.constraint_value = self._get_scalarunit_constraint_value()
# check if constraint is valid for property type
if property_type not in self.valid_prop_types:
msg = _('Constraint type "%(ctype)s" is not valid '
'for data type "%(dtype)s".') % dict(
ctype=self.constraint_key,
dtype=property_type)
raise InvalidSchemaError(message=msg)
开发者ID:micafer,项目名称:heat-translator,代码行数:14,代码来源:constraints.py
注:本文中的translator.toscalib.utils.gettextutils._函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论