-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.py
executable file
·47 lines (41 loc) · 1.39 KB
/
db.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
#!/usr/bin/env python3
'''
Wrapper for database tools.
'''
import sys
from argparse import ArgumentParser, RawDescriptionHelpFormatter
from importlib import import_module
def main(args):
'''Execute a database-related utility.'''
description = [
'Tools',
'\timport - import CSV files into the database',
'\tre-import - re-import CSV files from the data directory',
'\tdelete - delete CSV files from the database',
'\tcall - call a database procedure',
'\treport - generate a canned report',
'\tlogin - login to the database',
'\tinit - initialize/rebuild the database',
]
parser = ArgumentParser(
formatter_class=RawDescriptionHelpFormatter,
description="\n".join(description))
parser.add_argument(
'tool',
type=str,
choices=['import', 're-import', 'delete', 'call', 'report', 'login', 'init'])
parser_args = parser.parse_args(args[:1])
package_name = {
'import': 'db_import',
're-import': 'db_re_import',
'delete': 'db_delete',
'call': 'db_call',
'report': 'db_report',
'login': 'db_login',
'init': 'db_init'
}.get(parser_args.tool)
package = import_module(f'.{package_name}', 'src.client')
return package.main(args[1:])
if __name__ == '__main__':
rc = main(sys.argv[1:])
sys.exit(rc)