Completed first pass at converting all localized strings with multiple format substitutions.

This commit is contained in:
Ed Leafe
2011-01-18 21:00:28 -05:00
parent 3396f88fe1
commit d70f915ace
7 changed files with 65 additions and 48 deletions

View File

@@ -55,7 +55,7 @@ def run_app(paste_config_file):
if config is None: if config is None:
LOG.debug(_("No paste configuration for app: %s"), api) LOG.debug(_("No paste configuration for app: %s"), api)
continue continue
LOG.debug(_("App Config: %s\n%r"), api, config) LOG.debug(_("App Config: %(api)s\n%(config)r") % locals())
wsgi.paste_config_to_flags(config, { wsgi.paste_config_to_flags(config, {
"verbose": FLAGS.verbose, "verbose": FLAGS.verbose,
"%s_host" % api: config.get('host', '0.0.0.0'), "%s_host" % api: config.get('host', '0.0.0.0'),

View File

@@ -120,9 +120,9 @@ def main():
mac = argv[2] mac = argv[2]
ip = argv[3] ip = argv[3]
hostname = argv[4] hostname = argv[4]
LOG.debug(_("Called %s for mac %s with ip %s and " msg = _("Called %(action)s for mac %(mac)s with ip %(ip)s and"
"hostname %s on interface %s"), " hostname %(hostname)s on interface %(interface)s") % locals()
action, mac, ip, hostname, interface) LOG.debug(msg)
globals()[action + '_lease'](mac, ip, hostname, interface) globals()[action + '_lease'](mac, ip, hostname, interface)
else: else:
print init_leases(interface) print init_leases(interface)

View File

@@ -473,8 +473,8 @@ class LdapDriver(object):
raise exception.NotFound("The group at dn %s doesn't exist" % raise exception.NotFound("The group at dn %s doesn't exist" %
group_dn) group_dn)
if self.__is_in_group(uid, group_dn): if self.__is_in_group(uid, group_dn):
raise exception.Duplicate(_("User %s is already a member of " raise exception.Duplicate(_("User %(uid)s is already a member of "
"the group %s") % (uid, group_dn)) "the group %(group_dn)s") % locals())
attr = [(self.ldap.MOD_ADD, 'member', self.__uid_to_dn(uid))] attr = [(self.ldap.MOD_ADD, 'member', self.__uid_to_dn(uid))]
self.conn.modify_s(group_dn, attr) self.conn.modify_s(group_dn, attr)

View File

@@ -272,16 +272,22 @@ class AuthManager(object):
project = self.get_project(project_id) project = self.get_project(project_id)
if project == None: if project == None:
LOG.audit(_("failed authorization: no project named %s (user=%s)"), pjid = project_id
project_id, user.name) uname = user.name
LOG.audit(_("failed authorization: no project named %(pjid)s"
" (user=%(uname)s)") % locals())
raise exception.NotFound(_('No project called %s could be found') raise exception.NotFound(_('No project called %s could be found')
% project_id) % project_id)
if not self.is_admin(user) and not self.is_project_member(user, if not self.is_admin(user) and not self.is_project_member(user,
project): project):
LOG.audit(_("Failed authorization: user %s not admin and not " uname = user.name
"member of project %s"), user.name, project.name) uid = user.id
raise exception.NotFound(_('User %s is not a member of project %s') pjname = project.name
% (user.id, project.id)) pjid = project.id
LOG.audit(_("Failed authorization: user %(uname)s not admin"
" and not member of project %(pjname)s") % locals())
raise exception.NotFound(_('User %(uid)s is not a member of'
' project %(pjid)s') % locals())
if check_type == 's3': if check_type == 's3':
sign = signer.Signer(user.secret.encode()) sign = signer.Signer(user.secret.encode())
expected_signature = sign.s3_authorization(headers, verb, path) expected_signature = sign.s3_authorization(headers, verb, path)
@@ -408,14 +414,16 @@ class AuthManager(object):
raise exception.NotFound(_("The %s role can not be found") % role) raise exception.NotFound(_("The %s role can not be found") % role)
if project is not None and role in FLAGS.global_roles: if project is not None and role in FLAGS.global_roles:
raise exception.NotFound(_("The %s role is global only") % role) raise exception.NotFound(_("The %s role is global only") % role)
uid = User.safe_id(user)
pid = Project.safe_id(project)
if project: if project:
LOG.audit(_("Adding role %s to user %s in project %s"), role, LOG.audit(_("Adding role %(role)s to user %(uid)s"
User.safe_id(user), Project.safe_id(project)) " in project %(pid)s") % locals())
else: else:
LOG.audit(_("Adding sitewide role %s to user %s"), role, LOG.audit(_("Adding sitewide role %(role)s to user %(uid)s")
User.safe_id(user)) % locals())
with self.driver() as drv: with self.driver() as drv:
drv.add_role(User.safe_id(user), role, Project.safe_id(project)) drv.add_role(uid, role, pid)
def remove_role(self, user, role, project=None): def remove_role(self, user, role, project=None):
"""Removes role for user """Removes role for user
@@ -434,14 +442,16 @@ class AuthManager(object):
@type project: Project or project_id @type project: Project or project_id
@param project: Project in which to remove local role. @param project: Project in which to remove local role.
""" """
uid = User.safe_id(user)
pid = Project.safe_id(project)
if project: if project:
LOG.audit(_("Removing role %s from user %s on project %s"), LOG.audit(_("Removing role %(role)s from user %(uid)s"
role, User.safe_id(user), Project.safe_id(project)) " on project %(pid)s") % locals())
else: else:
LOG.audit(_("Removing sitewide role %s from user %s"), role, LOG.audit(_("Removing sitewide role %(role)s"
User.safe_id(user)) " from user %(uid)s") % locals())
with self.driver() as drv: with self.driver() as drv:
drv.remove_role(User.safe_id(user), role, Project.safe_id(project)) drv.remove_role(uid, role, pid)
@staticmethod @staticmethod
def get_roles(project_roles=True): def get_roles(project_roles=True):
@@ -502,8 +512,8 @@ class AuthManager(object):
description, description,
member_users) member_users)
if project_dict: if project_dict:
LOG.audit(_("Created project %s with manager %s"), name, LOG.audit(_("Created project %(name)s with"
manager_user) " manager %(manager_user)s") % locals())
project = Project(**project_dict) project = Project(**project_dict)
return project return project
@@ -530,8 +540,9 @@ class AuthManager(object):
def add_to_project(self, user, project): def add_to_project(self, user, project):
"""Add user to project""" """Add user to project"""
LOG.audit(_("Adding user %s to project %s"), User.safe_id(user), uid = User.safe_id(user)
Project.safe_id(project)) pid = Project.safe_id(project)
LOG.audit(_("Adding user %(uid)s to project %(pid)s") % locals())
with self.driver() as drv: with self.driver() as drv:
return drv.add_to_project(User.safe_id(user), return drv.add_to_project(User.safe_id(user),
Project.safe_id(project)) Project.safe_id(project))
@@ -550,11 +561,11 @@ class AuthManager(object):
def remove_from_project(self, user, project): def remove_from_project(self, user, project):
"""Removes a user from a project""" """Removes a user from a project"""
LOG.audit(_("Remove user %s from project %s"), User.safe_id(user), uid = User.safe_id(user)
Project.safe_id(project)) pid = Project.safe_id(project)
LOG.audit(_("Remove user %(uid)s from project %(pid)s") % locals())
with self.driver() as drv: with self.driver() as drv:
return drv.remove_from_project(User.safe_id(user), return drv.remove_from_project(uid, pid)
Project.safe_id(project))
@staticmethod @staticmethod
def get_project_vpn_data(project): def get_project_vpn_data(project):
@@ -634,7 +645,10 @@ class AuthManager(object):
user_dict = drv.create_user(name, access, secret, admin) user_dict = drv.create_user(name, access, secret, admin)
if user_dict: if user_dict:
rv = User(**user_dict) rv = User(**user_dict)
LOG.audit(_("Created user %s (admin: %r)"), rv.name, rv.admin) rvname = rv.name
rvadmin = rv.admin
LOG.audit(_("Created user %(rvname)s"
" (admin: %(rvadmin)r)") % locals())
return rv return rv
def delete_user(self, user): def delete_user(self, user):
@@ -656,7 +670,8 @@ class AuthManager(object):
if secret_key: if secret_key:
LOG.audit(_("Secret Key change for user %s"), uid) LOG.audit(_("Secret Key change for user %s"), uid)
if admin is not None: if admin is not None:
LOG.audit(_("Admin status set to %r for user %s"), admin, uid) LOG.audit(_("Admin status set to %(admin)r"
" for user %(uid)s") % locals())
with self.driver() as drv: with self.driver() as drv:
drv.modify_user(uid, access_key, secret_key, admin) drv.modify_user(uid, access_key, secret_key, admin)

View File

@@ -45,8 +45,9 @@ class Exchange(object):
self._routes = {} self._routes = {}
def publish(self, message, routing_key=None): def publish(self, message, routing_key=None):
LOG.debug(_('(%s) publish (key: %s) %s'), nm = self.name
self.name, routing_key, message) LOG.debug(_('(%(nm)s) publish (key: %(routing_key)s)'
' %(message)s') % locals())
routing_key = routing_key.split('.')[0] routing_key = routing_key.split('.')[0]
if routing_key in self._routes: if routing_key in self._routes:
for f in self._routes[routing_key]: for f in self._routes[routing_key]:
@@ -92,8 +93,8 @@ class Backend(base.BaseBackend):
def queue_bind(self, queue, exchange, routing_key, **kwargs): def queue_bind(self, queue, exchange, routing_key, **kwargs):
global EXCHANGES global EXCHANGES
global QUEUES global QUEUES
LOG.debug(_('Binding %s to %s with key %s'), LOG.debug(_('Binding %(queue)s to %(exchange)s with'
queue, exchange, routing_key) ' key %(routing_key)s') % locals())
EXCHANGES[exchange].bind(QUEUES[queue].push, routing_key) EXCHANGES[exchange].bind(QUEUES[queue].push, routing_key)
def declare_consumer(self, queue, callback, *args, **kwargs): def declare_consumer(self, queue, callback, *args, **kwargs):
@@ -117,7 +118,7 @@ class Backend(base.BaseBackend):
content_type=content_type, content_type=content_type,
content_encoding=content_encoding) content_encoding=content_encoding)
message.result = True message.result = True
LOG.debug(_('Getting from %s: %s'), queue, message) LOG.debug(_('Getting from %(queue)s: %(message)s') % locals())
return message return message
def prepare_message(self, message_data, delivery_mode, def prepare_message(self, message_data, delivery_mode,

View File

@@ -89,11 +89,12 @@ class Consumer(messaging.Consumer):
self.failed_connection = False self.failed_connection = False
break break
except: # Catching all because carrot sucks except: # Catching all because carrot sucks
LOG.exception(_("AMQP server on %s:%d is unreachable." fl_host = FLAGS.rabbit_host
" Trying again in %d seconds.") % ( fl_port = FLAGS.rabbit_port
FLAGS.rabbit_host, fl_intv = FLAGS.rabbit_retry_interval
FLAGS.rabbit_port, LOG.exception(_("AMQP server on %(fl_host)s:%(fl_port)d is"
FLAGS.rabbit_retry_interval)) " unreachable. Trying again in %(fl_intv)d seconds.")
% locals())
self.failed_connection = True self.failed_connection = True
if self.failed_connection: if self.failed_connection:
LOG.exception(_("Unable to connect to AMQP server " LOG.exception(_("Unable to connect to AMQP server "
@@ -152,7 +153,7 @@ class TopicConsumer(Consumer):
class AdapterConsumer(TopicConsumer): class AdapterConsumer(TopicConsumer):
"""Calls methods on a proxy object based on method and args""" """Calls methods on a proxy object based on method and args"""
def __init__(self, connection=None, topic="broadcast", proxy=None): def __init__(self, connection=None, topic="broadcast", proxy=None):
LOG.debug(_('Initing the Adapter Consumer for %s') % (topic)) LOG.debug(_('Initing the Adapter Consumer for %s') % topic)
self.proxy = proxy self.proxy = proxy
super(AdapterConsumer, self).__init__(connection=connection, super(AdapterConsumer, self).__init__(connection=connection,
topic=topic) topic=topic)
@@ -167,7 +168,7 @@ class AdapterConsumer(TopicConsumer):
Example: {'method': 'echo', 'args': {'value': 42}} Example: {'method': 'echo', 'args': {'value': 42}}
""" """
LOG.debug(_('received %s') % (message_data)) LOG.debug(_('received %s') % message_data)
msg_id = message_data.pop('_msg_id', None) msg_id = message_data.pop('_msg_id', None)
ctxt = _unpack_context(message_data) ctxt = _unpack_context(message_data)
@@ -180,7 +181,7 @@ class AdapterConsumer(TopicConsumer):
# messages stay in the queue indefinitely, so for now # messages stay in the queue indefinitely, so for now
# we just log the message and send an error string # we just log the message and send an error string
# back to the caller # back to the caller
LOG.warn(_('no method for message: %s') % (message_data)) LOG.warn(_('no method for message: %s') % message_data)
msg_reply(msg_id, _('No method for message: %s') % message_data) msg_reply(msg_id, _('No method for message: %s') % message_data)
return return

View File

@@ -86,7 +86,7 @@ class RpcTestCase(test.TestCase):
@staticmethod @staticmethod
def echo(context, queue, value): def echo(context, queue, value):
"""Calls echo in the passed queue""" """Calls echo in the passed queue"""
LOG.debug(_("Nested received %s, %s"), queue, value) LOG.debug(_("Nested received %(queue)s, %(value)s") % locals())
ret = rpc.call(context, ret = rpc.call(context,
queue, queue,
{"method": "echo", {"method": "echo",