-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmcsdksamplerunner.py
More file actions
77 lines (55 loc) · 2.48 KB
/
Copy pathmcsdksamplerunner.py
File metadata and controls
77 lines (55 loc) · 2.48 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
75
76
77
import importlib
import click
import sys
from lib.helpers.logs import LogHelper
from pathlib import Path
@click.group(help='MC SDK SAMPLE CATALOG', context_settings=dict(help_option_names=["-h", "--help"]))
@click.pass_context
def main_module(cmd):
pass
def bind_function(name):
def func(args):
call = importlib.import_module(f"{module}.{submodule.replace('-', '_')}")
try:
call.main(args)
except AttributeError as e:
click.echo(click.style(f"The '{submodule}' command is not supported yet", fg='red'))
func.__name__ = name
return func
if __name__ == '__main__':
# Define folders to track
modules = {'admin': {'description': 'Admin related operations and utilities.'},
'tables': {'description': 'Collection of actions and utilities around tables/views'},
'monitors': {'description': 'Collection of actions and utilities for MC monitors.'},
'lineage': {'description': 'Collection of actions and utilities around lineage'},}
for module in modules:
subpaths = sorted(Path(module).glob('[!__]*.py'))
@click.command(name=module, help=modules[module]['description'],
context_settings=dict(help_option_names=["-h", "--help"]))
def command():
pass
main_module.add_command(command)
if len(sys.argv) > 1:
if module == sys.argv[1]:
@click.group(name=module, help=modules[module]['description'],
context_settings=dict(help_option_names=["-h", "--help"]))
def main_submodule():
pass
#LogHelper.banner()
for path in subpaths:
submodule = str(path).split('/')[-1].replace('.py', '').replace('_', '-')
script = bind_function(f'_{submodule}')
@click.command(name=submodule, context_settings=dict(help_option_names=["-h", "--help"]))
def subcommand():
pass
if len(sys.argv) >= 3:
if submodule == sys.argv[2]:
script(sys.argv[3:])
exit(0)
main_submodule.add_command(subcommand)
main_module.add_command(main_submodule)
main_module(max_content_width=120)
else:
continue
LogHelper.banner()
main_module(max_content_width=120)