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

View File

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