Replace exit() with sys.exit()

This fix adds replacement for exit() to sys.exit(), as
exit() is not recommended way to exit from the program.

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2017-12-06 10:29:17 +05:30 committed by Brian Coca
parent 0ca828ebab
commit 36f82ae8cc
3 changed files with 10 additions and 13 deletions

View file

@ -34,6 +34,8 @@ Livestatus API: http://www.naemon.org/documentation/usersguide/livestatus.html
import os import os
import re import re
import argparse import argparse
import sys
try: try:
import configparser import configparser
except ImportError: except ImportError:
@ -44,8 +46,7 @@ import json
try: try:
from mk_livestatus import Socket from mk_livestatus import Socket
except ImportError: except ImportError:
print("Error: mk_livestatus is needed. Try something like: pip install python-mk-livestatus") sys.exit("Error: mk_livestatus is needed. Try something like: pip install python-mk-livestatus")
exit(1)
class NagiosLivestatusInventory(object): class NagiosLivestatusInventory(object):
@ -160,8 +161,7 @@ class NagiosLivestatusInventory(object):
self.json_indent = 2 self.json_indent = 2
if len(self.backends) == 0: if len(self.backends) == 0:
print("Error: Livestatus configuration is missing. See nagios_livestatus.ini.") sys.exit("Error: Livestatus configuration is missing. See nagios_livestatus.ini.")
exit(1)
for backend in self.backends: for backend in self.backends:
self.query_backend(backend, self.options.host) self.query_backend(backend, self.options.host)
@ -171,7 +171,6 @@ class NagiosLivestatusInventory(object):
elif self.options.list: elif self.options.list:
print(json.dumps(self.result, indent=self.json_indent)) print(json.dumps(self.result, indent=self.json_indent))
else: else:
print("usage: --list or --host HOSTNAME [--pretty]") sys.exit("usage: --list or --host HOSTNAME [--pretty]")
exit(1)
NagiosLivestatusInventory() NagiosLivestatusInventory()

View file

@ -28,6 +28,7 @@ Configuration is read from `nagios_ndo.ini`.
import os import os
import argparse import argparse
import sys
try: try:
import configparser import configparser
except ImportError: except ImportError:
@ -39,8 +40,7 @@ try:
from sqlalchemy import text from sqlalchemy import text
from sqlalchemy.engine import create_engine from sqlalchemy.engine import create_engine
except ImportError: except ImportError:
print("Error: SQLAlchemy is needed. Try something like: pip install sqlalchemy") sys.exit("Error: SQLAlchemy is needed. Try something like: pip install sqlalchemy")
exit(1)
class NagiosNDOInventory(object): class NagiosNDOInventory(object):
@ -101,10 +101,8 @@ class NagiosNDOInventory(object):
elif self.options.list: elif self.options.list:
print(json.dumps(self.result)) print(json.dumps(self.result))
else: else:
print("usage: --list or --host HOSTNAME") sys.exit("usage: --list or --host HOSTNAME")
exit(1)
else: else:
print("Error: Database configuration is missing. See nagios_ndo.ini.") sys.exit("Error: Database configuration is missing. See nagios_ndo.ini.")
exit(1)
NagiosNDOInventory() NagiosNDOInventory()

View file

@ -63,7 +63,7 @@ def parse_args():
def query_database(): def query_database():
if not os.path.exists(DATABASE_PATH): if not os.path.exists(DATABASE_PATH):
exit('error: Database not found. Did you run `report.py populate` first?') sys.exit('error: Database not found. Did you run `report.py populate` first?')
os.execvp('sqlite3', ('sqlite3', DATABASE_PATH)) os.execvp('sqlite3', ('sqlite3', DATABASE_PATH))