Addresses glance/+spec/i18n

Added gettext.install to glance endpoints, setup.py, and run_tests.py. Wrapped all exceptions in common/exception.py with gettext.

Included fix for bug lp:823676.

Change-Id: Ied4381e1676227afea857acd01f4754e6a181106
This commit is contained in:
Justin Shepherd 2011-08-06 12:28:27 -05:00
parent de78df9020
commit 8a33e24311
13 changed files with 59 additions and 10 deletions

View File

@ -23,6 +23,7 @@ stored in one or more Glance nodes.
"""
import functools
import gettext
import optparse
import os
import re
@ -37,6 +38,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
sys.path.insert(0, possible_topdir)
gettext.install('glance', unicode=1)
from glance import client as glance_client
from glance import version
from glance.common import exception

View File

@ -22,6 +22,7 @@
Glance API Server
"""
import gettext
import optparse
import os
import sys
@ -34,6 +35,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
sys.path.insert(0, possible_topdir)
gettext.install('glance', unicode=1)
from glance import version
from glance.common import config
from glance.common import wsgi

View File

@ -24,6 +24,7 @@ Glance Image Cache Pre-fetcher
This is meant to be run as a periodic task from cron.
"""
import gettext
import optparse
import os
import sys
@ -36,6 +37,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
sys.path.insert(0, possible_topdir)
gettext.install('glance', unicode=1)
from glance import version
from glance.common import config
from glance.common import wsgi

View File

@ -24,6 +24,7 @@ Glance Image Cache Pruner
This is meant to be run as a periodic task, perhaps every half-hour.
"""
import gettext
import optparse
import os
import sys
@ -36,6 +37,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
sys.path.insert(0, possible_topdir)
gettext.install('glance', unicode=1)
from glance import version
from glance.common import config
from glance.common import wsgi

View File

@ -32,6 +32,7 @@ Also, if an incomplete image hangs around past the image_cache_stall_timeout
period, we automatically sweep it up.
"""
import gettext
import optparse
import os
import sys
@ -44,6 +45,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
sys.path.insert(0, possible_topdir)
gettext.install('glance', unicode=1)
from glance import version
from glance.common import config
from glance.common import wsgi

View File

@ -24,6 +24,7 @@ Thanks for some of the code, Swifties ;)
from __future__ import with_statement
import errno
import gettext
import os
import optparse
import resource
@ -39,6 +40,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
sys.path.insert(0, possible_topdir)
gettext.install('glance', unicode=1)
from glance import version
from glance.common import config

View File

@ -26,6 +26,7 @@ Glance Management Utility
# Perhaps for consistency with Nova, we would then rename glance-admin ->
# glance-manage (or the other way around)
import gettext
import optparse
import os
import sys
@ -38,6 +39,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
sys.path.insert(0, possible_topdir)
gettext.install('glance', unicode=1)
from glance import version as glance_version
from glance.common import config
from glance.common import exception

View File

@ -22,6 +22,7 @@
Reference implementation server for Glance Registry
"""
import gettext
import optparse
import os
import sys
@ -34,6 +35,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
sys.path.insert(0, possible_topdir)
gettext.install('glance', unicode=1)
from glance import version
from glance.common import config
from glance.common import wsgi

View File

@ -20,6 +20,7 @@
Glance Scrub Service
"""
import gettext
import optparse
import os
import sys
@ -32,6 +33,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
sys.path.insert(0, possible_topdir)
gettext.install('glance', unicode=1)
from glance import version
from glance.common import config
from glance.store import scrubber

View File

@ -47,6 +47,7 @@ Usage
# FIXME(sirp): This can be merged into glance-admin when that becomes
# available
import argparse
import gettext
import pprint
import os
import sys
@ -59,6 +60,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
sys.path.insert(0, possible_topdir)
gettext.install('glance', unicode=1)
from glance.client import Client
from glance.registry.db.api import DISK_FORMATS, CONTAINER_FORMATS

View File

@ -33,8 +33,8 @@ class ProcessExecutionError(IOError):
description = "Unexpected error while running command."
if exit_code is None:
exit_code = '-'
message = "%s\nCommand: %s\nExit code: %s\nStdout: %r\nStderr: %r" % (
description, cmd, exit_code, stdout, stderr)
message = _("%s\nCommand: %s\nExit code: %s\nStdout: %r\nStderr: %r")\
% (description, cmd, exit_code, stdout, stderr)
IOError.__init__(self, message)
@ -56,7 +56,7 @@ class NotFound(Error):
class UnknownScheme(Error):
msg = "Unknown scheme '%s' found in URI"
msg = _("Unknown scheme '%s' found in URI")
def __init__(self, scheme):
msg = self.__class__.msg % scheme
@ -65,7 +65,7 @@ class UnknownScheme(Error):
class BadStoreUri(Error):
msg = "The Store URI %s was malformed. Reason: %s"
msg = _("The Store URI %s was malformed. Reason: %s")
def __init__(self, uri, reason):
msg = self.__class__.msg % (uri, reason)
@ -129,7 +129,7 @@ class GlanceException(Exception):
a 'message' property. That message will get printf'd
with the keyword arguments provided to the constructor.
"""
message = "An unknown exception occurred"
message = _("An unknown exception occurred")
def __init__(self, **kwargs):
try:
@ -144,18 +144,18 @@ class GlanceException(Exception):
class InvalidContentType(GlanceException):
message = "Invalid content type %(content_type)s"
message = _("Invalid content type %(content_type)s")
class BadStoreConfiguration(GlanceException):
message = ("Store %(store_name)s could not be configured correctly. "
message = _("Store %(store_name)s could not be configured correctly. "
"Reason: %(reason)s")
class StoreDeleteNotSupported(GlanceException):
message = ("Deleting images from this store is not supported.")
message = _("Deleting images from this store is not supported.")
class StoreAddDisabled(GlanceException):
message = ("Configuration for store failed. Adding images to this "
message = _("Configuration for store failed. Adding images to this "
"store is disabled.")

View File

@ -57,6 +57,8 @@ import os
import unittest
import sys
gettext.install('glance', unicode=1)
from nose import config
from nose import result
from nose import core

View File

@ -14,12 +14,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import gettext
import os
import subprocess
from setuptools import setup, find_packages
from setuptools.command.sdist import sdist
# In order to run the i18n commands for compiling and
# installing message catalogs, we use DistUtilsExtra.
# Don't make this a hard requirement, but warn that
# i18n commands won't be available if DistUtilsExtra is
# not installed...
try:
from DistUtilsExtra.auto import setup
except ImportError:
from setuptools import setup
print "Warning: DistUtilsExtra required to use i18n builders. "
print "To build glance with support for message catalogs, you need "
print " https://launchpad.net/python-distutils-extra >= 2.18"
gettext.install('glance', unicode=1)
from glance import version
@ -110,4 +126,5 @@ setup(
'bin/glance-manage',
'bin/glance-registry',
'bin/glance-scrubber',
'bin/glance-upload'])
'bin/glance-upload'],
py_modules=[])