LGTM: Use of exit() or quit()

Replace exit() with sys.exit(). exit() or quit() may fail if the interpreter
is run with the -S option.

https://pagure.io/freeipa/issue/7344

Signed-off-by: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Fraser Tweedale <ftweedal@redhat.com>
This commit is contained in:
Christian Heimes 2018-01-03 10:08:50 +01:00
parent cae2d99f89
commit 1ed4461f33
5 changed files with 22 additions and 16 deletions

View File

@ -956,13 +956,13 @@ class console(frontend.Command):
try:
script = open(filename)
except IOError as e:
exit("%s: %s" % (e.filename, e.strerror))
sys.exit("%s: %s" % (e.filename, e.strerror))
try:
with script:
exec(script, globals(), local)
except Exception:
traceback.print_exc()
exit(1)
sys.exit(1)
else:
code.interact(
'(Custom IPA interactive Python console)',
@ -1121,7 +1121,7 @@ class cli(backend.Executioner):
self.Command.help(outfile=sys.stderr)
print(file=sys.stderr)
print('Error: Command not specified', file=sys.stderr)
exit(2)
sys.exit(2)
(key, argv) = (argv[0], argv[1:])
name = from_cli(key)
if name not in self.Command and len(argv) == 0:

View File

@ -1370,7 +1370,7 @@ def replica_ca_install_check(config, promote):
'Please run copy-schema-to-ca.py on all CA masters.\n'
'If you are certain that this is a false positive, use '
'--skip-schema-check.')
exit('IPA schema missing on master CA directory server')
sys.exit('IPA schema missing on master CA directory server')
def __update_entry_from_cert(make_filter, make_entry, cert):

View File

@ -105,7 +105,7 @@ def get_object(conf, args):
try:
return conf.host_by_name(args.host)
except LookupError:
exit('Host %s not found in config. Try --global' % args.host)
sys.exit('Host %s not found in config. Try --global' % args.host)
else:
if args.domain:
try:
@ -113,18 +113,18 @@ def get_object(conf, args):
except ValueError:
domains = [d for d in conf.domains if d.name == args.domain]
if not domains:
exit('Domain %s not found' % args.domain)
sys.exit('Domain %s not found' % args.domain)
domain = domains[0]
else:
try:
domain = conf.domains[num]
except LookupError:
exit('Domain %s not found.' % args.domain)
sys.exit('Domain %s not found.' % args.domain)
else:
try:
domain = conf.domains[0]
except IndexError:
exit('No domains are configured.')
sys.exit('No domains are configured.')
if args.master:
return domain.master
@ -133,23 +133,29 @@ def get_object(conf, args):
try:
return domain.replicas[args.replica]
except LookupError:
exit('Domain %s not found in domain %s' % (args.replica,
domain.name))
sys.exit(
'Domain %s not found in domain %s'
% (args.replica, domain.name)
)
elif args.client:
num = int(args.client) - 1
try:
return domain.replicas[args.client]
except LookupError:
exit('Client %s not found in domain %s' % (args.client,
domain.name))
sys.exit(
'Client %s not found in domain %s'
% (args.client, domain.name)
)
elif args.role:
try:
return domain.get_host_by_role(args.role)
except LookupError:
exit('No host with role %s not found in domain %s'
% (args.role, domain.name))
sys.exit(
'No host with role %s not found in domain %s'
% (args.role, domain.name)
)
else:
return domain

View File

@ -453,4 +453,4 @@ class TaskRunner(object):
tasks.add_a_record(master, host)
if __name__ == '__main__':
exit(TaskRunner().main(sys.argv[1:]))
sys.exit(TaskRunner().main(sys.argv[1:]))

View File

@ -121,7 +121,7 @@ def main(options):
print(file=sys.stderr)
print('Managed permission ACI validation failed.', file=sys.stderr)
print('Re-check permission changes and run `makeaci`.', file=sys.stderr)
exit('%s validation failed' % options.filename)
sys.exit('%s validation failed' % options.filename)
else:
with open(options.filename, 'w') as file:
file.writelines(output_lines)