Merge "Change optparse to argparse"

This commit is contained in:
Zuul 2020-01-22 18:59:19 +00:00 committed by Gerrit Code Review
commit 5e8264bb20
3 changed files with 40 additions and 43 deletions

View File

@ -13,8 +13,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import argparse
import logging
from optparse import OptionParser
import os
import six
import sys
@ -54,16 +54,16 @@ timeout = 10
nova_cfg = '/etc/nova/nova.conf'
if __name__ == '__main__':
parser = OptionParser(usage="usage: %prog [options]")
parser.add_option('-k', '--insecure',
action="store_false",
dest='insecure',
default=True,
help='Allow insecure connection when using SSL')
parser = argparse.ArgumentParser(usage='%(prog)s [options]')
parser.add_argument('-k', '--insecure',
action="store_false",
dest='insecure',
default=True,
help='Allow insecure connection when using SSL')
(options, args) = parser.parse_args()
args = parser.parse_args()
LOG.debug('Running with parameter insecure = %s',
options.insecure)
args.insecure)
if os.path.isfile(nova_cfg):
try:
@ -88,7 +88,7 @@ if __name__ == '__main__':
'project_domain_name'),
user_domain_name=config.get('neutron',
'user_domain_name'))
sess = session.Session(auth=auth, verify=options.insecure)
sess = session.Session(auth=auth, verify=args.insecure)
# Wait until this host is listed in the service list
for i in range(iterations):

View File

@ -13,8 +13,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import argparse
import logging
from optparse import OptionParser
import os
import six
import socket
@ -54,16 +54,16 @@ timeout = 10
nova_cfg = '/etc/nova/nova.conf'
if __name__ == '__main__':
parser = OptionParser(usage="usage: %prog [options]")
parser.add_option('-k', '--insecure',
action="store_false",
dest='insecure',
default=True,
help='Allow insecure connection when using SSL')
parser = argparse.ArgumentParser(usage='%(prog)s [options]')
parser.add_argument('-k', '--insecure',
action="store_false",
dest='insecure',
default=True,
help='Allow insecure connection when using SSL')
(options, args) = parser.parse_args()
args = parser.parse_args()
LOG.debug('Running with parameter insecure = %s',
options.insecure)
args.insecure)
if os.path.isfile(nova_cfg):
try:
@ -93,7 +93,7 @@ if __name__ == '__main__':
'project_domain_name'),
user_domain_name=config.get('neutron',
'user_domain_name'))
sess = session.Session(auth=auth, verify=options.insecure)
sess = session.Session(auth=auth, verify=args.insecure)
nova = client.Client('2.11', session=sess, endpoint_type='internal',
region_name=config.get('neutron', 'region_name'))

View File

@ -267,43 +267,40 @@ def check_up_to_date(output_filename=None, input_filename=None):
def get_options():
from optparse import OptionParser
import argparse
parser = OptionParser('usage: %prog'
' [-i INPUT_FILE] [-o OUTPUT_FILE] [--check]',
description=__doc__)
parser.add_option('-i', '--input', dest='input_file', action='store',
default=None,
help='Specify a different endpoint data file')
parser.add_option('-o', '--output', dest='output_file', action='store',
default=None,
help='Specify a different endpoint map template file')
parser.add_option('-c', '--check', dest='check', action='store_true',
default=False, help='Check that the output file is '
'up to date with the data')
parser.add_option('-d', '--debug', dest='debug', action='store_true',
default=False, help='Print stack traces on error')
parser = argparse.ArgumentParser(
usage="%(prog)s [-i INPUT_FILE] [-o OUTPUT_FILE] [--check]",
description=__doc__)
parser.add_argument('-i', '--input', dest='input_file', action='store',
default=None,
help='Specify a different endpoint data file')
parser.add_argument('-o', '--output', dest='output_file', action='store',
default=None,
help='Specify a different endpoint map template file')
parser.add_argument('-c', '--check', dest='check', action='store_true',
default=False, help='Check that the output file is '
'up to date with the data')
parser.add_argument('-d', '--debug', dest='debug', action='store_true',
default=False, help='Print stack traces on error')
return parser.parse_args()
def main():
options, args = get_options()
if args:
print('Warning: ignoring positional args: %s' % ' '.join(args),
file=sys.stderr)
args = get_options()
try:
if options.check:
if not check_up_to_date(options.output_file, options.input_file):
if args.check:
if not check_up_to_date(args.output_file, args.input_file):
print('EndpointMap template does not match input data. Please '
'run the build_endpoint_map.py tool to update the '
'template.', file=sys.stderr)
sys.exit(2)
else:
build_endpoint_map(options.output_file, options.input_file)
build_endpoint_map(args.output_file, args.input_file)
except Exception as exc:
if options.debug:
if args.debug:
raise
print('%s: %s' % (type(exc).__name__, str(exc)), file=sys.stderr)
sys.exit(1)