Update main.py according to cement docs

This commit is contained in:
VirtuBox
2019-09-15 14:47:58 +02:00
parent e444886c52
commit a70a45a484
3 changed files with 90 additions and 92 deletions

View File

@@ -79,56 +79,55 @@ class WOTestApp(WOApp):
# Define the applicaiton object outside of main, as some libraries might wish
# to import it as a global (rather than passing it into another class/func)
app = WOApp()
def main():
try:
global sys
# Default our exit status to 0 (non-error)
code = 0
with WOApp() as app:
try:
global sys
# Default our exit status to 0 (non-error)
code = 0
# if not root...kick out
if not os.geteuid() == 0:
print("\nNon-privileged users cant use WordOps. "
"Switch to root or invoke sudo.\n")
app.close(1)
# if not root...kick out
if not os.geteuid() == 0:
print("\nNon-privileged users cant use WordOps. "
"Switch to root or invoke sudo.\n")
app.close(1)
# Setup the application
app.setup()
# Setup the application
app.setup()
# Dump all arguments into wo log
app.log.debug(sys.argv)
# Dump all arguments into wo log
app.log.debug(sys.argv)
# Run the application
app.run()
except exc.WOError as e:
# Catch our application errors and exit 1 (error)
code = 1
print(e)
except FrameworkError as e:
# Catch framework errors and exit 1 (error)
code = 1
print(e)
except CaughtSignal as e:
# Default Cement signals are SIGINT and SIGTERM, exit 0 (non-error)
code = 0
print(e)
except Exception as e:
code = 1
print(e)
finally:
# Print an exception (if it occurred) and --debug was passed
if app.debug:
import sys
import traceback
# Run the application
app.run()
except exc.WOError as e:
# Catch our application errors and exit 1 (error)
code = 1
print(e)
except FrameworkError as e:
# Catch framework errors and exit 1 (error)
code = 1
print(e)
except CaughtSignal as e:
# Default Cement signals are SIGINT and SIGTERM, exit 0 (non-error)
code = 0
print(e)
except Exception as e:
code = 1
print(e)
finally:
# Print an exception (if it occurred) and --debug was passed
if app.debug:
import sys
import traceback
exc_type, exc_value, exc_traceback = sys.exc_info()
if exc_traceback is not None:
traceback.print_exc()
exc_type, exc_value, exc_traceback = sys.exc_info()
if exc_traceback is not None:
traceback.print_exc()
# # Close the application
app.close(code)
# # Close the application
app.close(code)
def get_test_app(**kw):