forked from PalisadoesFoundation/pattoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpattoo_cli.py
executable file
·68 lines (49 loc) · 1.51 KB
/
pattoo_cli.py
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
#!/usr/bin/env python3
"""Pattoo CLI script."""
# Standard libraries
import sys
import os
# Try to create a working PYTHONPATH
_BIN_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
_ROOT_DIRECTORY = os.path.abspath(os.path.join(_BIN_DIRECTORY, os.pardir))
_EXPECTED = '{0}pattoo{0}bin'.format(os.sep)
if _BIN_DIRECTORY.endswith(_EXPECTED) is True:
sys.path.append(_ROOT_DIRECTORY)
else:
print('''This script is not installed in the "{0}" directory. Please fix.\
'''.format(_EXPECTED))
sys.exit(2)
# pattoo imports
from pattoo.cli.cli import Parser
from pattoo.cli import cli_show, cli_create, cli_set, cli_import, cli_assign
from pattoo.db.db import connectivity
def main():
"""Pattoo CLI script.
Args:
None
Returns:
None
"""
# Make sure we have a database
_ = connectivity()
# Initialize key variables
_help = 'This program is the CLI interface to configuring pattoo'
# Process the CLI
_parser = Parser(additional_help=_help)
(args, parser) = _parser.args()
# Process CLI options
if args.action == 'show':
cli_show.process(args)
elif args.action == 'create':
cli_create.process(args)
elif args.action == 'set':
cli_set.process(args)
elif args.action == 'import':
cli_import.process(args)
elif args.action == 'assign':
cli_assign.process(args)
# Print help if no argument options were triggered
parser.print_help(sys.stderr)
sys.exit(1)
if __name__ == '__main__':
main()