Commit 330b3374722299c0ddceafcf2772d7ce1701478c
1 parent
aea9578a
Exists in
dev
supprimé fichier install.py (ne sert plus)
Showing
1 changed file
with
0 additions
and
419 deletions
Show diff stats
install/install.py deleted
... | ... | @@ -1,419 +0,0 @@ |
1 | -#!/usr/bin/env python3 | |
2 | - | |
3 | -import platform | |
4 | -import os, sys | |
5 | -import subprocess | |
6 | -import shutil | |
7 | -import fileinput | |
8 | - | |
9 | - | |
10 | -# By default, install the virtual environment AND the database | |
11 | -INSTALL_VENV = True | |
12 | -INSTALL_DB = True | |
13 | - | |
14 | -VENV = "venv_py3_pyros" | |
15 | - | |
16 | -SQL_DATABASE = "pyros" | |
17 | -# Database automatically created by Django for tests (and automatically deleted after tests) | |
18 | -SQL_DATABASE_TEST = "test_pyros" | |
19 | -# Specific database that we need(ed?) for some simulations | |
20 | -SQL_DATABASE_SIMU = "pyros_test" | |
21 | -SQL_USER = "pyros" | |
22 | -SQL_PSWD = "DjangoPyros" | |
23 | -MYSQL_EXE_PATH = "" | |
24 | - | |
25 | -REQUIREMENTS = 'requirements.txt' | |
26 | -##REQUIREMENTS = 'REQUIREMENTS.txt' | |
27 | -#REQUIREMENTS = 'REQUIREMENTS_36.txt' | |
28 | -#REQUIREMENTS = 'REQUIREMENTS_37.txt' | |
29 | -END_OF_LINE = '\n\n' | |
30 | -VENV_BIN = '/bin/' | |
31 | -WINDOWS = False | |
32 | -# -------------------------------------------- | |
33 | -# --- Modified values for Windows | |
34 | -# -------------------------------------------- | |
35 | -if (platform.system() == "Windows"): | |
36 | - WINDOWS = True | |
37 | - REQUIREMENTS = 'requirements_win.txt' | |
38 | - ##REQUIREMENTS = 'REQUIREMENTS_WINDOWS.txt' | |
39 | - #REQUIREMENTS = 'REQUIREMENTS_WINDOWS_36.txt' | |
40 | - END_OF_LINE = "\r\n\r\n" | |
41 | - VENV_BIN = '\\Scripts\\' | |
42 | - #MYSQL_EXE_PATH = "C:/Program Files (x86)/MySQL/MySQL Server 5.0/bin/" | |
43 | - #question = "Enter the path of the MySQL server if it is not the following name (" + MYSQL_EXE_PATH + "): " | |
44 | - #res = input(question) | |
45 | - #if res!="": | |
46 | - # MYSQL_EXE_PATH = res | |
47 | -VENV_PIP = VENV + VENV_BIN+'pip' | |
48 | -VENV_PYTHON = VENV + VENV_BIN+'python' | |
49 | - | |
50 | - | |
51 | -class Colors: | |
52 | - if WINDOWS: | |
53 | - ERROR = '' | |
54 | - END = '' | |
55 | - LOG_BLUE = '' | |
56 | - else: | |
57 | - ERROR = '\033[91m' | |
58 | - END = '\033[0m' | |
59 | - LOG_BLUE = '\033[94m' | |
60 | - | |
61 | - | |
62 | -# GLOBAL_PYTHON = 'python3' | |
63 | -GLOBAL_PYTHON = os.path.split(sys.executable)[-1] | |
64 | -print(Colors.LOG_BLUE + "Python executable is " + GLOBAL_PYTHON + Colors.END) | |
65 | -##if platform.dist()[0] == "centos": print("centos platform") | |
66 | - | |
67 | - | |
68 | - | |
69 | - | |
70 | - | |
71 | -def replacePatternInFile(pattern, replace, file_path): | |
72 | - try: | |
73 | - with fileinput.FileInput(file_path, inplace=True, backup='.bak') as file: | |
74 | - for line in file: | |
75 | - print(line.replace(pattern, replace), end='') | |
76 | - except: | |
77 | - sys.stderr.write(Colors.ERROR + "ERROR !: replacement in file failed !" + Colors.END + "\r\n") | |
78 | - return 1 | |
79 | - return 0 | |
80 | - | |
81 | - | |
82 | -def install_dependency_ubuntu(command, mode): | |
83 | - ''' | |
84 | - Install dependency then check the return code | |
85 | - ''' | |
86 | - old = command | |
87 | - if (mode == 'i'): | |
88 | - command = 'apt-get install ' + command | |
89 | - elif (mode == 'u'): | |
90 | - command = 'apt-get update' | |
91 | - elif (mode == 'a'): | |
92 | - command = 'add-apt-repository ' + command | |
93 | - process = subprocess.Popen(command, shell=True) | |
94 | - process.wait() | |
95 | - if process.returncode != 0: | |
96 | - sys.stderr.write(Colors.ERROR + "ERROR !: installation of " + old + " failed !" + Colors.END + "\r\n") | |
97 | - | |
98 | - | |
99 | -def install_required_ubuntu(): | |
100 | - install_dependency_ubuntu("update", 'u') | |
101 | - install_dependency_ubuntu("python-lxml", 'i') | |
102 | - install_dependency_ubuntu("libxml2-dev", 'i') | |
103 | - install_dependency_ubuntu("libxslt-dev", 'i') | |
104 | - install_dependency_ubuntu("zlib1g-dev", 'i') | |
105 | - install_dependency_ubuntu("update", 'u') | |
106 | - install_dependency_ubuntu("rabbitmq-server", 'i') | |
107 | - #install_dependency_ubuntu("libmysqlclient-dev", 'i') | |
108 | - | |
109 | - | |
110 | -def install_dependency_centos(command, mode): | |
111 | - old = command | |
112 | - if (mode == 'i'): | |
113 | - command = 'yum -y install ' + command | |
114 | - elif (mode == 'u'): | |
115 | - command = 'yum update ' + command | |
116 | - process = subprocess.Popen(command, shell=True) | |
117 | - process.wait() | |
118 | - if process.returncode != 0: | |
119 | - sys.stderr.write(Colors.ERROR + "ERROR !: installation of " + old + " failed !" + Colors.END + "\r\n") | |
120 | - | |
121 | - | |
122 | -def install_required_centos(): | |
123 | - install_dependency_centos("yum", 'u') | |
124 | - install_dependency_centos("kernel", 'u') | |
125 | - install_dependency_centos("", 'u') | |
126 | - install_dependency_centos("libxml2", 'i') | |
127 | - install_dependency_centos("libxslt libxslt-2", 'i') | |
128 | - install_dependency_centos("libxslt-devel libxml2-devel", 'i') | |
129 | - install_dependency_centos("rabbitmq-server", 'i') | |
130 | - install_dependency_centos("mariadb-server", 'i') | |
131 | - install_dependency_centos("mariadb", 'i') | |
132 | - install_dependency_centos("mariadb-devel", 'i') | |
133 | - | |
134 | - process = subprocess.Popen("systemctl start mariadb.service", shell=True) | |
135 | - process.wait() | |
136 | - if process.returncode != 0: | |
137 | - sys.stderr.write(Colors.ERROR + "ERROR !" + Colors.END + "\r\n") | |
138 | - | |
139 | - process = subprocess.Popen("systemctl enable mariadb.service", shell=True) | |
140 | - process.wait() | |
141 | - if process.returncode != 0: | |
142 | - sys.stderr.write(Colors.ERROR + "ERROR !" + Colors.END + "\r\n") | |
143 | - | |
144 | - process = subprocess.Popen("mysql_secure_installation", shell=True) | |
145 | - process.wait() | |
146 | - if process.returncode != 0: | |
147 | - sys.stderr.write(Colors.ERROR + "ERROR !" + Colors.END + "\r\n") | |
148 | - | |
149 | - | |
150 | -def install_required(): | |
151 | - # Checking if user is sudo then install the needed dependencies | |
152 | - # Find the linux distribution and call the related function | |
153 | - distribution = platform.dist() | |
154 | - if not 'SUDO_UID' in os.environ.keys(): | |
155 | - sys.stderr.write("Super user rights are needed to install prerequisites\r\n") | |
156 | - exit(1) | |
157 | - if distribution[0] == "Ubuntu" or distribution[0] == "Debian": | |
158 | - install_required_ubuntu() | |
159 | - elif distribution[0] == "centos": | |
160 | - install_required_centos() | |
161 | - else: | |
162 | - print("Requirements are made for Ubuntu, Debian and CentOS only") | |
163 | - exit(1) | |
164 | - | |
165 | - | |
166 | -def venv_pip_install(package_name:str, options:str=''): | |
167 | - os.system(VENV_PIP + ' install ' + options + ' ' + package_name) | |
168 | - | |
169 | - | |
170 | -def install_venv(venv:str): | |
171 | - | |
172 | - # -------------------------------------------- | |
173 | - # --- Be aware not to create virtual environment in case of user root | |
174 | - # -------------------------------------------- | |
175 | - if 'SUDO_UID' in os.environ.keys(): | |
176 | - answer = input( | |
177 | - "You are about to install your virtualenv only for root, this is discouraged, are you sure ? (Y/N) If you are not sure, relaunch the script without super user privileges\n") | |
178 | - while (answer != 'Y' and answer != 'y' and answer != 'n' and answer != 'N'): | |
179 | - answer = input( | |
180 | - "You are about to install your virtualenv only for root, this is discouraged, are you sure ? (Y/N) \n") | |
181 | - if (answer not in ['y', 'Y']): | |
182 | - exit(1) | |
183 | - | |
184 | - # -------------------------------------------- | |
185 | - # --- Create the (private) venv directory to put in files for virtual environment | |
186 | - # -------------------------------------------- | |
187 | - if (os.path.basename(os.getcwd()) != "venv"): | |
188 | - if not(os.path.isdir("../venv")): | |
189 | - print(Colors.LOG_BLUE + "-----------------------------Creating \'venv\' directory-----------------------------" + Colors.END) | |
190 | - os.mkdir("../venv") | |
191 | - | |
192 | - | |
193 | - # -------------------------------------------- | |
194 | - # --- Deleting if already exist then creating the venv | |
195 | - # -------------------------------------------- | |
196 | - #print(Colors.LOG_BLUE + "-----------------------------cd venv-----------------------------" + Colors.END) | |
197 | - os.chdir("../venv/") | |
198 | - while True: | |
199 | - try: | |
200 | - if (os.path.isdir(venv)): | |
201 | - print(Colors.LOG_BLUE + "-----------------------------Deleting existing venv-----------------------------" + Colors.END) | |
202 | - shutil.rmtree(venv) | |
203 | - break | |
204 | - # Exception on Windows WinError 145 : Cannot remove folder because files in folder not yet removed... | |
205 | - except Exception as e: | |
206 | - #print(e) | |
207 | - continue | |
208 | - | |
209 | - # -------------------------------------------- | |
210 | - # --- Reinstall the virtual environment (from ../venv/) | |
211 | - # -------------------------------------------- | |
212 | - | |
213 | - print(Colors.LOG_BLUE + "-----------------------------Creating venv " + venv + "-----------------------------"+END_OF_LINE + Colors.END) | |
214 | - os.system(GLOBAL_PYTHON+" -m venv " + venv) | |
215 | - | |
216 | - print(Colors.LOG_BLUE + "-----------------------------Upgrade pip, wheel, and setuptools" + "-----------------------------"+END_OF_LINE + Colors.END) | |
217 | - # Upgrade pip | |
218 | - os.system(VENV_PYTHON + ' -m pip install --upgrade pip') | |
219 | - ''' | |
220 | - if (platform.system() == "Windows"): | |
221 | - os.system(venv + '\Scripts\python -m pip install --upgrade pip') | |
222 | - else: # Linux | |
223 | - os.system(venv + '/bin/python -m pip install --upgrade pip') | |
224 | - ''' | |
225 | - | |
226 | - # Pip upgrade wheel and setuptools | |
227 | - venv_pip_install('wheel', '--upgrade') | |
228 | - #os.system(VENV_PIP+' install --upgrade wheel') | |
229 | - venv_pip_install('setuptools', '--upgrade') | |
230 | - #os.system(VENV_PIP+' install --upgrade setuptools') | |
231 | - | |
232 | - # Pip install required packages from REQUIREMENTS file | |
233 | - print() | |
234 | - print(Colors.LOG_BLUE + "-----------------------------Installing python packages via pip-----------------------------" + Colors.END) | |
235 | - venv_pip_install('../install/'+REQUIREMENTS, '-r') | |
236 | - #os.system(VENV_PIP+' install -r ../install' + os.sep + REQUIREMENTS) | |
237 | - | |
238 | - #print(Colors.LOG_BLUE + "-----------------------------cd ../install-----------------------------" + Colors.END) | |
239 | - os.chdir("../install") | |
240 | - | |
241 | - if WINDOWS: | |
242 | - ## moving voeventparse in site-packages directory | |
243 | - try: | |
244 | - site_packages = "..\\venv\\"+VENV+"\\Lib\\site-packages\\" | |
245 | - if (not os.path.isdir(site_packages + "voevent_parse-0.9.5.dist-info") and | |
246 | - not os.path.isdir(site_packages + "voeventparse")): | |
247 | - print(Colors.LOG_BLUE + "\r\n\r\n-----------------------------Copying the voevent library in Lib/site-packages-----------------------------" + Colors.END) | |
248 | - cmdline = "xcopy /i /y windows\\voeventparse " + site_packages + "voeventparse" | |
249 | - process = subprocess.Popen(cmdline) | |
250 | - process.wait() | |
251 | - if (process.returncode != 0): raise Exception | |
252 | - process = subprocess.Popen("xcopy /i /y windows\\voevent_parse-0.9.5.dist-info " + site_packages + "voevent_parse-0.9.5.dist-info") | |
253 | - process.wait() | |
254 | - if (process.returncode != 0): raise Exception | |
255 | - print(Colors.LOG_BLUE + "\r\n-----------------------------library successfully copied-----------------------------" + Colors.END) | |
256 | - except Exception as e: | |
257 | - print(Colors.ERROR + "ERROR while Copying the voevent library in Lib/site-packages" + Colors.END) ; #, file=stderr) | |
258 | - return False | |
259 | - return 0 | |
260 | - | |
261 | - | |
262 | -def install_database(venv): | |
263 | - | |
264 | - print(Colors.LOG_BLUE + END_OF_LINE+"-----------------------------Launching mysql to create database and create and grant user pyros-----------------------------" + Colors.END) | |
265 | - | |
266 | - # -------------------------------------------- | |
267 | - # --- Determine the MySQL version | |
268 | - # -------------------------------------------- | |
269 | - output = subprocess.check_output("mysql --version", shell=True) | |
270 | - # output is something like: "mysql Ver 15.1 Distrib 10.0.20-MariaDB, for Linux (x86_64) using EditLine wrapper" | |
271 | - tmp = (str(output).split()[4]).split('.') | |
272 | - sql_version = float(tmp[0]+'.'+tmp[1]) | |
273 | - print(Colors.LOG_BLUE + "MySQL version is " + str(sql_version) + Colors.END) | |
274 | - | |
275 | - # -------------------------------------------- | |
276 | - # --- Prepare the SQL query to create and initialize the pyros database if needed | |
277 | - # -------------------------------------------- | |
278 | - ''' | |
279 | - (OLD) | |
280 | - sql_query = \ | |
281 | - f"CREATE DATABASE IF NOT EXISTS {SQL_DATABASE}; " +\ | |
282 | - f"CREATE DATABASE IF NOT EXISTS {SQL_DATABASE_SIMU}; " | |
283 | - if sql_version < 5.5: | |
284 | - #sql_query = "drop database "+SQL_DATABASE+" ; CREATE DATABASE "+SQL_DATABASE+"; drop database "+SQL_DATABASE_SIMU+" ; CREATE DATABASE "+SQL_DATABASE_SIMU+"; CREATE USER "+SQL_USER+" ; GRANT USAGE ON *.* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"' WITH GRANT OPTION; DROP USER '"+SQL_USER+"'@'localhost'; GRANT ALL ON "+SQL_DATABASE+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"'; GRANT ALL PRIVILEGES ON "+SQL_DATABASE+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON "+SQL_DATABASE_SIMU+".* TO "+SQL_USER+"@localhost IDENTIFIED BY '"+SQL_PSWD+"' WITH GRANT OPTION;" | |
285 | - sql_query = \ | |
286 | - f"DROP DATABASE {SQL_DATABASE}; CREATE DATABASE {SQL_DATABASE}; " +\ | |
287 | - f"DROP DATABASE {SQL_DATABASE_SIMU}; CREATE DATABASE {SQL_DATABASE_SIMU}; " | |
288 | - sql_query += "CREATE USER "+SQL_USER+" ; GRANT USAGE ON *.* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"' WITH GRANT OPTION; " | |
289 | - sql_query += "DROP USER '"+SQL_USER+"'@'localhost'; " | |
290 | - sql_query += "GRANT ALL ON "+SQL_DATABASE+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"'; " | |
291 | - sql_query += "GRANT ALL PRIVILEGES ON "+SQL_DATABASE+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"' WITH GRANT OPTION; " | |
292 | - sql_query += "GRANT ALL PRIVILEGES ON "+SQL_DATABASE_SIMU+".* TO "+SQL_USER+"@localhost IDENTIFIED BY '"+SQL_PSWD+"' WITH GRANT OPTION; " | |
293 | - ''' | |
294 | - # 1) Create databases pyros and pyros_test (but not test_pyros because will be automatically created by django) | |
295 | - # TODO: Pour mysql < 5.5, comment éviter un "drop database" inutile (si la BD n'existe pas encore) qui va provoquer un plantage mysql ? | |
296 | - IF_EXISTS = '' if sql_version < 5.5 else 'IF EXISTS' | |
297 | - sql_query = \ | |
298 | - f"DROP DATABASE {IF_EXISTS} {SQL_DATABASE}; CREATE DATABASE {SQL_DATABASE}; " +\ | |
299 | - f"DROP DATABASE {IF_EXISTS} {SQL_DATABASE_SIMU}; CREATE DATABASE {SQL_DATABASE_SIMU}; " | |
300 | - | |
301 | - # 2) Create user pyros and give it all rights on 3 databases | |
302 | - # Ne marche pas si l'utilisateur existe déjà => erreur | |
303 | - #"CREATE USER "+SQL_USER+"; " +\ | |
304 | - # Donc, il faut ruser | |
305 | - # Mysql >= 5.7 only: | |
306 | - #sql_query_elem = "CREATE USER IF NOT EXISTS "+SQL_USER+"; " | |
307 | - # Si user n'existe pas => est créé ; Si user existe => pas d'erreur ; DONC ok dans les 2 cas | |
308 | - #sql_query_elem = "GRANT ALL ON "+SQL_DATABASE+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"'; " | |
309 | - sql_query += f"GRANT ALL ON {SQL_DATABASE}.* TO '{SQL_USER}'@localhost IDENTIFIED BY '{SQL_PSWD}'; " | |
310 | - sql_query += f"GRANT ALL ON {SQL_DATABASE_SIMU}.* TO '{SQL_USER}'@localhost IDENTIFIED BY '{SQL_PSWD}'; " | |
311 | - # This database does not yet exists and will be automatically created by Django, but we already give access rights to it for pyros user | |
312 | - sql_query += f"GRANT ALL ON {SQL_DATABASE_TEST}.* TO '{SQL_USER}'@localhost IDENTIFIED BY '{SQL_PSWD}'; " | |
313 | - #"GRANT USAGE ON *.* TO '"+SQL_USER+"'@localhost ; " | |
314 | - | |
315 | - ''' | |
316 | - # (EP) AVANT, y avait tout ça..., vraiment utile ? | |
317 | - "GRANT USAGE ON *.* TO '"+SQL_USER+"'; " +\ | |
318 | - "DROP USER '"+SQL_USER+"'; " +\ | |
319 | - "GRANT ALL ON "+SQL_DATABASE+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"'; " +\ | |
320 | - "GRANT ALL ON "+SQL_DATABASE_SIMU+".* TO '"+SQL_USER+"'@'localhost'; " +\ | |
321 | - "GRANT ALL PRIVILEGES ON "+SQL_DATABASE_SIMU+".* TO '"+SQL_USER+"'@'localhost'; " +\ | |
322 | - "GRANT ALL ON "+SQL_DATABASE_SIMU+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"' ;" | |
323 | - ''' | |
324 | - # NEWER MYSQL: | |
325 | - # OLDER MYSQL: Try this instead for OLDER mysql (works on CentOS 6.4 and Centos 7.5 with mysql 5.5): | |
326 | - #req = "drop database pyros; CREATE DATABASE pyros; drop database pyros_test ; CREATE DATABASE pyros_test; drop user 'pyros'@'localhost' ; CREATE USER pyros; GRANT USAGE ON *.* TO 'pyros'; DROP USER 'pyros'; GRANT ALL ON pyros.* TO 'pyros'@'localhost' IDENTIFIED BY 'DjangoPyros'; GRANT ALL ON test_pyros.* TO 'pyros'@'localhost'; GRANT ALL PRIVILEGES ON test_pyros_test.* TO 'pyros'@'localhost'; GRANT ALL ON pyros_test.* TO 'pyros'@'localhost' IDENTIFIED BY 'DjangoPyros'" | |
327 | - #req = "drop database pyros ; CREATE DATABASE pyros; drop database pyros_test ; CREATE DATABASE pyros_test; DROP USER 'pyros'@'localhost' ; GRANT USAGE ON *.* TO 'pyros'@'localhost' IDENTIFIED BY 'DjangoPyros' WITH GRANT OPTION; DROP USER 'pyros'@'localhost'; GRANT ALL ON pyros.* TO 'pyros'@'localhost' IDENTIFIED BY 'DjangoPyros'; GRANT ALL PRIVILEGES ON pyros.* TO 'pyros'@'localhost' IDENTIFIED BY 'DjangoPyros' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON pyros_test.* TO pyros@localhost IDENTIFIED BY 'DjangoPyros' WITH GRANT OPTION;" | |
328 | - # (EP) ok for CENTOS 7 I suppose (but not for CentOS 6): | |
329 | - #req_centos = "CREATE DATABASE IF NOT EXISTS pyros; CREATE DATABASE IF NOT EXISTS pyros_test; GRANT USAGE ON *.* TO 'pyros'@'localhost' IDENTIFIED BY 'DjangoPyros' WITH GRANT OPTION; DROP USER 'pyros'@'localhost'; GRANT ALL ON pyros.* TO 'pyros'@'localhost' IDENTIFIED BY 'DjangoPyros'; GRANT ALL PRIVILEGES ON pyros.* TO 'pyros'@'localhost' IDENTIFIED BY 'DjangoPyros' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON pyros_test.* TO pyros@localhost IDENTIFIED BY 'DjangoPyros' WITH GRANT OPTION;" | |
330 | - | |
331 | - # --- Prepare the SQL query to create and initialize the pyros database if needed | |
332 | - #if platform.dist()[0] == "centos": | |
333 | - # req = sql_query | |
334 | - #mysql_call_root = '"' + MYSQL_EXE_PATH + 'mysql" -u root -p' | |
335 | - mysql_call_root = 'mysql -u root -p' | |
336 | - mysql_call_pyros = "\"" + MYSQL_EXE_PATH+ "mysql\" -u "+SQL_USER+" -p" | |
337 | - | |
338 | - # -------------------------------------------- | |
339 | - # --- Creating database and creating and granting user pyros | |
340 | - # -------------------------------------------- | |
341 | - user_ros_is_created = True | |
342 | - if sql_version<5.5: | |
343 | - print(Colors.LOG_BLUE +"------------------ Check if the user pyros exists in MYSQL (type the pyros password) -----------------------------" + Colors.END) | |
344 | - # --- We are testing if user pyros already exists in the database | |
345 | - process = subprocess.Popen("echo quit |" + mysql_call_pyros, shell=True) | |
346 | - process.wait() | |
347 | - if (process.returncode == 0): | |
348 | - user_ros_is_created = False | |
349 | - if user_ros_is_created: | |
350 | - # --- The user pyros must be created in the database | |
351 | - print(Colors.LOG_BLUE +"-----------------------------Please enter your MYSQL root password-----------------------------" + Colors.END) | |
352 | - #process = subprocess.Popen("echo \"" + sql_query + "\" |"+ mysql_call_root, shell=True) | |
353 | - sql_cmd = 'echo "' + sql_query + '" | '+ mysql_call_root | |
354 | - print("Executing sql cmd: ", sql_cmd) | |
355 | - process = subprocess.Popen(sql_cmd, shell=True) | |
356 | - process.wait() | |
357 | - if (process.returncode != 0): | |
358 | - sys.stderr.write(Colors.ERROR + "ERROR !: db configuration failed !" + Colors.END + "\r\n") | |
359 | - return -1 | |
360 | - print(Colors.LOG_BLUE + END_OF_LINE+"-----------------------------Database created and user pyros successfully created and granted-----------------------------" + Colors.END) | |
361 | - | |
362 | - # -------------------------------------------- | |
363 | - # --- Replacing pattern in settings.py to use mysql | |
364 | - # -------------------------------------------- | |
365 | - print(Colors.LOG_BLUE + "-----------------------------setting MYSQL = True in settings-----------------------------" + Colors.END) | |
366 | - replacePatternInFile("MYSQL = False", "MYSQL = True", os.path.normpath("../src/core/pyros_django/pyros/settings.py")) | |
367 | - | |
368 | - #print(Colors.LOG_BLUE + "\r\n-----------------------------cd ..-----------------------------" + Colors.END) | |
369 | - os.chdir("..") | |
370 | - | |
371 | - # -------------------------------------------- | |
372 | - # --- Executing migrations | |
373 | - # -------------------------------------------- | |
374 | - | |
375 | - print(Colors.LOG_BLUE + "\r\n\r\n-----------------------------Migrate : executing pyros.py init_database-----------------------------" + Colors.END) | |
376 | - #TODO: from venv !!! | |
377 | - try: | |
378 | - #os.system(GLOBAL_PYTHON+" pyros.py init_database") | |
379 | - os.system(GLOBAL_PYTHON+" pyros.py initdb") | |
380 | - ''' | |
381 | - process = subprocess.Popen(GLOBAL_PYTHON + " pyros.py init_database" , shell=True) | |
382 | - process.wait() | |
383 | - ''' | |
384 | - except Exception as e: | |
385 | - print("Exception ", e) | |
386 | - print(Colors.ERROR + "Error while initializing database :" + Colors.END) | |
387 | - return -1 | |
388 | - | |
389 | - print(Colors.LOG_BLUE + "\r\n\r\n-----------------------------Install successfull !-----------------------------" + Colors.END) | |
390 | - return 0 | |
391 | - | |
392 | - | |
393 | -def _help(): | |
394 | - print( | |
395 | - #"Welcome in the installation script of the pyros venv.\t\nPlease launch it from the install directory of pyros.\n\tIf you're on Ubuntu Debian or CentOS:\n\tlaunch it with sudo and <--prerequisites> or <-p> to install the prerequisites.\n\t-->sudo ./test_install.py -p\n\n\tFor the python packages launch it from the install directory of pyros without sudo and without parameter\n\t-->./test_install.py") | |
396 | - "Welcome to the installation script of the pyros software.\t\n" + \ | |
397 | - "Usage:\n" + \ | |
398 | - " [python] ./pyros.py install [-p] [-d]" | |
399 | - ) | |
400 | - | |
401 | - | |
402 | - | |
403 | - | |
404 | -if __name__ == '__main__': | |
405 | - if len(sys.argv) > 2: _help() ; sys.exit(1) | |
406 | - #print(sys.argv) | |
407 | - if len(sys.argv) == 2: | |
408 | - INSTALL_VENV = INSTALL_DB = False | |
409 | - if sys.argv[1] == '-p': INSTALL_VENV=True | |
410 | - if sys.argv[1] == '-d': INSTALL_DB=True | |
411 | - ''' | |
412 | - # Prerequisistes installation (for CentOS) => not a good idea for now, deactivated (EP) | |
413 | - if sys.argv[1] == "--prerequisites" or sys.argv[1] == "-p": | |
414 | - install_required() | |
415 | - else: | |
416 | - _help() | |
417 | - ''' | |
418 | - if INSTALL_VENV: install_venv(VENV) | |
419 | - if INSTALL_DB: install_database(VENV) |