forked from LTD-Beget/sprutio-rpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_init.py
131 lines (118 loc) · 5.37 KB
/
db_init.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python
import os
import sqlite3
import traceback
from sqlite3 import OperationalError
from config.main import DB_FILE
if os.path.exists(DB_FILE):
print("Database already created")
db = sqlite3.connect(DB_FILE)
db.execute("PRAGMA journal_mode=MEMORY")
print("Database created and opened successfully file = %s" % DB_FILE)
cursor = db.cursor()
try:
try:
cursor.execute('''CREATE TABLE ftp_servers (
id INTEGER PRIMARY KEY NOT NULL,
fm_login TEXT,
host TEXT,
port INTEGER,
user TEXT,
password TEXT
);''')
cursor.execute('''CREATE INDEX ftp_servers_fm_login ON ftp_servers (fm_login);''')
print("table ftp_servers created successfully")
except OperationalError as e:
if str(e) == "table ftp_servers already exists":
print(e)
else:
raise(e)
try:
cursor.execute('''CREATE TABLE sftp_servers (
id INTEGER PRIMARY KEY NOT NULL,
fm_login TEXT,
host TEXT,
port INTEGER,
user TEXT,
password TEXT
);''')
cursor.execute('''CREATE INDEX sftp_servers_fm_login ON sftp_servers (fm_login);''')
print("table sftp_servers created successfully")
except OperationalError as e:
if str(e) == "table sftp_servers already exists":
print(e)
else:
raise(e)
try:
cursor.execute('''CREATE TABLE webdav_servers (
id INTEGER PRIMARY KEY NOT NULL,
fm_login TEXT,
host TEXT,
user TEXT,
password TEXT
);''')
cursor.execute('''CREATE INDEX webdav_servers_fm_login ON webdav_servers (fm_login);''')
print("table webdav_servers created successfully")
except OperationalError as e:
if str(e) == "table webdav_servers already exists":
print(e)
else:
raise(e)
try:
cursor.execute('''CREATE TABLE editor_settings (
id INTEGER PRIMARY KEY NOT NULL,
fm_login TEXT,
print_margin_size INTEGER,
font_size INTEGER,
tab_size INTEGER,
full_line_selection INTEGER,
highlight_active_line INTEGER,
show_invisible INTEGER,
wrap_lines INTEGER,
use_soft_tabs INTEGER,
show_line_numbers INTEGER,
highlight_selected_word INTEGER,
show_print_margin INTEGER,
use_autocompletion INTEGER,
enable_emmet INTEGER,
code_folding_type TEXT,
theme TEXT
);''')
cursor.execute('''CREATE INDEX editor_settings_fm_login ON editor_settings (fm_login);''')
print("table editor_settings created successfully")
except OperationalError as e:
if str(e) == "table editor_settings already exists":
print(e)
else:
raise(e)
try:
cursor.execute('''CREATE TABLE viewer_settings (
id INTEGER PRIMARY KEY NOT NULL,
fm_login TEXT,
print_margin_size INTEGER,
font_size INTEGER,
tab_size INTEGER,
full_line_selection INTEGER,
highlight_active_line INTEGER,
show_invisible INTEGER,
wrap_lines INTEGER,
use_soft_tabs INTEGER,
show_line_numbers INTEGER,
highlight_selected_word INTEGER,
show_print_margin INTEGER,
code_folding_type TEXT,
theme TEXT
);''')
cursor.execute('''CREATE INDEX viewer_settings_fm_login ON viewer_settings (fm_login);''')
print("table viewer_settings created successfully")
except OperationalError as e:
if str(e) == "table viewer_settings already exists":
print(e)
else:
raise(e)
print("All tables created successfully or alreandy exists")
db.commit()
except Exception as e:
print('Error while creating DB %s -- Traceback: %s' % (str(e), traceback.format_exc()))
finally:
db.close()