Use oslo.i18n

oslo.i18n provides the i18n function that were provided by
oslo-incubator's gettextutils module

Import _ where needed, oslo.i18n deprecated the builtin method.

Closes-Bug: #1382187
Change-Id: I12aa1c725aa4bb52a9aa46e9c3d2b303839de48b
This commit is contained in:
Andreas Jaeger 2014-10-16 21:36:13 +02:00
parent 732ccbc661
commit 7b659fc4e0
69 changed files with 149 additions and 9 deletions

View File

@ -39,9 +39,11 @@ possible_topdir = os.path.normpath(os.path.join
if os.path.exists(os.path.join(possible_topdir, "manila", "__init__.py")):
sys.path.insert(0, possible_topdir)
from manila.openstack.common import gettextutils
gettextutils.install('manila')
from manila import i18n
i18n.enable_lazy()
from manila.common import config # Need to register global_opts # noqa
from manila.i18n import _
from manila.openstack.common import log as logging
from manila import service
from manila import utils

View File

@ -36,8 +36,9 @@ possible_topdir = os.path.normpath(os.path.join
if os.path.exists(os.path.join(possible_topdir, "manila", "__init__.py")):
sys.path.insert(0, possible_topdir)
from manila.openstack.common import gettextutils
gettextutils.install('manila')
from manila import i18n
i18n.enable_lazy()
from manila.common import config # Need to register global_opts # noqa
from manila.openstack.common import log as logging
from manila import service

View File

@ -67,8 +67,8 @@ POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'manila', '__init__.py')):
sys.path.insert(0, POSSIBLE_TOPDIR)
from manila.openstack.common import gettextutils
gettextutils.install('manila')
from manila import i18n
i18n.enable_lazy()
from oslo.config import cfg
@ -76,6 +76,7 @@ from manila.common import config # Need to register global_opts # noqa
from manila import context
from manila import db
from manila.db import migration
from manila.i18n import _
from manila.openstack.common import log as logging
from manila.openstack.common import uuidutils
from manila import utils

View File

@ -34,8 +34,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
if os.path.exists(os.path.join(possible_topdir, 'manila', '__init__.py')):
sys.path.insert(0, possible_topdir)
from manila.openstack.common import gettextutils
gettextutils.install('manila')
from manila import i18n
i18n.enable_lazy()
from manila.common import config # Need to register global_opts # noqa
from manila.openstack.common import log as logging
from manila import service

View File

@ -15,6 +15,7 @@
# under the License.
from manila.api.middleware import auth
from manila.i18n import _
from manila.openstack.common import log as logging

View File

@ -23,6 +23,7 @@ import webob
from manila.api.openstack import wsgi
from manila.api import xmlutil
from manila.i18n import _
from manila.openstack.common import log as logging
from manila import utils

View File

@ -23,6 +23,7 @@ from manila.api import xmlutil
from manila import db
from manila.db.sqlalchemy import api as sqlalchemy_api
from manila import exception
from manila.i18n import _
from manila.openstack.common import log as logging
from manila.openstack.common import strutils
from manila import quota

View File

@ -21,6 +21,7 @@ from manila.api import extensions
from manila.api.openstack import wsgi
from manila.api import xmlutil
from manila import exception
from manila.i18n import _
from manila import share

View File

@ -23,6 +23,7 @@ from manila.api import extensions
from manila.api.openstack import wsgi
from manila import db
from manila import exception
from manila.i18n import _
from manila import rpc
from manila.share import volume_types

View File

@ -25,6 +25,7 @@ import manila.api.openstack
from manila.api.openstack import wsgi
from manila.api import xmlutil
from manila import exception
from manila.i18n import _
from manila.openstack.common import importutils
from manila.openstack.common import log as logging
import manila.policy

View File

@ -24,6 +24,7 @@ import webob.exc
from manila.api.openstack import wsgi
from manila import context
from manila.i18n import _
from manila.openstack.common import jsonutils
from manila.openstack.common import log as logging
from manila import wsgi as base_wsgi

View File

@ -19,6 +19,7 @@ import webob.dec
import webob.exc
from manila.api.openstack import wsgi
from manila.i18n import _
from manila.openstack.common import log as logging
from manila import utils
from manila import wsgi as base_wsgi

View File

@ -21,6 +21,7 @@ import webob.dec
import webob.exc
from manila.i18n import _
from manila.openstack.common import log as logging
from manila import wsgi

View File

@ -22,6 +22,7 @@ import routes
from manila.api.openstack import wsgi
from manila.openstack.common import log as logging
from manila.i18n import _
from manila import utils
from manila import wsgi as base_wsgi

View File

@ -16,6 +16,7 @@
from manila.api import urlmap
from manila.openstack.common import log as logging
from manila.i18n import _
LOG = logging.getLogger(__name__)

View File

@ -15,6 +15,7 @@
# under the License.
from manila.api.v1.router import APIRouter as v1_router
from manila.i18n import _
from manila.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -15,6 +15,7 @@
# under the License.
from manila.api import versions
from manila.i18n import _
from manila.openstack.common import log as logging

View File

@ -20,6 +20,7 @@ import time
import webob
from manila import exception
from manila.i18n import _
from manila.openstack.common import jsonutils
from manila.openstack.common import log as logging
from manila import utils

View File

@ -15,6 +15,7 @@
# under the License.
from manila.api.middleware import sizelimit
from manila.i18n import _
from manila.openstack.common import log as logging
LOG = logging.getLogger(__name__)

View File

@ -30,6 +30,7 @@ import webob.exc
from manila.api.openstack import wsgi
from manila.api.views import limits as limits_views
from manila.api import xmlutil
from manila.i18n import _
from manila.openstack.common import importutils
from manila.openstack.common import jsonutils
from manila import quota

View File

@ -26,6 +26,7 @@ from manila.api import xmlutil
from manila.common import constants
from manila import db
from manila import exception
from manila.i18n import _
from manila.openstack.common import log as logging
from manila import policy

View File

@ -19,6 +19,7 @@ from webob import exc
from manila.api import common
from manila.api.openstack import wsgi
from manila import exception
from manila.i18n import _
from manila import share

View File

@ -25,6 +25,7 @@ from manila.api.views import share_networks as share_networks_views
from manila.api import xmlutil
from manila.db import api as db_api
from manila import exception
from manila.i18n import _
from manila.openstack.common import log as logging
from manila import policy
from manila import quota

View File

@ -23,6 +23,7 @@ from manila.api import xmlutil
from manila.common import constants
from manila.db import api as db_api
from manila import exception
from manila.i18n import _
from manila.openstack.common import log as logging
from manila import policy
from manila import share

View File

@ -24,6 +24,7 @@ from manila.api.openstack import wsgi
from manila.api.views import share_snapshots as snapshot_views
from manila.api import xmlutil
from manila import exception
from manila.i18n import _
from manila.openstack.common import log as logging
from manila import share

View File

@ -26,6 +26,7 @@ from manila.api.openstack import wsgi
from manila.api.views import shares as share_views
from manila.api import xmlutil
from manila import exception
from manila.i18n import _
from manila.openstack.common import log as logging
from manila.openstack.common import uuidutils
from manila import share

View File

@ -19,6 +19,7 @@ from webob import exc
from manila.api.openstack import wsgi
from manila.api.views import types as views_types
from manila import exception
from manila.i18n import _
from manila.share import volume_types

View File

@ -18,6 +18,7 @@ import os.path
from lxml import etree
import six
from manila.i18n import _
from manila import utils

View File

@ -29,6 +29,7 @@ import socket
from oslo.config import cfg
from manila.i18n import _
CONF = cfg.CONF

View File

@ -21,6 +21,7 @@ import copy
import six
from manila.i18n import _
from manila.openstack.common import context as common_context
from manila.openstack.common import local
from manila.openstack.common import log as logging

View File

@ -28,6 +28,7 @@ from alembic import op
from sqlalchemy import Boolean, Column, DateTime, ForeignKey
from sqlalchemy import Integer, MetaData, String, Table, UniqueConstraint
from manila.i18n import _
from manila.openstack.common import log as logging

View File

@ -35,6 +35,7 @@ from sqlalchemy.sql import func
from manila.common import constants
from manila.db.sqlalchemy import models
from manila import exception
from manila.i18n import _
from manila.openstack.common import log as logging
from manila.openstack.common import timeutils

View File

@ -26,6 +26,7 @@ from oslo.config import cfg
import six
import webob.exc
from manila.i18n import _
from manila.openstack.common import log as logging
from manila.openstack.common import processutils

71
manila/i18n.py Normal file
View File

@ -0,0 +1,71 @@
# Copyright 2014 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""oslo.i18n integration module.
See http://docs.openstack.org/developer/oslo.i18n/usage.html .
"""
from oslo import i18n
from manila.openstack.common import gettextutils
DOMAIN = 'manila'
_translators = i18n.TranslatorFactory(domain=DOMAIN)
# The primary translation function using the well-known name "_"
_ = _translators.primary
# Translators for log levels.
#
# The abbreviated names are meant to reflect the usual use of a short
# name like '_'. The "L" is for "log" and the other letter comes from
# the level.
_LI = _translators.log_info
_LW = _translators.log_warning
_LE = _translators.log_error
_LC = _translators.log_critical
def enable_lazy():
return i18n.enable_lazy()
def translate(value, user_locale):
return i18n.translate(value, user_locale)
def get_available_languages():
return i18n.get_available_languages(DOMAIN)
# Parts in oslo-incubator are still using gettextutils._(), _LI(), etc., from
# oslo-incubator. Until these parts are changed to use oslo.i18n, Manila
# needs to do something to allow them to work. One option is to continue to
# initialize gettextutils, but with the way that manila has initialization
# spread out over multiple entry points, we'll monkey-patch
# gettextutils._(), _LI(), etc., to use our oslo.i18n versions.
# FIXME(jaegerandi): Remove the monkey-patching and update
# openstack-common.conf and do a sync with oslo-incubator to remove
# gettextutils once oslo-incubator isn't using oslo-incubator
# gettextutils any more.
gettextutils._ = _
gettextutils._LI = _LI
gettextutils._LW = _LW
gettextutils._LE = _LE
gettextutils._LC = _LC

View File

@ -55,6 +55,7 @@ from oslo.config import cfg
import six
from manila.db import base
from manila.i18n import _
from manila.openstack.common import log as logging
from manila.scheduler import rpcapi as scheduler_rpcapi
from manila import version

View File

@ -20,6 +20,7 @@ from oslo.config import cfg
import six
from manila import exception
from manila.i18n import _
from manila.network.linux import ip_lib
from manila.network.linux import ovs_lib
from manila.openstack.common import log as logging

View File

@ -16,6 +16,7 @@
import netaddr
import six
from manila.i18n import _
from manila import utils

View File

@ -15,6 +15,7 @@
import re
from manila.i18n import _
from manila.openstack.common import log as logging
from manila import utils

View File

@ -19,6 +19,7 @@ from oslo.config import cfg
from manila import context
from manila.db import base
from manila import exception
from manila.i18n import _
from manila.network import neutron
from manila.network.neutron import constants as neutron_constants
from manila.openstack.common import log as logging

View File

@ -23,6 +23,7 @@ import six
from manila import db
from manila import exception
from manila.i18n import _
from manila.openstack.common import importutils
from manila.openstack.common import log as logging
from manila.openstack.common import timeutils

View File

@ -24,6 +24,7 @@ import random
from oslo.config import cfg
from manila import exception
from manila.i18n import _
from manila.scheduler import driver
CONF = cfg.CONF

View File

@ -22,6 +22,7 @@ Scheduler base class that all Schedulers should inherit from
from oslo.config import cfg
from manila import db
from manila.i18n import _
from manila.openstack.common import importutils
from manila.openstack.common import timeutils
from manila.share import rpcapi as share_rpcapi

View File

@ -23,6 +23,7 @@ Weighing Functions.
from oslo.config import cfg
from manila import exception
from manila.i18n import _
from manila.openstack.common import log as logging
from manila.scheduler import driver
from manila.scheduler import scheduler_options

View File

@ -18,6 +18,7 @@
import math
from manila.i18n import _
from manila.openstack.common import log as logging
from manila.openstack.common.scheduler import filters

View File

@ -24,6 +24,7 @@ import six
from manila import db
from manila import exception
from manila.i18n import _
from manila.openstack.common import log as logging
from manila.openstack.common.scheduler import filters
from manila.openstack.common.scheduler import weights

View File

@ -24,6 +24,7 @@ from oslo.config import cfg
from manila import context
from manila import db
from manila import exception
from manila.i18n import _
from manila import manager
from manila.openstack.common import excutils
from manila.openstack.common import importutils

View File

@ -25,6 +25,7 @@ import os
from oslo.config import cfg
from manila.i18n import _
from manila.openstack.common import jsonutils
from manila.openstack.common import log as logging
from manila.openstack.common import timeutils

View File

@ -23,6 +23,7 @@ from oslo.config import cfg
from manila import db
from manila import exception
from manila.i18n import _
from manila.scheduler import chance
from manila.scheduler import driver
from manila import utils

View File

@ -33,6 +33,7 @@ from oslo import messaging
from manila import context
from manila import db
from manila import exception
from manila.i18n import _
from manila.openstack.common import importutils
from manila.openstack.common import log as logging
from manila.openstack.common import loopingcall

View File

@ -24,6 +24,7 @@ import six
from manila.api import extensions
from manila.db import base
from manila import exception
from manila.i18n import _
from manila.openstack.common import excutils
from manila.openstack.common import log as logging
from manila.openstack.common import timeutils

View File

@ -20,6 +20,7 @@ Drivers for shares.
import time
from manila import exception
from manila.i18n import _
from manila.openstack.common import log as logging
from manila import utils

View File

@ -18,6 +18,7 @@ import six
from manila import db as manila_db
from manila import exception
from manila.i18n import _
from manila.openstack.common import excutils
from manila.openstack.common import log
from manila.share.drivers.emc.plugins import base as driver

View File

@ -22,6 +22,7 @@ from six.moves.urllib import error as url_error # pylint: disable=E0611
from six.moves.urllib import request as url_request # pylint: disable=E0611
import manila.exception
from manila.i18n import _
from manila.openstack.common import lockutils
from manila.openstack.common import log as logging
from manila.share.drivers.emc.plugins.vnx import constants

View File

@ -15,6 +15,7 @@
import types
import xml.dom.minidom
from manila.i18n import _
from manila.openstack.common import log

View File

@ -26,6 +26,7 @@ from manila.common import constants as const
from manila import compute
from manila import context
from manila import exception
from manila.i18n import _
from manila.openstack.common import excutils
from manila.openstack.common import importutils
from manila.openstack.common import log as logging

View File

@ -30,6 +30,7 @@ import re
import xml.etree.cElementTree as etree
from manila import exception
from manila.i18n import _
from manila.openstack.common import log as logging
from manila.share import driver

View File

@ -34,6 +34,7 @@ from oslo.config import cfg
import six
from manila import exception
from manila.i18n import _
from manila.openstack.common import log as logging
from manila.share import driver
from manila.share.drivers import glusterfs

View File

@ -22,6 +22,7 @@ import urllib2
from lxml import etree
from manila.i18n import _
from manila.openstack.common import log

View File

@ -29,6 +29,7 @@ import six
from manila import context
from manila import exception
from manila.i18n import _
from manila.openstack.common import excutils
from manila.openstack.common import log
from manila.share import driver

View File

@ -28,6 +28,7 @@ from manila.common import constants
from manila import compute
from manila import context
from manila import exception
from manila.i18n import _
from manila.network.linux import ip_lib
from manila.network.neutron import api as neutron
from manila.openstack.common import importutils

View File

@ -25,6 +25,7 @@ import six
from manila.common import constants
from manila import context
from manila import exception
from manila.i18n import _
from manila import manager
from manila import network
from manila.openstack.common import excutils

View File

@ -22,6 +22,7 @@ import six
from manila import context
from manila import db
from manila import exception
from manila.i18n import _
from manila.openstack.common import log as logging
CONF = cfg.CONF

View File

@ -24,6 +24,7 @@ from oslo.db.sqlalchemy import test_migrations
from sqlalchemy.sql import text
from manila.db.migrations.alembic import migration
from manila.i18n import _
from manila.openstack.common import log as logging
LOG = logging.getLogger('manila.tests.test_migrations')

View File

@ -15,6 +15,7 @@
import httplib
import urlparse
from manila.i18n import _
from manila.openstack.common import jsonutils
from manila.openstack.common import log as logging

View File

@ -43,6 +43,7 @@ import paramiko
import six
from manila import exception
from manila.i18n import _
from manila.openstack.common import excutils
from manila.openstack.common import importutils
from manila.openstack.common import lockutils

View File

@ -27,6 +27,7 @@ from oslo.config import cfg
from manila.db import base
from manila import exception
from manila.i18n import _
from manila.openstack.common import log as logging

View File

@ -37,6 +37,7 @@ import webob.dec
import webob.exc
from manila import exception
from manila.i18n import _
from manila.openstack.common import log as logging
socket_opts = [

View File

@ -6,7 +6,6 @@ module=context
module=eventlet_backdoor
module=excutils
module=fileutils
module=gettextutils
module=importutils
module=jsonutils
module=local

View File

@ -47,3 +47,7 @@ commands = bash tools/lintstack.sh
ignore = H904
builtins = _
exclude = .venv,.tox,dist,doc,openstack,*egg
[hacking]
import_exceptions =
manila.i18n