Merge "Output Strings of bin/*.py should support i18n"

This commit is contained in:
Jenkins 2013-12-31 20:13:57 +00:00 committed by Gerrit Code Review
commit 7b04653595
2 changed files with 25 additions and 20 deletions

View File

@ -196,8 +196,7 @@ class HostCommands(object):
"""Show a list of all physical hosts. Filter by zone.
args: [zone]
"""
print("%-25s\t%-15s" % (_('host'),
_('zone')))
print(_("%(host)-25s\t%(zone)-15s") % {'host': 'host', 'zone': 'zone'})
ctxt = context.get_admin_context()
services = db.service_get_all(ctxt)
if zone:
@ -208,7 +207,9 @@ class HostCommands(object):
hosts.append(srv)
for h in hosts:
print("%-25s\t%-15s" % (h['host'], h['availability_zone']))
print(_("%(host)-25s\t%(availability_zone)-15s")
% {'host': h['host'],
'availability_zone': h['availability_zone']})
class DbCommands(object):
@ -255,14 +256,14 @@ class VolumeCommands(object):
host = volume['host']
if not host:
print("Volume not yet assigned to host.")
print("Deleting volume from database and skipping rpc.")
print(_("Volume not yet assigned to host."))
print(_("Deleting volume from database and skipping rpc."))
db.volume_destroy(ctxt, param2id(volume_id))
return
if volume['status'] == 'in-use':
print("Volume is in-use.")
print("Detach volume from instance and then try again.")
print(_("Volume is in-use."))
print(_("Detach volume from instance and then try again."))
return
rpc.cast(ctxt,
@ -280,7 +281,7 @@ class VolumeCommands(object):
ctxt = context.get_admin_context()
volume = db.volume_get(ctxt, param2id(volume_id))
if not volume['instance_id']:
print("volume is not attached to an instance")
print(_("volume is not attached to an instance"))
return
instance = db.instance_get(ctxt, volume['instance_id'])
host = instance['host']
@ -335,9 +336,10 @@ class GetLogCommands(object):
if print_name == 0:
print(log_file + ":-")
print_name = 1
print("Line %d : %s" % (len(lines) - index, line))
print(_("Line %(dis)d : %(line)s") %
{'dis': len(lines) - index, 'line': line})
if error_found == 0:
print("No errors in logfiles!")
print(_("No errors in logfiles!"))
@args('num_entries', nargs='?', type=int, default=10,
help='Number of entries to list (default: %(default)d)')
@ -351,20 +353,20 @@ class GetLogCommands(object):
elif os.path.exists('/var/log/messages'):
log_file = '/var/log/messages'
else:
print("Unable to find system log file!")
print(_("Unable to find system log file!"))
sys.exit(1)
lines = [line.strip() for line in open(log_file, "r")]
lines.reverse()
print("Last %s cinder syslog entries:-" % (entries))
print(_("Last %s cinder syslog entries:-") % (entries))
for line in lines:
if line.find("cinder") > 0:
count += 1
print("%s" % (line))
print(_("%s") % (line))
if count == entries:
break
if count == 0:
print("No cinder entries in syslog!")
print(_("No cinder entries in syslog!"))
class BackupCommands(object):
@ -513,7 +515,7 @@ def main():
print(script_name + " category action [<args>]")
print(_("Available categories:"))
for category in CATEGORIES:
print("\t%s" % category)
print(_("\t%s") % category)
sys.exit(2)
try:

View File

@ -55,7 +55,8 @@ def _subprocess_setup():
def _exit_error(execname, message, errorcode, log=True):
print("%s: %s" % (execname, message))
print(_("%(execname)s: %(message)s") %
{'execname': execname, 'message': message})
if log:
logging.error(message)
sys.exit(errorcode)
@ -84,7 +85,8 @@ if __name__ == '__main__':
rawconfig.read(configfile)
config = wrapper.RootwrapConfig(rawconfig)
except ValueError as exc:
msg = "Incorrect value in %s: %s" % (configfile, exc.message)
msg = (_("Incorrect value in %(configfile)s: %(message)s")
% {'configfile': configfile, 'message': exc.message})
_exit_error(execname, msg, RC_BADCONFIG, log=False)
except ConfigParser.Error:
_exit_error(execname, "Incorrect configuration file: %s" % configfile,
@ -118,11 +120,12 @@ if __name__ == '__main__':
sys.exit(obj.returncode)
except wrapper.FilterMatchNotExecutable as exc:
msg = ("Executable not found: %s (filter match = %s)"
% (exc.match.exec_path, exc.match.name))
msg = (_("Executable not found: %(exec_path)s "
"(filter match = %(name)s)")
% {'exec_path': exc.match.exec_path, 'name': exc.match.name})
_exit_error(execname, msg, RC_NOEXECFOUND, log=config.use_syslog)
except wrapper.NoFilterMatched:
msg = ("Unauthorized command: %s (no filter matched)"
msg = (_("Unauthorized command: %s (no filter matched)")
% ' '.join(userargs))
_exit_error(execname, msg, RC_UNAUTHORIZED, log=config.use_syslog)