Merge "Add i18n support for some ERROR message"
This commit is contained in:
commit
c07698f2e8
@ -22,6 +22,7 @@ import wsme
|
||||
from magnum.common import exception
|
||||
from magnum.common import utils
|
||||
from magnum.i18n import _
|
||||
from magnum.i18n import _LE
|
||||
from magnum import objects
|
||||
|
||||
CONF = cfg.CONF
|
||||
@ -119,9 +120,10 @@ def get_openstack_resource(manager, resource_ident, resource_type):
|
||||
raise exception.ResourceNotFound(name=resource_type,
|
||||
id=resource_ident)
|
||||
if len(matches) > 1:
|
||||
msg = ("Multiple '%s' exist with same name '%s'. "
|
||||
"Please use the resource id instead." %
|
||||
(resource_type, resource_ident))
|
||||
msg = _LE("Multiple %(resource_type)s exist with same name "
|
||||
"%(resource_ident)s. Please use the resource id "
|
||||
"instead.") % {'resource_type': resource_type,
|
||||
'resource_ident': resource_ident}
|
||||
raise exception.Conflict(msg)
|
||||
resource_data = matches[0]
|
||||
return resource_data
|
||||
|
@ -21,6 +21,7 @@ from six.moves import urllib
|
||||
|
||||
from magnum.common import exception
|
||||
from magnum.i18n import _
|
||||
from magnum.i18n import _LE
|
||||
from magnum.i18n import _LI
|
||||
|
||||
URLFETCH_OPTS = [
|
||||
@ -76,8 +77,9 @@ def get(url, allowed_schemes=('http', 'https')):
|
||||
for chunk in reader:
|
||||
result += chunk
|
||||
if len(result) > cfg.CONF.max_manifest_size:
|
||||
raise URLFetchError("Manifest exceeds maximum allowed size (%s"
|
||||
" bytes)" % cfg.CONF.max_manifest_size)
|
||||
raise URLFetchError(_LE("Manifest exceeds maximum allowed"
|
||||
"size (%s bytes)") %
|
||||
cfg.CONF.max_manifest_size)
|
||||
return result
|
||||
|
||||
except exceptions.RequestException as ex:
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
import yaml
|
||||
|
||||
from magnum.i18n import _LE
|
||||
|
||||
if hasattr(yaml, 'CSafeDumper'):
|
||||
yaml_dumper = yaml.CSafeDumper
|
||||
@ -23,15 +24,17 @@ def load(s):
|
||||
try:
|
||||
yml_dict = yaml.safe_load(s)
|
||||
except yaml.YAMLError as exc:
|
||||
msg = 'An error occurred during YAML parsing.'
|
||||
msg = _LE('An error occurred during YAML parsing.')
|
||||
if hasattr(exc, 'problem_mark'):
|
||||
msg += ' Error position: (%s:%s)' % (exc.problem_mark.line + 1,
|
||||
exc.problem_mark.column + 1)
|
||||
msg += _LE(' Error position: '
|
||||
'(%(l)s:%(c)s)') % {'l': exc.problem_mark.line + 1,
|
||||
'c': exc.problem_mark.column + 1}
|
||||
raise ValueError(msg)
|
||||
if not isinstance(yml_dict, dict) and not isinstance(yml_dict, list):
|
||||
raise ValueError('The source is not a YAML mapping or list.')
|
||||
raise ValueError(_LE('The source is not a YAML mapping or list.'))
|
||||
if isinstance(yml_dict, dict) and len(yml_dict) < 1:
|
||||
raise ValueError('Could not find any element in your YAML mapping.')
|
||||
raise ValueError(_LE('Could not find any element in your YAML '
|
||||
'mapping.'))
|
||||
return yml_dict
|
||||
|
||||
|
||||
|
@ -31,6 +31,8 @@ from sqlalchemy import String
|
||||
from sqlalchemy import Text
|
||||
from sqlalchemy.types import TypeDecorator, TEXT
|
||||
|
||||
from magnum.i18n import _LE
|
||||
|
||||
|
||||
def table_args():
|
||||
engine_name = urlparse.urlparse(cfg.CONF.database.connection).scheme
|
||||
@ -51,10 +53,11 @@ class JsonEncodedType(TypeDecorator):
|
||||
# interface the consistent.
|
||||
value = self.type()
|
||||
elif not isinstance(value, self.type):
|
||||
raise TypeError("%s supposes to store %s objects, but %s given"
|
||||
% (self.__class__.__name__,
|
||||
self.type.__name__,
|
||||
type(value).__name__))
|
||||
raise TypeError(_LE("%(class)s supposes to store "
|
||||
"%(type)s objects, but %(value)s "
|
||||
"given") % {'class': self.__class__.__name__,
|
||||
'type': self.type.__name__,
|
||||
'value': type(value).__name__})
|
||||
serialized_value = json.dumps(value)
|
||||
return serialized_value
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user