-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.py
56 lines (43 loc) · 1.46 KB
/
convert.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
import argparse
from rich_argparse import RichHelpFormatter
from app.transfer import (
storage_from_ac,
storage_from_pg,
storage_from_txt,
storage_to_ac,
storage_to_pg,
storage_to_txt,
)
def generate_parser():
supported_types = ["postgres", "access", "text"]
parser = argparse.ArgumentParser(
description="Database Converter CLI Tool", formatter_class=RichHelpFormatter
)
parser.add_argument(
"from_type", choices=supported_types, help="source type"
)
parser.add_argument("from_path", help="source path")
parser.add_argument(
"to_type", choices=supported_types, help="destination type"
)
parser.add_argument("to_path", help="destination path")
return parser
def db_converter(from_type, from_path, to_type, to_path):
from_functions = {
"access": storage_from_ac,
"postgres": storage_from_pg,
"text": storage_from_txt,
}
to_functions = {
"access": storage_to_ac,
"postgres": storage_to_pg,
"text": storage_to_txt,
}
if from_type not in from_functions or to_type not in to_functions:
raise ValueError("Invalid from_type or to_type")
storage = from_functions.get(from_type)(from_path)
to_functions.get(to_type)(to_path, storage)
if __name__ == "__main__":
convert_parser = generate_parser()
args = convert_parser.parse_args()
db_converter(args.from_type, args.from_path, args.to_type, args.to_path)