Synch up with OSLO-Incubator
Wanted to get updates before next push to pypi. The main thing driving this is we're now calling in some methods from strutils and gettextutils that don't have the py33 updates. Change-Id: I358f08f5c5c0a9ee6729947a8f01b1e96de0a729
This commit is contained in:
parent
5ad95e9fd2
commit
945b211cd0
@ -1,7 +1,7 @@
|
|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||||
|
|
||||||
# Copyright 2010 Jacob Kaplan-Moss
|
# Copyright 2010 Jacob Kaplan-Moss
|
||||||
# Copyright 2011 OpenStack LLC
|
# Copyright 2011 OpenStack Foundation
|
||||||
# Copyright 2012 Grid Dynamics
|
# Copyright 2012 Grid Dynamics
|
||||||
# Copyright 2013 OpenStack Foundation
|
# Copyright 2013 OpenStack Foundation
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||||
|
|
||||||
# Copyright 2010 Jacob Kaplan-Moss
|
# Copyright 2010 Jacob Kaplan-Moss
|
||||||
# Copyright 2011 OpenStack LLC
|
# Copyright 2011 OpenStack Foundation
|
||||||
# Copyright 2011 Piston Cloud Computing, Inc.
|
# Copyright 2011 Piston Cloud Computing, Inc.
|
||||||
# Copyright 2013 Alessio Ababilov
|
# Copyright 2013 Alessio Ababilov
|
||||||
# Copyright 2013 Grid Dynamics
|
# Copyright 2013 Grid Dynamics
|
||||||
|
@ -26,10 +26,13 @@ Usual usage in an openstack.common module:
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
import gettext
|
import gettext
|
||||||
import logging.handlers
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import UserString
|
try:
|
||||||
|
import UserString as _userString
|
||||||
|
except ImportError:
|
||||||
|
import collections as _userString
|
||||||
|
|
||||||
from babel import localedata
|
from babel import localedata
|
||||||
import six
|
import six
|
||||||
@ -37,10 +40,28 @@ import six
|
|||||||
_localedir = os.environ.get('cinderclient'.upper() + '_LOCALEDIR')
|
_localedir = os.environ.get('cinderclient'.upper() + '_LOCALEDIR')
|
||||||
_t = gettext.translation('cinderclient', localedir=_localedir, fallback=True)
|
_t = gettext.translation('cinderclient', localedir=_localedir, fallback=True)
|
||||||
|
|
||||||
_AVAILABLE_LANGUAGES = []
|
_AVAILABLE_LANGUAGES = {}
|
||||||
|
USE_LAZY = False
|
||||||
|
|
||||||
|
|
||||||
|
def enable_lazy():
|
||||||
|
"""Convenience function for configuring _() to use lazy gettext
|
||||||
|
|
||||||
|
Call this at the start of execution to enable the gettextutils._
|
||||||
|
function to use lazy gettext functionality. This is useful if
|
||||||
|
your project is importing _ directly instead of using the
|
||||||
|
gettextutils.install() way of importing the _ function.
|
||||||
|
"""
|
||||||
|
global USE_LAZY
|
||||||
|
USE_LAZY = True
|
||||||
|
|
||||||
|
|
||||||
def _(msg):
|
def _(msg):
|
||||||
|
if USE_LAZY:
|
||||||
|
return Message(msg, 'cinderclient')
|
||||||
|
else:
|
||||||
|
if six.PY3:
|
||||||
|
return _t.gettext(msg)
|
||||||
return _t.ugettext(msg)
|
return _t.ugettext(msg)
|
||||||
|
|
||||||
|
|
||||||
@ -86,24 +107,28 @@ def install(domain, lazy=False):
|
|||||||
"""
|
"""
|
||||||
return Message(msg, domain)
|
return Message(msg, domain)
|
||||||
|
|
||||||
import __builtin__
|
from six import moves
|
||||||
__builtin__.__dict__['_'] = _lazy_gettext
|
moves.builtins.__dict__['_'] = _lazy_gettext
|
||||||
else:
|
else:
|
||||||
localedir = '%s_LOCALEDIR' % domain.upper()
|
localedir = '%s_LOCALEDIR' % domain.upper()
|
||||||
|
if six.PY3:
|
||||||
|
gettext.install(domain,
|
||||||
|
localedir=os.environ.get(localedir))
|
||||||
|
else:
|
||||||
gettext.install(domain,
|
gettext.install(domain,
|
||||||
localedir=os.environ.get(localedir),
|
localedir=os.environ.get(localedir),
|
||||||
unicode=True)
|
unicode=True)
|
||||||
|
|
||||||
|
|
||||||
class Message(UserString.UserString, object):
|
class Message(_userString.UserString, object):
|
||||||
"""Class used to encapsulate translatable messages."""
|
"""Class used to encapsulate translatable messages."""
|
||||||
def __init__(self, msg, domain):
|
def __init__(self, msg, domain):
|
||||||
# _msg is the gettext msgid and should never change
|
# _msg is the gettext msgid and should never change
|
||||||
self._msg = msg
|
self._msg = msg
|
||||||
self._left_extra_msg = ''
|
self._left_extra_msg = ''
|
||||||
self._right_extra_msg = ''
|
self._right_extra_msg = ''
|
||||||
|
self._locale = None
|
||||||
self.params = None
|
self.params = None
|
||||||
self.locale = None
|
|
||||||
self.domain = domain
|
self.domain = domain
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -123,8 +148,13 @@ class Message(UserString.UserString, object):
|
|||||||
localedir=localedir,
|
localedir=localedir,
|
||||||
fallback=True)
|
fallback=True)
|
||||||
|
|
||||||
|
if six.PY3:
|
||||||
|
ugettext = lang.gettext
|
||||||
|
else:
|
||||||
|
ugettext = lang.ugettext
|
||||||
|
|
||||||
full_msg = (self._left_extra_msg +
|
full_msg = (self._left_extra_msg +
|
||||||
lang.ugettext(self._msg) +
|
ugettext(self._msg) +
|
||||||
self._right_extra_msg)
|
self._right_extra_msg)
|
||||||
|
|
||||||
if self.params is not None:
|
if self.params is not None:
|
||||||
@ -132,6 +162,33 @@ class Message(UserString.UserString, object):
|
|||||||
|
|
||||||
return six.text_type(full_msg)
|
return six.text_type(full_msg)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def locale(self):
|
||||||
|
return self._locale
|
||||||
|
|
||||||
|
@locale.setter
|
||||||
|
def locale(self, value):
|
||||||
|
self._locale = value
|
||||||
|
if not self.params:
|
||||||
|
return
|
||||||
|
|
||||||
|
# This Message object may have been constructed with one or more
|
||||||
|
# Message objects as substitution parameters, given as a single
|
||||||
|
# Message, or a tuple or Map containing some, so when setting the
|
||||||
|
# locale for this Message we need to set it for those Messages too.
|
||||||
|
if isinstance(self.params, Message):
|
||||||
|
self.params.locale = value
|
||||||
|
return
|
||||||
|
if isinstance(self.params, tuple):
|
||||||
|
for param in self.params:
|
||||||
|
if isinstance(param, Message):
|
||||||
|
param.locale = value
|
||||||
|
return
|
||||||
|
if isinstance(self.params, dict):
|
||||||
|
for param in self.params.values():
|
||||||
|
if isinstance(param, Message):
|
||||||
|
param.locale = value
|
||||||
|
|
||||||
def _save_dictionary_parameter(self, dict_param):
|
def _save_dictionary_parameter(self, dict_param):
|
||||||
full_msg = self.data
|
full_msg = self.data
|
||||||
# look for %(blah) fields in string;
|
# look for %(blah) fields in string;
|
||||||
@ -150,7 +207,7 @@ class Message(UserString.UserString, object):
|
|||||||
params[key] = copy.deepcopy(dict_param[key])
|
params[key] = copy.deepcopy(dict_param[key])
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# cast uncopyable thing to unicode string
|
# cast uncopyable thing to unicode string
|
||||||
params[key] = unicode(dict_param[key])
|
params[key] = six.text_type(dict_param[key])
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
|
||||||
@ -169,7 +226,7 @@ class Message(UserString.UserString, object):
|
|||||||
try:
|
try:
|
||||||
self.params = copy.deepcopy(other)
|
self.params = copy.deepcopy(other)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
self.params = unicode(other)
|
self.params = six.text_type(other)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@ -178,11 +235,13 @@ class Message(UserString.UserString, object):
|
|||||||
return self.data
|
return self.data
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
if six.PY3:
|
||||||
|
return self.__unicode__()
|
||||||
return self.data.encode('utf-8')
|
return self.data.encode('utf-8')
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
to_copy = ['_msg', '_right_extra_msg', '_left_extra_msg',
|
to_copy = ['_msg', '_right_extra_msg', '_left_extra_msg',
|
||||||
'domain', 'params', 'locale']
|
'domain', 'params', '_locale']
|
||||||
new_dict = self.__dict__.fromkeys(to_copy)
|
new_dict = self.__dict__.fromkeys(to_copy)
|
||||||
for attr in to_copy:
|
for attr in to_copy:
|
||||||
new_dict[attr] = copy.deepcopy(self.__dict__[attr])
|
new_dict[attr] = copy.deepcopy(self.__dict__[attr])
|
||||||
@ -236,7 +295,7 @@ class Message(UserString.UserString, object):
|
|||||||
if name in ops:
|
if name in ops:
|
||||||
return getattr(self.data, name)
|
return getattr(self.data, name)
|
||||||
else:
|
else:
|
||||||
return UserString.UserString.__getattribute__(self, name)
|
return _userString.UserString.__getattribute__(self, name)
|
||||||
|
|
||||||
|
|
||||||
def get_available_languages(domain):
|
def get_available_languages(domain):
|
||||||
@ -244,8 +303,8 @@ def get_available_languages(domain):
|
|||||||
|
|
||||||
:param domain: the domain to get languages for
|
:param domain: the domain to get languages for
|
||||||
"""
|
"""
|
||||||
if _AVAILABLE_LANGUAGES:
|
if domain in _AVAILABLE_LANGUAGES:
|
||||||
return _AVAILABLE_LANGUAGES
|
return copy.copy(_AVAILABLE_LANGUAGES[domain])
|
||||||
|
|
||||||
localedir = '%s_LOCALEDIR' % domain.upper()
|
localedir = '%s_LOCALEDIR' % domain.upper()
|
||||||
find = lambda x: gettext.find(domain,
|
find = lambda x: gettext.find(domain,
|
||||||
@ -254,7 +313,7 @@ def get_available_languages(domain):
|
|||||||
|
|
||||||
# NOTE(mrodden): en_US should always be available (and first in case
|
# NOTE(mrodden): en_US should always be available (and first in case
|
||||||
# order matters) since our in-line message strings are en_US
|
# order matters) since our in-line message strings are en_US
|
||||||
_AVAILABLE_LANGUAGES.append('en_US')
|
language_list = ['en_US']
|
||||||
# NOTE(luisg): Babel <1.0 used a function called list(), which was
|
# NOTE(luisg): Babel <1.0 used a function called list(), which was
|
||||||
# renamed to locale_identifiers() in >=1.0, the requirements master list
|
# renamed to locale_identifiers() in >=1.0, the requirements master list
|
||||||
# requires >=0.9.6, uncapped, so defensively work with both. We can remove
|
# requires >=0.9.6, uncapped, so defensively work with both. We can remove
|
||||||
@ -264,16 +323,17 @@ def get_available_languages(domain):
|
|||||||
locale_identifiers = list_identifiers()
|
locale_identifiers = list_identifiers()
|
||||||
for i in locale_identifiers:
|
for i in locale_identifiers:
|
||||||
if find(i) is not None:
|
if find(i) is not None:
|
||||||
_AVAILABLE_LANGUAGES.append(i)
|
language_list.append(i)
|
||||||
return _AVAILABLE_LANGUAGES
|
_AVAILABLE_LANGUAGES[domain] = language_list
|
||||||
|
return copy.copy(language_list)
|
||||||
|
|
||||||
|
|
||||||
def get_localized_message(message, user_locale):
|
def get_localized_message(message, user_locale):
|
||||||
"""Gets a localized version of the given message in the given locale."""
|
"""Gets a localized version of the given message in the given locale."""
|
||||||
if (isinstance(message, Message)):
|
if isinstance(message, Message):
|
||||||
if user_locale:
|
if user_locale:
|
||||||
message.locale = user_locale
|
message.locale = user_locale
|
||||||
return unicode(message)
|
return six.text_type(message)
|
||||||
else:
|
else:
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
@ -119,8 +119,7 @@ class InstallVenv(object):
|
|||||||
self.pip_install('setuptools')
|
self.pip_install('setuptools')
|
||||||
self.pip_install('pbr')
|
self.pip_install('pbr')
|
||||||
|
|
||||||
self.pip_install('-r', self.requirements)
|
self.pip_install('-r', self.requirements, '-r', self.test_requirements)
|
||||||
self.pip_install('-r', self.test_requirements)
|
|
||||||
|
|
||||||
def post_process(self):
|
def post_process(self):
|
||||||
self.get_distro().post_process()
|
self.get_distro().post_process()
|
||||||
@ -202,6 +201,7 @@ class Fedora(Distro):
|
|||||||
RHEL: https://bugzilla.redhat.com/958868
|
RHEL: https://bugzilla.redhat.com/958868
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if os.path.exists('contrib/redhat-eventlet.patch'):
|
||||||
# Install "patch" program if it's not there
|
# Install "patch" program if it's not there
|
||||||
if not self.check_pkg('patch'):
|
if not self.check_pkg('patch'):
|
||||||
self.die("Please install 'patch'.")
|
self.die("Please install 'patch'.")
|
||||||
|
Loading…
Reference in New Issue
Block a user