-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
158 lines (129 loc) · 5.59 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import os
import io
import sys
import json
from distutils.dir_util import copy_tree
from tools import fdb_to_sqlite
from os import system, name
def clear():
if name == 'nt':
_ = system('cls')
else:
_ = system('clear')
def setup_resources():
print("Welcome to the Setup tool for OpenLU\n")
print("Some pre requisites are required before we start")
print("1. OpenLU: https://github.com/MashedTatoes/OpenLU\n")
print("2. Lego Universe unpacked client: https://docs.google.com/document/d/1XmHXWuUQqzUIOcv6SVVjaNBm4bFg9lnW4Pk1pllimEg/edit\n\t(humanoid/lcdr’s unpacked client reccomended)")
print("3. MySql: https://dev.mysql.com/downloads/mysql/")
input("Once you are ready to continue press any key")
global openluResDir
openluResDir = "OpenLU\Resources"
if sys.platform == "win32":
appdir = os.path.expanduser("~\Documents")
openluResDir = os.path.join(appdir,openluResDir)
elif sys.platform.startswith('linux'):
appdir = os.path.expanduser('~')
openluResDir = os.path.join(appdir,".%s" % openluResDir)
elif sys.platform == 'darwin':
appdir = "%s/Libary/Application" % os.path.expanduser('~')
openluResDir = os.path.join(appdir,openluResDir)
else:
print ("Operating system %s not supported" % sys.platform)
return -1
if os.path.isdir(openluResDir) == False:
print("Making OpenLU resource directory at '%s'\n" % openluResDir)
os.makedirs(openluResDir)
input("Once you are ready to continue press any key")
luClientResDir = ""
while os.path.isdir(luClientResDir) == False or luClientResDir == "":
clear()
print("Please input the path of the res directory in you Lego Universe client\n")
luClientResDir = input(">>")
usr_input = ""
while usr_input.lower() != "y" and usr_input.lower() != "n" :
print("{} needs to be copied to {}\ndo you want to do this step automatically[y/n]? (Could take a few minutes)\n".format( luClientResDir, openluResDir))
usr_input = input(">>")
clear()
if usr_input.lower() == "y" :
print("Copying client resource files to OpenLU Resource directory...")
copy_tree(luClientResDir,openluResDir)
print("Done!")
input("Press any key to continue")
clear()
else:
input("Skipped copying resources\nPlease do it manually\nOnce you are press any key to continue")
if os.path.exists("%s/cdclient.fdb"% openluResDir) and os.path.exists("%s/cdclient.db"% openluResDir) == False:
print("Creating client sqlite database")
in_path = "%s/cdclient.fdb" % openluResDir
out_path= "%s/cdclient.db" % openluResDir
fdb_to_sqlite.start(in_path,out_path)
input("Finished setting up Resources\nPress any key to continue")
return 0
def setup_db():
input("Press enter to start database setup")
accepted_db = ["mysql","sqlite"]
global user_db
user_db = ""
while (user_db.lower() in accepted_db) == False:
clear()
print("Input sql provider, accpeted providers are:\n")
for db in accepted_db:
print(db)
user_db = input(">>")
clear()
global connection_string
ok = False
while ok == False:
clear()
if user_db == "mysql":
print("Please follow the prompts to create your connection string")
connection_string = "server={};database={};user id={};password={};persistsecurityinfo=True;port={}"
server_ip = input("Enter mysql server address >> ")
database = input("Enter mysql database name >> ")
user_id = input("Enter mysql database user id >> ")
pwd = input("Enter my sql database password >> ")
port = input("Enter mysql server port (leave blank for 3306) >> ")
if port == "" or port == None:
port = 3306
connection_string = connection_string.format(server_ip,database,user_id,pwd,port)
elif user_db == "sqlite":
connection_string = "Data Source = {}"
data_source = input("Please enter the desired location of your database >> ")
connection_string = connection_string.format(data_source)
usr_input = ""
while usr_input.lower() != "y" and usr_input.lower() != "n" :
print("Your connection string is %s\nis this ok? [y/n]" % connection_string)
usr_input = input(">>")
clear()
if usr_input.lower() == "y":
ok = True
def setup_cfg():
input("Press any to setup OpenLU configuration file (last step!)")
openlu_install = ""
while os.path.isdir(openlu_install) == False or openlu_install == "":
clear()
print("Enter OpenLU install directory (containing OpenLU.sln)")
openlu_install = input(">>")
config_file = {
"connectionString" : connection_string,
"luResources" : openluResDir,
"provider" : user_db
}
cfg_sln = "%s/OpenLU.Configuration" % openlu_install
if os.path.isdir(cfg_sln):
cfg_file = None
cfg_file_path = "%s/cfg.json" % cfg_sln
if os.path.exists(cfg_sln):
cfg_file = open(cfg_file_path,"w")
else :
cfg_file = open(cfg_file_path,"x")
cfg_file.write(json.dumps(config_file))
cfg_file.close()
print("Config file save to %s" % cfg_file_path)
else:
print("Could not find OpenLU.Configuration\nExiting...")
if __name__ == "__main__":
if setup_resources() == 0:
setup_db()
setup_cfg()