-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
99 lines (89 loc) · 4.51 KB
/
main.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import os
import argparse
import logging
from lib import multi_thread, single_thread
from prop.properties import Properties
def main():
fmt = logging.Formatter(fmt='[%(asctime)s] [%(levelname)s] >>> %(message)s', datefmt='%Y-%m-%d %I:%M:%S')
if not os.path.exists("log"):
os.mkdir("log")
if not os.path.exists("sqlite"):
os.mkdir("sqlite")
file1 = logging.FileHandler(filename='log/error.log', mode='a', encoding='utf-8')
file1.setFormatter(fmt)
error_log = logging.Logger(name='ERROR_LOG', level=logging.ERROR)
error_log.addHandler(file1)
file2 = logging.FileHandler(filename='log/info.log', mode='a', encoding='utf-8')
file2.setFormatter(fmt)
info_log = logging.Logger(name='INFO_LOG', level=logging.INFO)
info_log.addHandler(file2)
parser = argparse.ArgumentParser(description='Data Migration Script')
parser.add_argument("--opengauss", "-o", default="")
parser.add_argument("--sqlite", "-s", default="")
parser.add_argument("--multithreading", "-m", action="store_true")
args = parser.parse_args()
opengauss_properties = {}
is_file_update = False
if args.opengauss != '':
opengauss_file = 'prop/' + str(args.opengauss)
p = Properties(opengauss_file)
opengauss_properties = p.get_properties()
else:
opengauss_file = 'prop/opengauss.properties'
if not opengauss_properties.__contains__('database.name') or opengauss_properties['database.name'] == '':
opengauss_properties['database.name'] = input("Input the database name of OpenGauss:")
is_file_update = True
if not opengauss_properties.__contains__('database.schema') or opengauss_properties['database.schema'] == '':
opengauss_properties['database.schema'] = input("Input the schema name of OpenGauss:")
is_file_update = True
if not opengauss_properties.__contains__('database.host') or opengauss_properties['database.host'] == '':
opengauss_properties['database.host'] = input("Input the host of OpenGauss:")
is_file_update = True
if not opengauss_properties.__contains__('database.port') or opengauss_properties['database.port'] == '':
opengauss_properties['database.port'] = input("Input the port of OpenGauss:")
is_file_update = True
if not opengauss_properties.__contains__('database.user') or opengauss_properties['database.user'] == '':
opengauss_properties['database.user'] = input("Input the username of OpenGauss:")
is_file_update = True
if not opengauss_properties.__contains__('database.password') or opengauss_properties['database.password'] == '':
opengauss_properties['database.password'] = input("Input the user password of OpenGauss:")
is_file_update = True
if is_file_update:
save_message = "Save your input in the %s? [y/n]" % opengauss_file
flag = input(save_message)
if flag.upper() == 'Y' or flag.upper() == 'YES':
Properties.write_properties(opengauss_file, opengauss_properties)
sqlite_properties = {}
is_file_update = False
if args.sqlite != '':
sqlite_file = str(args.sqlite)
sqlite_file = "prop/" + sqlite_file
p = Properties(sqlite_file)
sqlite_properties = p.get_properties()
else:
sqlite_file = 'prop/sqlite.properties'
if not sqlite_properties.__contains__('database.filename'):
sqlite_properties['database.filename'] = input("Input the filename of Sqlite3:")
is_file_update = True
if is_file_update:
save_message = "Save your input in the %s? [y/n]" % sqlite_file
flag = input(save_message)
if flag.upper() == 'Y' or flag.upper() == 'YES':
Properties.write_properties(sqlite_file, sqlite_properties)
sqls_log = None
flag = input("Save the SQL statements in Data Migration? [y/n]")
is_record_sqls = False
if flag.upper() == 'Y' or flag.upper() == 'YES':
is_record_sqls = True
file3 = logging.FileHandler(filename='log/sqls.log', mode='a', encoding='utf-8')
file3.setFormatter(fmt)
sqls_log = logging.Logger(name='SQLS_LOG', level=logging.DEBUG)
sqls_log.addHandler(file3)
if args.multithreading:
multi_thread.multi_thread(opengauss_properties, sqlite_properties, error_log, info_log, sqls_log,
is_record_sqls)
else:
single_thread.single_thread(opengauss_properties, sqlite_properties, error_log, info_log, sqls_log,
is_record_sqls)
if __name__ == '__main__':
main()