-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·74 lines (57 loc) · 1.77 KB
/
main.py
File metadata and controls
executable file
·74 lines (57 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python3
import os
import sys
import errno
import json
import app
from app import settings, logging
# -----------------------------------------------------------------------------
# Application Definition
def main(argv):
'''
Main entry point into the program.
'''
# Get arguments and argument parser.
(args, parser) = app.cli(argv)
# Initialize logging and set verbosity level.
logger = logging.get_logger(__name__)
logger.debug(f'Program arguments: {argv}')
# Check if any command arguments have been passed.
if (len(argv) <= 1):
# No arguments passed.
logger.warning(f'No command arguments passed')
#parser.print_help()
#sys.exit(errno.EAGAIN)
if args.list_configs:
configs = settings.list_configs()
print(configs)
return os.EX_OK
# Initialize our app.
try:
app.init(args)
except Exception as e:
logger.exception(e)
logger.failure(f'App initialization failed: {e.errno}')
parser.print_help()
return os.EX_SOFTWARE
# Load application configuration.
try:
config = app.load_config(args)
except Exception as e:
logger.exception(e)
logger.failure(f'App configuration failed: {e.errno}')
parser.print_help()
return os.EX_CONFIG
# Do something with config before running main app logic.
# Run main app logic
try:
exit_code = app.process(args, config)
except Exception as e:
logger.exception(e)
logger.failure(f'App processing failed: {e.errno}')
parser.print_help()
return os.EX_SOFTWARE
# Handle anything else you need to, we're getting out of here.
return exit_code
if __name__ == "__main__":
sys.exit(main(sys.argv))