Translator functions cleanup part 1
This part fixes ironic/common folder and tox.ini file. Some modules use _ function for log translation, even when the translated string is passed to e.g. LOG.warn function. This patch fixes it, using translator functions appropriate for corresponding log levels. Translator functions, imported from ironic.openstack.common.gettextutils are now imported from ironic.common.i18n. Translator functions are imported the same way across all modules. All places that are changed conform to http://docs.openstack.org/developer/oslo.i18n/guidelines.html Partial-bug: #1364813 Change-Id: I195d0e256c5412d6d75d2e6c35b19b44f2a0b09f
This commit is contained in:
parent
892b4d84d7
commit
284f83eb93
|
@ -19,6 +19,7 @@ from oslo.config import cfg
|
|||
|
||||
from ironic.common import exception
|
||||
from ironic.common.i18n import _
|
||||
from ironic.common.i18n import _LW
|
||||
from ironic.common import utils
|
||||
from ironic.openstack.common import log as logging
|
||||
from ironic.openstack.common import loopingcall
|
||||
|
@ -129,8 +130,8 @@ class DiskPartitioner(object):
|
|||
pids_match = re.search(self._fuser_pids_re, out)
|
||||
pids[0] = pids_match.group()
|
||||
except processutils.ProcessExecutionError as exc:
|
||||
LOG.warning(_('Failed to check the device %(device)s with fuser: '
|
||||
' %(err)s') % {'device': self._device, 'err': exc})
|
||||
LOG.warning(_LW('Failed to check the device %(device)s with fuser:'
|
||||
' %(err)s'), {'device': self._device, 'err': exc})
|
||||
|
||||
def commit(self):
|
||||
"""Write to the disk."""
|
||||
|
@ -194,9 +195,9 @@ def list_partitions(device):
|
|||
for line in lines:
|
||||
match = _PARTED_PRINT_RE.match(line)
|
||||
if match is None:
|
||||
LOG.warn(_("Partition information from parted for device "
|
||||
"%(device)s does not match "
|
||||
"expected format: %(line)s"),
|
||||
LOG.warn(_LW("Partition information from parted for device "
|
||||
"%(device)s does not match "
|
||||
"expected format: %(line)s"),
|
||||
dict(device=device, line=line))
|
||||
continue
|
||||
# Cast int fields to ints (some are floats and we round them down)
|
||||
|
|
|
@ -35,6 +35,8 @@ import six
|
|||
|
||||
from ironic.common import exception
|
||||
from ironic.common.i18n import _
|
||||
from ironic.common.i18n import _LE
|
||||
from ironic.common.i18n import _LW
|
||||
from ironic.openstack.common import log as logging
|
||||
from ironic.openstack.common import processutils
|
||||
|
||||
|
@ -409,7 +411,7 @@ def tempdir(**kwargs):
|
|||
try:
|
||||
shutil.rmtree(tmpdir)
|
||||
except OSError as e:
|
||||
LOG.error(_('Could not remove tmpdir: %s'), str(e))
|
||||
LOG.error(_LE('Could not remove tmpdir: %s'), e)
|
||||
|
||||
|
||||
def mkfs(fs, path, label=None):
|
||||
|
@ -444,8 +446,8 @@ def unlink_without_raise(path):
|
|||
if e.errno == errno.ENOENT:
|
||||
return
|
||||
else:
|
||||
LOG.warn(_("Failed to unlink %(path)s, error: %(e)s") %
|
||||
{'path': path, 'e': e})
|
||||
LOG.warn(_LW("Failed to unlink %(path)s, error: %(e)s"),
|
||||
{'path': path, 'e': e})
|
||||
|
||||
|
||||
def rmtree_without_raise(path):
|
||||
|
@ -453,7 +455,7 @@ def rmtree_without_raise(path):
|
|||
if os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
except OSError as e:
|
||||
LOG.warn(_("Failed to remove dir %(path)s, error: %(e)s") %
|
||||
LOG.warn(_LW("Failed to remove dir %(path)s, error: %(e)s"),
|
||||
{'path': path, 'e': e})
|
||||
|
||||
|
||||
|
@ -469,9 +471,9 @@ def create_link_without_raise(source, link):
|
|||
if e.errno == errno.EEXIST:
|
||||
return
|
||||
else:
|
||||
LOG.warn(_("Failed to create symlink from %(source)s to %(link)s"
|
||||
", error: %(e)s") %
|
||||
{'source': source, 'link': link, 'e': e})
|
||||
LOG.warn(_LW("Failed to create symlink from %(source)s to %(link)s"
|
||||
", error: %(e)s"),
|
||||
{'source': source, 'link': link, 'e': e})
|
||||
|
||||
|
||||
def safe_rstrip(value, chars=None):
|
||||
|
@ -483,8 +485,8 @@ def safe_rstrip(value, chars=None):
|
|||
|
||||
"""
|
||||
if not isinstance(value, six.string_types):
|
||||
LOG.warn(_("Failed to remove trailing character. Returning original "
|
||||
"object. Supplied object is not a string: %s,") % value)
|
||||
LOG.warn(_LW("Failed to remove trailing character. Returning original "
|
||||
"object. Supplied object is not a string: %s,"), value)
|
||||
return value
|
||||
|
||||
return value.rstrip(chars) or value
|
||||
|
|
2
tox.ini
2
tox.ini
|
@ -48,4 +48,4 @@ exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,t
|
|||
[hacking]
|
||||
import_exceptions = ironic.openstack.common.gettextutils._, ironic.openstack.common.gettextutils._LI,
|
||||
ironic.openstack.common.gettextutils._LW,ironic.openstack.common.gettextutils._LE,
|
||||
ironic.openstack.common.gettextutils._LC, testtools.matchers, ironic.common.i18n._
|
||||
ironic.openstack.common.gettextutils._LC, testtools.matchers, ironic.common.i18n
|
||||
|
|
Loading…
Reference in New Issue