Use i18n for shell.py
Help msg and output should support,This can be beneficial to the string type Partial-Bug: #1379001 Change-Id: I7d12aead49f5771f0762533ce9f53e477367101c
This commit is contained in:
parent
e403659799
commit
18bf918086
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
other:
|
||||||
|
- Use i18n for shell.py Partial-Bug 1379001.
|
|
@ -94,8 +94,8 @@ class OpenStackTroveShell(object):
|
||||||
parser = TroveClientArgumentParser(
|
parser = TroveClientArgumentParser(
|
||||||
prog='trove',
|
prog='trove',
|
||||||
description=__doc__.strip(),
|
description=__doc__.strip(),
|
||||||
epilog='See "trove help COMMAND" '
|
epilog=_('See "trove help COMMAND" '
|
||||||
'for help on a specific command.',
|
'for help on a specific command.'),
|
||||||
add_help=False,
|
add_help=False,
|
||||||
formatter_class=OpenStackHelpFormatter,
|
formatter_class=OpenStackHelpFormatter,
|
||||||
)
|
)
|
||||||
|
@ -108,13 +108,13 @@ class OpenStackTroveShell(object):
|
||||||
parser.add_argument('--version',
|
parser.add_argument('--version',
|
||||||
action='version',
|
action='version',
|
||||||
version=troveclient.__version__,
|
version=troveclient.__version__,
|
||||||
help="Show program's version number and exit.")
|
help=_("Show program's version number and exit."))
|
||||||
|
|
||||||
parser.add_argument('--debug',
|
parser.add_argument('--debug',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=utils.env('TROVECLIENT_DEBUG',
|
default=utils.env('TROVECLIENT_DEBUG',
|
||||||
default=False),
|
default=False),
|
||||||
help="Print debugging output.")
|
help=_("Print debugging output."))
|
||||||
|
|
||||||
parser.add_argument('--os-auth-system',
|
parser.add_argument('--os-auth-system',
|
||||||
metavar='<auth-system>',
|
metavar='<auth-system>',
|
||||||
|
@ -128,29 +128,29 @@ class OpenStackTroveShell(object):
|
||||||
metavar='<service-type>',
|
metavar='<service-type>',
|
||||||
default=utils.env('OS_SERVICE_TYPE',
|
default=utils.env('OS_SERVICE_TYPE',
|
||||||
'TROVE_SERVICE_TYPE'),
|
'TROVE_SERVICE_TYPE'),
|
||||||
help='Defaults to database for most actions.')
|
help=_('Defaults to database for most actions.'))
|
||||||
parser.add_argument('--service_type',
|
parser.add_argument('--service_type',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
|
||||||
parser.add_argument('--service-name',
|
parser.add_argument('--service-name',
|
||||||
metavar='<service-name>',
|
metavar='<service-name>',
|
||||||
default=utils.env('TROVE_SERVICE_NAME'),
|
default=utils.env('TROVE_SERVICE_NAME'),
|
||||||
help='Defaults to env[TROVE_SERVICE_NAME].')
|
help=_('Defaults to env[TROVE_SERVICE_NAME].'))
|
||||||
parser.add_argument('--service_name',
|
parser.add_argument('--service_name',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
|
||||||
parser.add_argument('--bypass-url',
|
parser.add_argument('--bypass-url',
|
||||||
metavar='<bypass-url>',
|
metavar='<bypass-url>',
|
||||||
default=utils.env('TROVE_BYPASS_URL'),
|
default=utils.env('TROVE_BYPASS_URL'),
|
||||||
help='Defaults to env[TROVE_BYPASS_URL].')
|
help=_('Defaults to env[TROVE_BYPASS_URL].'))
|
||||||
parser.add_argument('--bypass_url',
|
parser.add_argument('--bypass_url',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
|
||||||
parser.add_argument('--database-service-name',
|
parser.add_argument('--database-service-name',
|
||||||
metavar='<database-service-name>',
|
metavar='<database-service-name>',
|
||||||
default=utils.env('TROVE_DATABASE_SERVICE_NAME'),
|
default=utils.env('TROVE_DATABASE_SERVICE_NAME'),
|
||||||
help='Defaults to env'
|
help=_('Defaults to env'
|
||||||
'[TROVE_DATABASE_SERVICE_NAME].')
|
'[TROVE_DATABASE_SERVICE_NAME].'))
|
||||||
parser.add_argument('--database_service_name',
|
parser.add_argument('--database_service_name',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
|
||||||
|
@ -162,9 +162,12 @@ class OpenStackTroveShell(object):
|
||||||
default=utils.env(
|
default=utils.env(
|
||||||
'TROVE_ENDPOINT_TYPE',
|
'TROVE_ENDPOINT_TYPE',
|
||||||
default=default_trove_endpoint_type),
|
default=default_trove_endpoint_type),
|
||||||
help='Defaults to env[TROVE_ENDPOINT_TYPE] or '
|
help=(_('Defaults to env[TROVE_ENDPOINT_TYPE] or '
|
||||||
+ 'env[OS_ENDPOINT_TYPE] or '
|
'env[OS_ENDPOINT_TYPE] or '
|
||||||
+ DEFAULT_TROVE_ENDPOINT_TYPE + '.')
|
'%(DEFAULT_TROVE_ENDPOINT_TYPE)s.') %
|
||||||
|
{'DEFAULT_TROVE_ENDPOINT_TYPE':
|
||||||
|
DEFAULT_TROVE_ENDPOINT_TYPE}))
|
||||||
|
|
||||||
parser.add_argument('--endpoint_type',
|
parser.add_argument('--endpoint_type',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
|
||||||
|
@ -173,8 +176,8 @@ class OpenStackTroveShell(object):
|
||||||
default=utils.env(
|
default=utils.env(
|
||||||
'OS_DATABASE_API_VERSION',
|
'OS_DATABASE_API_VERSION',
|
||||||
default=DEFAULT_OS_DATABASE_API_VERSION),
|
default=DEFAULT_OS_DATABASE_API_VERSION),
|
||||||
help='Accepts 1, defaults '
|
help=_('Accepts 1, defaults '
|
||||||
'to env[OS_DATABASE_API_VERSION].')
|
'to env[OS_DATABASE_API_VERSION].'))
|
||||||
parser.add_argument('--os_database_api_version',
|
parser.add_argument('--os_database_api_version',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
|
||||||
|
@ -182,30 +185,32 @@ class OpenStackTroveShell(object):
|
||||||
metavar='<retries>',
|
metavar='<retries>',
|
||||||
type=int,
|
type=int,
|
||||||
default=0,
|
default=0,
|
||||||
help='Number of retries.')
|
help=_('Number of retries.'))
|
||||||
|
|
||||||
parser.add_argument('--json', '--os-json-output',
|
parser.add_argument('--json', '--os-json-output',
|
||||||
dest='json',
|
dest='json',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=utils.env('OS_JSON_OUTPUT',
|
default=utils.env('OS_JSON_OUTPUT',
|
||||||
default=False),
|
default=False),
|
||||||
help='Output JSON instead of prettyprint. '
|
help=_('Output JSON instead of prettyprint. '
|
||||||
'Defaults to env[OS_JSON_OUTPUT].')
|
'Defaults to env[OS_JSON_OUTPUT].'))
|
||||||
|
|
||||||
if osprofiler_profiler:
|
if osprofiler_profiler:
|
||||||
parser.add_argument('--profile',
|
parser.add_argument('--profile',
|
||||||
metavar='HMAC_KEY',
|
metavar='HMAC_KEY',
|
||||||
default=utils.env('OS_PROFILE_HMACKEY',
|
default=utils.env('OS_PROFILE_HMACKEY',
|
||||||
default=None),
|
default=None),
|
||||||
help='HMAC key used to encrypt context '
|
help=_('HMAC key used to encrypt context '
|
||||||
'data when profiling the performance of an '
|
'data when profiling the performance '
|
||||||
'operation. This key should be set to one of '
|
'of an operation. This key should be '
|
||||||
'the HMAC keys configured in Trove (they are '
|
'set to one of the HMAC keys '
|
||||||
'found in api-paste.ini, typically in '
|
'configured in Trove (they are found '
|
||||||
'/etc/trove). Without the key, profiling '
|
'in api-paste.ini, typically in '
|
||||||
'will not be triggered even if it is enabled '
|
'/etc/trove). Without the key, '
|
||||||
'on the server side. '
|
'profiling will not be triggered even '
|
||||||
'Defaults to env[OS_PROFILE_HMACKEY].')
|
'if it is enabled on the server side. '
|
||||||
|
'Defaults to env[OS_PROFILE_HMACKEY].'
|
||||||
|
))
|
||||||
|
|
||||||
self._append_global_identity_args(parser, argv)
|
self._append_global_identity_args(parser, argv)
|
||||||
|
|
||||||
|
@ -248,8 +253,8 @@ class OpenStackTroveShell(object):
|
||||||
parser.add_argument('--os-region-name',
|
parser.add_argument('--os-region-name',
|
||||||
metavar='<region-name>',
|
metavar='<region-name>',
|
||||||
default=utils.env('OS_REGION_NAME'),
|
default=utils.env('OS_REGION_NAME'),
|
||||||
help='Specify the region to use. '
|
help=_('Specify the region to use. '
|
||||||
'Defaults to env[OS_REGION_NAME].')
|
'Defaults to env[OS_REGION_NAME].'))
|
||||||
parser.add_argument('--os_region_name',
|
parser.add_argument('--os_region_name',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
|
||||||
|
@ -448,9 +453,9 @@ class OpenStackTroveShell(object):
|
||||||
|
|
||||||
if not auth_plugin or not auth_plugin.opts:
|
if not auth_plugin or not auth_plugin.opts:
|
||||||
if not os_username:
|
if not os_username:
|
||||||
raise exc.CommandError(
|
raise exc.CommandError(_(
|
||||||
"You must provide a username "
|
"You must provide a username "
|
||||||
"via either --os-username or env[OS_USERNAME]")
|
"via either --os-username or env[OS_USERNAME]"))
|
||||||
|
|
||||||
if not os_password:
|
if not os_password:
|
||||||
os_password = getpass.getpass()
|
os_password = getpass.getpass()
|
||||||
|
@ -476,12 +481,12 @@ class OpenStackTroveShell(object):
|
||||||
"(env[OS_PROJECT_DOMAIN_NAME])"))
|
"(env[OS_PROJECT_DOMAIN_NAME])"))
|
||||||
|
|
||||||
if not os_auth_url:
|
if not os_auth_url:
|
||||||
raise exc.CommandError("You must provide an auth url "
|
raise exc.CommandError(_("You must provide an auth url "
|
||||||
"via either --os-auth-url or "
|
"via either --os-auth-url or "
|
||||||
"env[OS_AUTH_URL] or specify an "
|
"env[OS_AUTH_URL] or specify an "
|
||||||
"auth_system which defines a default "
|
"auth_system which defines a default "
|
||||||
"url with --os-auth-system or "
|
"url with --os-auth-system or "
|
||||||
"env[OS_AUTH_SYSTEM]")
|
"env[OS_AUTH_SYSTEM]"))
|
||||||
|
|
||||||
use_session = True
|
use_session = True
|
||||||
if auth_plugin or bypass_url:
|
if auth_plugin or bypass_url:
|
||||||
|
@ -537,18 +542,19 @@ class OpenStackTroveShell(object):
|
||||||
if not use_session:
|
if not use_session:
|
||||||
self.cs.authenticate()
|
self.cs.authenticate()
|
||||||
except exc.Unauthorized:
|
except exc.Unauthorized:
|
||||||
raise exc.CommandError("Invalid OpenStack Trove credentials.")
|
raise exc.CommandError(_("Invalid OpenStack Trove credentials."))
|
||||||
except exc.AuthorizationFailure:
|
except exc.AuthorizationFailure:
|
||||||
raise exc.CommandError("Unable to authorize user")
|
raise exc.CommandError(_("Unable to authorize user"))
|
||||||
|
|
||||||
endpoint_api_version = self.cs.get_database_api_version_from_endpoint()
|
endpoint_api_version = self.cs.get_database_api_version_from_endpoint()
|
||||||
|
|
||||||
if endpoint_api_version != options.os_database_api_version:
|
if endpoint_api_version != options.os_database_api_version:
|
||||||
msg = (("Database API version is set to %s "
|
msg = (_("Database API version is set to %(db_ver)s "
|
||||||
"but you are accessing a %s endpoint. "
|
"but you are accessing a %(ep_ver)s endpoint. "
|
||||||
"Change its value via either --os-database-api-version "
|
"Change its value via either --os-database-api-version "
|
||||||
"or env[OS_DATABASE_API_VERSION]")
|
"or env[OS_DATABASE_API_VERSION]") %
|
||||||
% (options.os_database_api_version, endpoint_api_version))
|
{'db_ver': options.os_database_api_version,
|
||||||
|
'ep_ver': endpoint_api_version})
|
||||||
# raise exc.InvalidAPIVersion(msg)
|
# raise exc.InvalidAPIVersion(msg)
|
||||||
raise exc.UnsupportedVersion(msg)
|
raise exc.UnsupportedVersion(msg)
|
||||||
|
|
||||||
|
@ -563,9 +569,10 @@ class OpenStackTroveShell(object):
|
||||||
finally:
|
finally:
|
||||||
if profile:
|
if profile:
|
||||||
trace_id = osprofiler_profiler.get().get_base_id()
|
trace_id = osprofiler_profiler.get().get_base_id()
|
||||||
print("Trace ID: %s" % trace_id)
|
print(_("Trace ID: %(trace_id)s") % {'trace_id': trace_id})
|
||||||
print("To display the trace, use the following command:\n"
|
print(_("To display the trace, use the following command:\n"
|
||||||
"osprofiler trace show --html %s" % trace_id)
|
"osprofiler trace show --html %(trace_id)s")
|
||||||
|
% {'trace_id': trace_id})
|
||||||
|
|
||||||
def _run_extension_hooks(self, hook_type, *args, **kwargs):
|
def _run_extension_hooks(self, hook_type, *args, **kwargs):
|
||||||
"""Run hooks for all registered extensions."""
|
"""Run hooks for all registered extensions."""
|
||||||
|
@ -590,14 +597,14 @@ class OpenStackTroveShell(object):
|
||||||
print(' '.join(commands | options))
|
print(' '.join(commands | options))
|
||||||
|
|
||||||
@utils.arg('command', metavar='<subcommand>', nargs='?',
|
@utils.arg('command', metavar='<subcommand>', nargs='?',
|
||||||
help='Display help for <subcommand>.')
|
help=_('Display help for <subcommand>.'))
|
||||||
def do_help(self, args):
|
def do_help(self, args):
|
||||||
"""Displays help about this program or one of its subcommands."""
|
"""Displays help about this program or one of its subcommands."""
|
||||||
if args.command:
|
if args.command:
|
||||||
if args.command in self.subcommands:
|
if args.command in self.subcommands:
|
||||||
self.subcommands[args.command].print_help()
|
self.subcommands[args.command].print_help()
|
||||||
else:
|
else:
|
||||||
raise exc.CommandError("'%s' is not a valid subcommand" %
|
raise exc.CommandError(_("'%s' is not a valid subcommand") %
|
||||||
args.command)
|
args.command)
|
||||||
else:
|
else:
|
||||||
self.parser.print_help()
|
self.parser.print_help()
|
||||||
|
@ -746,14 +753,15 @@ def main():
|
||||||
OpenStackTroveShell().main(map(encodeutils.safe_decode,
|
OpenStackTroveShell().main(map(encodeutils.safe_decode,
|
||||||
sys.argv[1:]))
|
sys.argv[1:]))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("... terminating trove client", file=sys.stderr)
|
print(_("... terminating trove client"), file=sys.stderr)
|
||||||
sys.exit(130)
|
sys.exit(130)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(e, exc_info=1)
|
logger.debug(e, exc_info=1)
|
||||||
message = six.text_type(e)
|
message = six.text_type(e)
|
||||||
if not isinstance(message, six.string_types):
|
if not isinstance(message, six.string_types):
|
||||||
message = str(message)
|
message = str(message)
|
||||||
print("ERROR: %s" % encodeutils.safe_encode(message), file=sys.stderr)
|
print(_("ERROR: %s") % encodeutils.safe_encode(message),
|
||||||
|
file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue