Commit cd21eb386318d31cbe42668d3cdb07f52f87e681
1 parent
564a4812
Exists in
dev
fixing pyros.py for classic installation (without docker)
Showing
1 changed file
with
172 additions
and
141 deletions
Show diff stats
pyros.py
... | ... | @@ -9,13 +9,13 @@ |
9 | 9 | |
10 | 10 | ''' *** STANDARD IMPORTS *** ''' |
11 | 11 | |
12 | -#import logging | |
12 | +# import logging | |
13 | 13 | |
14 | 14 | |
15 | 15 | ''' *** PROJECT IMPORTS *** ''' |
16 | -#from src.pyros_logger import * | |
17 | -#from src.pyros_logger import log, log_d,log_i,log_w,log_e,log_c | |
18 | -#from src import pyros_logger | |
16 | +# from src.pyros_logger import * | |
17 | +# from src.pyros_logger import log, log_d,log_i,log_w,log_e,log_c | |
18 | +# from src import pyros_logger | |
19 | 19 | |
20 | 20 | |
21 | 21 | """ |
... | ... | @@ -24,7 +24,7 @@ |
24 | 24 | ***************************************************************** |
25 | 25 | """ |
26 | 26 | |
27 | -#DEBUG = False | |
27 | +# DEBUG = False | |
28 | 28 | |
29 | 29 | |
30 | 30 | from src.pyros_logger import log |
... | ... | @@ -72,10 +72,10 @@ AGENTS = { |
72 | 72 | "scheduler": "scheduler", |
73 | 73 | "alert_manager": "alert_manager" |
74 | 74 | } |
75 | -#AGENTS = ["agentX", "webserver", "monitoring", "majordome", "scheduler", "alert_manager"] | |
76 | -#AGENTS = ["all", "webserver", "monitoring", "majordome", "scheduler", "alert"] | |
75 | +# AGENTS = ["agentX", "webserver", "monitoring", "majordome", "scheduler", "alert_manager"] | |
76 | +# AGENTS = ["all", "webserver", "monitoring", "majordome", "scheduler", "alert"] | |
77 | 77 | |
78 | -#COMMANDS = {"install": [], "start": AGENTS, "stop": AGENTS} | |
78 | +# COMMANDS = {"install": [], "start": AGENTS, "stop": AGENTS} | |
79 | 79 | |
80 | 80 | REQUIREMENTS = 'requirements.txt' |
81 | 81 | REQUIREMENTS_DEV = 'requirements_dev.txt' |
... | ... | @@ -83,7 +83,7 @@ REQUIREMENTS_DEV = 'requirements_dev.txt' |
83 | 83 | b_in_dir = "bin" |
84 | 84 | PYTHON = "python3" |
85 | 85 | # should also be ok from venv: |
86 | -#PYTHON = "python" | |
86 | +# PYTHON = "python" | |
87 | 87 | |
88 | 88 | IS_WINDOWS = platform.system() == "Windows" |
89 | 89 | if IS_WINDOWS: |
... | ... | @@ -105,7 +105,7 @@ else: |
105 | 105 | WITH_DOCKER = False |
106 | 106 | |
107 | 107 | my_abs_path = os.path.dirname(os.path.realpath(__file__)) |
108 | -#VENV_ROOT = "private" | |
108 | +# VENV_ROOT = "private" | |
109 | 109 | if WITH_DOCKER: |
110 | 110 | VENV_ROOT = "" |
111 | 111 | VENV = "" |
... | ... | @@ -164,27 +164,27 @@ ENV_SAMPLE_PATH = "docker/.env-sample" |
164 | 164 | |
165 | 165 | |
166 | 166 | END_OF_LINE = '\n\n' |
167 | -##VENV_BIN = '/bin/' | |
167 | +# VENV_BIN = '/bin/' | |
168 | 168 | # -------------------------------------------- |
169 | 169 | # --- Modified values for Windows |
170 | 170 | # -------------------------------------------- |
171 | 171 | if (platform.system() == "Windows"): |
172 | 172 | END_OF_LINE = "\r\n\r\n" |
173 | - ##VENV_BIN = '\\Scripts\\' | |
174 | - #MYSQL_EXE_PATH = "C:/Program Files (x86)/MySQL/MySQL Server 5.0/bin/" | |
175 | - #question = "Enter the path of the MySQL server if it is not the following name (" + MYSQL_EXE_PATH + "): " | |
176 | - #res = input(question) | |
173 | + # VENV_BIN = '\\Scripts\\' | |
174 | + # MYSQL_EXE_PATH = "C:/Program Files (x86)/MySQL/MySQL Server 5.0/bin/" | |
175 | + # question = "Enter the path of the MySQL server if it is not the following name (" + MYSQL_EXE_PATH + "): " | |
176 | + # res = input(question) | |
177 | 177 | # if res!="": |
178 | - #MYSQL_EXE_PATH = res | |
178 | + # MYSQL_EXE_PATH = res | |
179 | 179 | |
180 | -#VENV_PIP = VENV + VENV_BIN+'pip' | |
181 | -##VENV_BIN = VENV + VENV_BIN+'python' | |
180 | +# VENV_PIP = VENV + VENV_BIN+'pip' | |
181 | +# VENV_BIN = VENV + VENV_BIN+'python' | |
182 | 182 | |
183 | 183 | # GLOBAL_PYTHON = 'python3' |
184 | 184 | GLOBAL_PYTHON = os.path.split(sys.executable)[-1] |
185 | 185 | log.debug(Colors.LOG_BLUE + "Python executable is " + |
186 | 186 | GLOBAL_PYTHON + Colors.END) |
187 | -##if platform.dist()[0] == "centos": print("centos platform") | |
187 | +# if platform.dist()[0] == "centos": print("centos platform") | |
188 | 188 | |
189 | 189 | |
190 | 190 | """ |
... | ... | @@ -193,11 +193,11 @@ log.debug(Colors.LOG_BLUE + "Python executable is " + |
193 | 193 | ************************************************************************************************* |
194 | 194 | """ |
195 | 195 | # First thing first, install the click package !!! |
196 | -#import fire | |
196 | +# import fire | |
197 | 197 | try: |
198 | 198 | import click # https://click.palletsprojects.com |
199 | 199 | except: |
200 | - #pip = "pip" if platform.system() == "Windows" else "pip3" | |
200 | + # pip = "pip" if platform.system() == "Windows" else "pip3" | |
201 | 201 | # TODO: "python -m pip" au lieu de "pip" |
202 | 202 | pip = "pip" if IS_WINDOWS else "pip3" |
203 | 203 | process = subprocess.Popen(pip + " install --upgrade click", shell=True) |
... | ... | @@ -237,7 +237,7 @@ def die(msg: str = ""): |
237 | 237 | # TODO: implement is_async |
238 | 238 | def execProcess(command, from_venv=False, is_async=False): |
239 | 239 | from_venv_str = " from venv ("+VENV_PYTHON+")" if from_venv else "" |
240 | - #printFullTerm(Colors.BLUE, "Executing command" + " [" + command + "]" + from_venv_str) | |
240 | + # printFullTerm(Colors.BLUE, "Executing command" + " [" + command + "]" + from_venv_str) | |
241 | 241 | log.debug("Executing command" + " [" + command + "]" + from_venv_str) |
242 | 242 | if from_venv: |
243 | 243 | command = VENV_PYTHON+' ' + command |
... | ... | @@ -269,7 +269,8 @@ def execProcessFromVenvAsync(command: str): |
269 | 269 | """ |
270 | 270 | args = command.split() |
271 | 271 | printFullTerm( |
272 | - Colors.BLUE, "Executing command from venv [" + str(" ".join(args[1:])) + "]" | |
272 | + Colors.BLUE, "Executing command from venv [" + \ | |
273 | + str(" ".join(args[1:])) + "]" | |
273 | 274 | ) |
274 | 275 | p = subprocess.Popen(args) |
275 | 276 | subproc.append((p, " ".join(args[1:]))) |
... | ... | @@ -281,7 +282,7 @@ def execProcessFromVenvAsync(command: str): |
281 | 282 | |
282 | 283 | |
283 | 284 | def printColor(color: Colors, message, file=sys.stdout, eol=os.linesep, forced=False): |
284 | - #system = platform.system() | |
285 | + # system = platform.system() | |
285 | 286 | """ |
286 | 287 | if (self.disp == False and forced == False): |
287 | 288 | return 0 |
... | ... | @@ -295,7 +296,7 @@ def printColor(color: Colors, message, file=sys.stdout, eol=os.linesep, forced=F |
295 | 296 | |
296 | 297 | |
297 | 298 | def printFullTerm(color: Colors, string: str): |
298 | - #system = platform.system() | |
299 | + # system = platform.system() | |
299 | 300 | columns = 100 |
300 | 301 | row = 1000 |
301 | 302 | disp = True |
... | ... | @@ -317,8 +318,9 @@ def set_environment_variables_if_not_configured(env_path: str, env_sample_path: |
317 | 318 | env_sample_path (str): path to .env-sample file |
318 | 319 | """ |
319 | 320 | """ |
320 | - variables_names = ["MYSQL_ROOT_PASSWORD","MYSQL_ROOT_LOGIN","MYSQL_TCP_PORT","MYSQL_PYROS_LOGIN","MYSQL_PYROS_PWD","PATH_TO_OBSCONF_FILE"] | |
321 | - is_environment_variables_defined = True | |
321 | + variables_names = ["MYSQL_ROOT_PASSWORD","MYSQL_ROOT_LOGIN","MYSQL_TCP_PORT", | |
322 | + "MYSQL_PYROS_LOGIN","MYSQL_PYROS_PWD","PATH_TO_OBSCONF_FILE"] | |
323 | + is_environment_variables_defined = True | |
322 | 324 | while(is_environment_variables_defined): |
323 | 325 | for variable in variables_names: |
324 | 326 | if( os.environ.get(variable) is None): |
... | ... | @@ -355,7 +357,7 @@ def set_environment_variables_if_not_configured(env_path: str, env_sample_path: |
355 | 357 | os.environ[key] = value |
356 | 358 | |
357 | 359 | except: |
358 | - #print(f".env not found at {env_path} or is empty, creating a file at this path from the .env-sample file stored at {ENV_SAMPLE_PATH}\nvalues from .env-sample will be used as environment variables") | |
360 | + # print(f".env not found at {env_path} or is empty, creating a file at this path from the .env-sample file stored at {ENV_SAMPLE_PATH}\nvalues from .env-sample will be used as environment variables") | |
359 | 361 | with open(env_sample_path, 'r') as env_sample_file: |
360 | 362 | with open(env_path, "w") as env_file: |
361 | 363 | for env_sample_line in env_sample_file: |
... | ... | @@ -384,10 +386,13 @@ else: |
384 | 386 | |
385 | 387 | ''' |
386 | 388 | _global_test_options = [ |
387 | - click.option('--test', '-t', is_flag=True, help="don't do it for real, just show what it would do"), | |
388 | - click.option('--verbose', '-v', 'verbosity', flag_value=2, default=1, help='Verbose output'), | |
389 | - click.option('--quiet', '-q', 'verbosity', flag_value=0, help='Minimal output'), | |
390 | - #click.option('--fail-fast', '--failfast', '-f', 'fail_fast', is_flag=True, default=False, help='Stop on failure'), | |
389 | + click.option('--test', '-t', is_flag=True, | |
390 | + help="don't do it for real, just show what it would do"), | |
391 | + click.option('--verbose', '-v', 'verbosity', flag_value=2, | |
392 | + default=1, help='Verbose output'), | |
393 | + click.option('--quiet', '-q', 'verbosity', | |
394 | + flag_value=0, help='Minimal output'), | |
395 | + # click.option('--fail-fast', '--failfast', '-f', 'fail_fast', is_flag=True, default=False, help='Stop on failure'), | |
391 | 396 | ] |
392 | 397 | def global_test_options(func): |
393 | 398 | for option in reversed(_global_test_options): |
... | ... | @@ -417,18 +422,18 @@ def debug_mode(): return GLOBAL_OPTIONS["debug"] |
417 | 422 | # @click.option('--quiet', '-q', 'verbosity', flag_value=0, help='Minimal output'), |
418 | 423 | # @click.option('--fail-fast', '--failfast', '-f', 'fail_fast', is_flag=True, default=False, help='Stop on failure'), |
419 | 424 | def pyros_launcher(debug, sim, test, verbose): |
420 | - ##global log | |
421 | - #log.info("in pyros launcher") | |
425 | + # global log | |
426 | + # log.info("in pyros launcher") | |
422 | 427 | # pass |
423 | 428 | os.environ['PYROS_DEBUG'] = '1' if debug else '0' |
424 | 429 | |
425 | 430 | # pyros_logger.set_logger_config() |
426 | - ##log = logging.getLogger('pyroslogger') | |
431 | + # log = logging.getLogger('pyroslogger') | |
427 | 432 | log.debug('starting pyros') |
428 | - #log.info('info toto msg from pyros') | |
429 | - #log.warning('warntoto msg from pyros') | |
430 | - #log.error('error toto msg from pyros') | |
431 | - #log.critical('error toto msg from pyros') | |
433 | + # log.info('info toto msg from pyros') | |
434 | + # log.warning('warntoto msg from pyros') | |
435 | + # log.error('error toto msg from pyros') | |
436 | + # log.critical('error toto msg from pyros') | |
432 | 437 | |
433 | 438 | if debug: |
434 | 439 | click.echo('DEBUG mode') |
... | ... | @@ -509,20 +514,20 @@ def update(): |
509 | 514 | # 1) Update source code (git pull) |
510 | 515 | printFullTerm(Colors.BLUE, "1) UPDATING SOURCE CODE: Running git pull") |
511 | 516 | _gitpull() or die() |
512 | - | |
517 | + | |
513 | 518 | # Re-install VENV if disappeared |
514 | 519 | install_venv(False) |
515 | - | |
520 | + | |
516 | 521 | # 2) Update python packages (pip upgrade AND pip install requirements) |
517 | 522 | printFullTerm(Colors.BLUE, "2) UPDATING PYTHON PACKAGES") |
518 | - ##_update_python_packages_from_requirements() or die() | |
523 | + # _update_python_packages_from_requirements() or die() | |
519 | 524 | install_packages() |
520 | 525 | print(os.getcwd()) |
521 | 526 | # 3) Update PlantUML diagrams |
522 | 527 | printFullTerm(Colors.BLUE, "3) UPDATING PLANTUML DIAGRAMS") |
523 | 528 | _update_plantuml_diags() or die() |
524 | 529 | print(os.getcwd()) |
525 | - | |
530 | + | |
526 | 531 | # 4) Update database structure (make migrations + migrate) |
527 | 532 | printFullTerm(Colors.BLUE, "4) UPDATING DATABASE") |
528 | 533 | _updatedb() or die() |
... | ... | @@ -537,12 +542,13 @@ def update(): |
537 | 542 | def install(packages_only, database_only): |
538 | 543 | with_packages = not database_only |
539 | 544 | with_database = not packages_only |
540 | - install_or_update(UPDATE=False, with_packages=with_packages, with_database=with_database) | |
541 | - #install_or_update(UPDATE=False, with_packages=packages_only, with_database=database_only) | |
542 | - #install_or_update(UPDATE=False, packages_only=packages_only, database_only=database_only) | |
545 | + install_or_update(UPDATE=False, with_packages=with_packages, | |
546 | + with_database=with_database) | |
547 | + # install_or_update(UPDATE=False, with_packages=packages_only, with_database=database_only) | |
548 | + # install_or_update(UPDATE=False, packages_only=packages_only, database_only=database_only) | |
543 | 549 | |
544 | 550 | |
545 | -#def install_or_update(UPDATE: bool = False, with_packages: bool = False, with_database: bool = False): | |
551 | +# def install_or_update(UPDATE: bool = False, with_packages: bool = False, with_database: bool = False): | |
546 | 552 | def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_database: bool = True): |
547 | 553 | SQL_USER = os.environ.get("MYSQL_PYROS_LOGIN").strip() |
548 | 554 | SQL_PSWD = os.environ.get("MYSQL_PYROS_PWD").strip() |
... | ... | @@ -550,14 +556,35 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat |
550 | 556 | PYROS_DJANGO_BASE_DIR), "../../../privatedev/config/default/") |
551 | 557 | ACTION = "UPDATING" if UPDATE else "INSTALLING" |
552 | 558 | |
553 | - #if WITH_DOCKER: with_database = True | |
554 | - if WITH_DOCKER: with_packages = False | |
559 | + # if WITH_DOCKER: with_database = True | |
560 | + if WITH_DOCKER: | |
561 | + with_packages = False | |
555 | 562 | |
556 | - #if not with_packages and not with_database: with_packages = with_database = True | |
563 | + # if not with_packages and not with_database: with_packages = with_database = True | |
557 | 564 | |
558 | 565 | print("- with_packages:", with_packages) |
559 | 566 | print("- with_database:", with_database) |
560 | - | |
567 | + | |
568 | + # if test_mode(): print("in test mode") | |
569 | + # self.execProcess("python3 install/install.py install") | |
570 | + # if (os.path.basename(os.getcwd()) != "private"): | |
571 | + | |
572 | + num = 0 | |
573 | + # 1) Update source code (git pull) | |
574 | + if UPDATE: | |
575 | + num += 1 | |
576 | + printFullTerm( | |
577 | + Colors.BLUE, f"{num}) UPDATING SOURCE CODE: Running git pull") | |
578 | + if not WITH_DOCKER: | |
579 | + _gitpull() or die() | |
580 | + | |
581 | + # 2) Update python packages (pip upgrade AND pip install requirements) | |
582 | + if with_packages: | |
583 | + num += 1 | |
584 | + printFullTerm(Colors.BLUE, f"{num}) {ACTION} PYTHON PACKAGES") | |
585 | + # (UPDATE) Re-install VENV if disappeared | |
586 | + install_venv(EVEN_IF_ALREADY_EXISTS=not UPDATE) | |
587 | + install_packages() | |
561 | 588 | if UPDATE: |
562 | 589 | print("Running UPDATE command") |
563 | 590 | else: |
... | ... | @@ -567,8 +594,12 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat |
567 | 594 | from git import Repo |
568 | 595 | except: |
569 | 596 | pip = "pip" if IS_WINDOWS else "pip3" |
570 | - process = subprocess.Popen( | |
571 | - pip + " install --user --upgrade GitPython", shell=True) | |
597 | + if WITH_DOCKER: | |
598 | + process = subprocess.Popen( | |
599 | + pip + " install --user --upgrade GitPython", shell=True) | |
600 | + else: | |
601 | + process = subprocess.Popen( | |
602 | + pip + " install --upgrade GitPython", shell=True) | |
572 | 603 | process.wait() |
573 | 604 | if process.returncode == 0: |
574 | 605 | # self.addExecuted(self.current_command, command) |
... | ... | @@ -576,9 +607,23 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat |
576 | 607 | else: |
577 | 608 | log.error( |
578 | 609 | "GitPython package (required for obsconfig class) installation failed") |
610 | + ''' | |
611 | + print("Guitastro : Generating (updating) API documentation (using Sphinx)") | |
612 | + # Make html doc from RST | |
613 | + # cd doc/sourcedoc/ | |
614 | + change_dir(GUITASTRO_PATH + '/doc_rst/') | |
615 | + # ./MAKE_DOC.sh | |
616 | + res = execProcess('/bin/bash MAKE_DOC.sh') | |
617 | + # Come back to where we were before | |
618 | + # cd - | |
619 | + change_dir("PREVIOUS") | |
620 | + ''' | |
579 | 621 | |
580 | 622 | # Guitastro |
581 | 623 | GUITASTRO_PATH = os.path.join(os.getcwd(), "./vendor/guitastro") |
624 | + if not WITH_DOCKER: | |
625 | + #GUITASTRO_PATH = os.path.join(os.getcwd(), "../vendor/guitastro") | |
626 | + change_dir("..") | |
582 | 627 | print(os.getcwd()) |
583 | 628 | # 1) clone repo if not yet done |
584 | 629 | if not os.path.exists(GUITASTRO_PATH): |
... | ... | @@ -588,47 +633,19 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat |
588 | 633 | print("Cloned successfully: ", cloned_repo.__class__ is Repo) |
589 | 634 | # 2) install/update requirements & generate API doc |
590 | 635 | if os.path.exists(GUITASTRO_PATH): |
591 | - #TODO: update guitastro (git pull from vendor/guitastro/) | |
636 | + # TODO: update guitastro (git pull from vendor/guitastro/) | |
592 | 637 | print("\nGuitastro : Installing/Updating python package dependencies\n") |
593 | 638 | # Upgrade pip if new version available |
594 | - os.system(VENV_PYTHON + ' -m pip install --user --upgrade pip') | |
595 | - #TODO: faire les apt-get intall aussi (indi, ...) | |
639 | + if WITH_DOCKER: | |
640 | + os.system(VENV_PYTHON + ' -m pip install --user --upgrade pip') | |
641 | + else: | |
642 | + os.system(VENV_PYTHON + ' -m pip install --upgrade pip') | |
643 | + # TODO: faire les apt-get intall aussi (indi, ...) | |
596 | 644 | venv_pip_install2(GUITASTRO_PATH + '/install/requirements.txt', '-r') |
597 | - venv_pip_install2(GUITASTRO_PATH + '/install/requirements_linux.txt', '-r') | |
598 | - venv_pip_install2(GUITASTRO_PATH + '/install/requirements_dev.txt', '-r') | |
599 | - ''' | |
600 | - print("Guitastro : Generating (updating) API documentation (using Sphinx)") | |
601 | - # Make html doc from RST | |
602 | - # cd doc/sourcedoc/ | |
603 | - change_dir(GUITASTRO_PATH + '/doc_rst/') | |
604 | - # ./MAKE_DOC.sh | |
605 | - res = execProcess('/bin/bash MAKE_DOC.sh') | |
606 | - # Come back to where we were before | |
607 | - # cd - | |
608 | - change_dir("PREVIOUS") | |
609 | - ''' | |
610 | - | |
611 | - | |
612 | - #if test_mode(): print("in test mode") | |
613 | - # self.execProcess("python3 install/install.py install") | |
614 | - # if (os.path.basename(os.getcwd()) != "private"): | |
615 | - | |
616 | - num = 0 | |
617 | - # 1) Update source code (git pull) | |
618 | - if UPDATE: | |
619 | - num += 1 | |
620 | - printFullTerm( | |
621 | - Colors.BLUE, f"{num}) UPDATING SOURCE CODE: Running git pull") | |
622 | - if not WITH_DOCKER: | |
623 | - _gitpull() or die() | |
624 | - | |
625 | - # 2) Update python packages (pip upgrade AND pip install requirements) | |
626 | - if with_packages: | |
627 | - num += 1 | |
628 | - printFullTerm(Colors.BLUE, f"{num}) {ACTION} PYTHON PACKAGES") | |
629 | - # (UPDATE) Re-install VENV if disappeared | |
630 | - install_venv(EVEN_IF_ALREADY_EXISTS=not UPDATE) | |
631 | - install_packages() | |
645 | + venv_pip_install2( | |
646 | + GUITASTRO_PATH + '/install/requirements_linux.txt', '-r') | |
647 | + venv_pip_install2( | |
648 | + GUITASTRO_PATH + '/install/requirements_dev.txt', '-r') | |
632 | 649 | |
633 | 650 | # 3) Update PlantUML diagrams |
634 | 651 | num += 1 |
... | ... | @@ -665,9 +682,9 @@ def test(app): |
665 | 682 | configfile = 'config_pyros.yml' |
666 | 683 | os.environ["pyros_config_file"] = os.path.join(os.path.abspath( |
667 | 684 | PYROS_DJANGO_BASE_DIR), "../../../config/pyros/", configfile) |
668 | - #start_dir = os.getcwd() | |
685 | + # start_dir = os.getcwd() | |
669 | 686 | if app == None: |
670 | - #apps = ['obsconfig','scientific_program','common', 'scheduler', 'routine_manager', 'user_manager', 'alert_manager.tests.TestStrategyChange'] | |
687 | + # apps = ['obsconfig','scientific_program','common', 'scheduler', 'routine_manager', 'user_manager', 'alert_manager.tests.TestStrategyChange'] | |
671 | 688 | # Removing alert_manager, scheduler from tests |
672 | 689 | apps = ['obsconfig', "scientific_program", |
673 | 690 | 'common', 'user_manager', 'routine_manager'] |
... | ... | @@ -684,12 +701,12 @@ def test(app): |
684 | 701 | # for every module except obsconfig, should use the simple observatory configuration in order to run the website with a configuration that isn't the observatory configuration used for production |
685 | 702 | os.environ["PATH_TO_OBSCONF_FILE"] = os.path.join(os.path.abspath( |
686 | 703 | PYROS_DJANGO_BASE_DIR), "obsconfig/fixtures/observatory_configuration_ok_simple.yml") |
687 | - #_loaddata() or die() | |
704 | + # _loaddata() or die() | |
688 | 705 | change_dir(PYROS_DJANGO_BASE_DIR) |
689 | 706 | # Delete test_pyros database after tests |
690 | - #execProcessFromVenv('manage.py test ' + app) or die() | |
707 | + # execProcessFromVenv('manage.py test ' + app) or die() | |
691 | 708 | # KEEP test_pyros database after tests |
692 | - #execProcessFromVenv('manage.py test --keep ' + app) or die() | |
709 | + # execProcessFromVenv('manage.py test --keep ' + app) or die() | |
693 | 710 | execProcessFromVenv('manage.py test --keep --noinput ' + app) or die() |
694 | 711 | change_dir("PREVIOUS") |
695 | 712 | # execProcess("python install.py install") |
... | ... | @@ -707,8 +724,6 @@ def testall(): |
707 | 724 | return True |
708 | 725 | |
709 | 726 | |
710 | - | |
711 | - | |
712 | 727 | def _gitpull(): |
713 | 728 | print("-- running git pull") |
714 | 729 | GIT = "git.exe" if IS_WINDOWS else "git" |
... | ... | @@ -752,7 +767,7 @@ def start(agent: str, configfile: str, observatory: str, unit: str): |
752 | 767 | try: |
753 | 768 | from config.pyros.config_pyros import ConfigPyros |
754 | 769 | except: |
755 | - #pip = "pip" if platform.system() == "Windows" else "pip3" | |
770 | + # pip = "pip" if platform.system() == "Windows" else "pip3" | |
756 | 771 | # TODO: "python -m pip" au lieu de "pip" |
757 | 772 | pip = "pip" if IS_WINDOWS else "pip3" |
758 | 773 | process = subprocess.Popen( |
... | ... | @@ -780,8 +795,8 @@ def start(agent: str, configfile: str, observatory: str, unit: str): |
780 | 795 | media_path = os.path.join(os.path.abspath( |
781 | 796 | PYROS_DJANGO_BASE_DIR), "misc/static/media", logo_name) |
782 | 797 | shutil.copy(logo_path, media_path) |
783 | - #if test_mode(): print("in test mode") | |
784 | - #if verbose_mode(): print("in verbose mode") | |
798 | + # if test_mode(): print("in test mode") | |
799 | + # if verbose_mode(): print("in verbose mode") | |
785 | 800 | if observatory == None or len(observatory) == 0: |
786 | 801 | observatory = "default" |
787 | 802 | observatories_configuration_folder = os.path.join( |
... | ... | @@ -814,7 +829,7 @@ def start(agent: str, configfile: str, observatory: str, unit: str): |
814 | 829 | ''' |
815 | 830 | |
816 | 831 | # add path to pyros_django folder as the config class is supposed to work within this folder |
817 | - #cmd_test_obs_config = f"-c \"from src.core.pyros_django.obsconfig.obsconfig_class import OBSConfig\nOBSConfig('{os.path.join(PYROS_DJANGO_BASE_DIR,os.environ.get('PATH_TO_OBSCONF_FILE'))}')\"" | |
832 | + # cmd_test_obs_config = f"-c \"from src.core.pyros_django.obsconfig.obsconfig_class import OBSConfig\nOBSConfig('{os.path.join(PYROS_DJANGO_BASE_DIR,os.environ.get('PATH_TO_OBSCONF_FILE'))}')\"" | |
818 | 833 | cmd_test_obs_config = f"-c \"from src.core.pyros_django.obsconfig.obsconfig_class import OBSConfig\nOBSConfig('{obs_config_file_path}')\"" |
819 | 834 | if not execProcessFromVenv(cmd_test_obs_config): |
820 | 835 | # Observatory configuration has an issue |
... | ... | @@ -824,7 +839,7 @@ def start(agent: str, configfile: str, observatory: str, unit: str): |
824 | 839 | for a in agents: |
825 | 840 | if not _check_agent(a): |
826 | 841 | return |
827 | - #print("Agents are:", agents) | |
842 | + # print("Agents are:", agents) | |
828 | 843 | ''' |
829 | 844 | # Check if multiple agents: |
830 | 845 | agents = None |
... | ... | @@ -851,8 +866,8 @@ def start(agent: str, configfile: str, observatory: str, unit: str): |
851 | 866 | # execProcessFromVenvAsync(VENV_PYTHON + " manage.py runserver") |
852 | 867 | log.debug(VENV_PYTHON) |
853 | 868 | log.debug("Launching agent" + agent_name + "...") |
854 | - #if not test_mode(): execProcess(VENV_PYTHON + " manage.py runserver") | |
855 | - #if not test_mode(): execProcessFromVenv("start_agent_" + agent_name + ".py " + configfile) | |
869 | + # if not test_mode(): execProcess(VENV_PYTHON + " manage.py runserver") | |
870 | + # if not test_mode(): execProcessFromVenv("start_agent_" + agent_name + ".py " + configfile) | |
856 | 871 | current_dir = os.getcwd() |
857 | 872 | |
858 | 873 | # OLD format agents: majordome, monitoring, alert... |
... | ... | @@ -866,7 +881,7 @@ def start(agent: str, configfile: str, observatory: str, unit: str): |
866 | 881 | PYROS_WEBSITE_PORT = os.environ.get("PYROS_WEBSITE_PORT") |
867 | 882 | cmd = f"manage.py runserver 0.0.0.0:{PYROS_WEBSITE_PORT}" |
868 | 883 | os.chdir(PYROS_DJANGO_BASE_DIR) |
869 | - #if not test_mode(): execProcessFromVenv("start_agent.py " + agent_name + " " + configfile) | |
884 | + # if not test_mode(): execProcessFromVenv("start_agent.py " + agent_name + " " + configfile) | |
870 | 885 | |
871 | 886 | # Agent "agentM", "agentA", "agentB", "agentX", ... |
872 | 887 | elif agent_name.startswith("agent"): |
... | ... | @@ -878,8 +893,8 @@ def start(agent: str, configfile: str, observatory: str, unit: str): |
878 | 893 | os.chdir(PYROS_DJANGO_BASE_DIR+"/scientific_program/") |
879 | 894 | else: |
880 | 895 | os.chdir(PYROS_DJANGO_BASE_DIR+"/agent/") |
881 | - #cmd = "-m AgentX" | |
882 | - #cmd = f" Agent{agent_name[5:]}.py {configfile}" | |
896 | + # cmd = "-m AgentX" | |
897 | + # cmd = f" Agent{agent_name[5:]}.py {configfile}" | |
883 | 898 | cmd = f"Agent{agent_name[5:]}.py" |
884 | 899 | if debug_mode(): |
885 | 900 | cmd += " -d" |
... | ... | @@ -892,7 +907,7 @@ def start(agent: str, configfile: str, observatory: str, unit: str): |
892 | 907 | if configfile: |
893 | 908 | cmd += " {configfile}" |
894 | 909 | |
895 | - #if not test_mode(): current_processes.append( [execProcessFromVenvAsync(cmd), agent_name, -1] ) | |
910 | + # if not test_mode(): current_processes.append( [execProcessFromVenvAsync(cmd), agent_name, -1] ) | |
896 | 911 | # Append this process ( [process id, agent_name, result=failure] ) |
897 | 912 | # ("result" will be updated at the end of execution) |
898 | 913 | current_processes.append( |
... | ... | @@ -933,7 +948,7 @@ def start(agent: str, configfile: str, observatory: str, unit: str): |
933 | 948 | printFullTerm(Colors.WARNING, f"Process {agent} execution failed") |
934 | 949 | # self.addError(self.current_command, command) |
935 | 950 | |
936 | - #print("************ end of START() ************") | |
951 | + # print("************ end of START() ************") | |
937 | 952 | # Only according to the last process status: |
938 | 953 | # return True if p.returncode==0 else False |
939 | 954 | return True if p.returncode == 0 else False |
... | ... | @@ -974,7 +989,7 @@ def _update_plantuml_diags(): |
974 | 989 | # if no diag.png or if diag.pu more recent than diag.png => re-generate diag.png |
975 | 990 | diag_png = diag.split('.pu')[0] + '.png' |
976 | 991 | if not os.path.isfile(diag_png) or (os.path.getmtime(diag) > os.path.getmtime(diag_png)): |
977 | - #res = execProcessFromVenv("-m plantuml "+diag) | |
992 | + # res = execProcessFromVenv("-m plantuml "+diag) | |
978 | 993 | # we need to use our own version of plantuml |
979 | 994 | res = execProcessFromVenv("./install/plantuml.py "+diag) |
980 | 995 | if not res: |
... | ... | @@ -986,7 +1001,10 @@ def _update_api_doc(): |
986 | 1001 | print(os.getcwd()) |
987 | 1002 | DOC_RST_PATH = "doc/doc_rst/" |
988 | 1003 | # 0) Upgrade pip if new version available |
989 | - os.system(VENV_PYTHON + ' -m pip install --user --upgrade pip') | |
1004 | + if WITH_DOCKER: | |
1005 | + os.system(VENV_PYTHON + ' -m pip install --user --upgrade pip') | |
1006 | + else: | |
1007 | + os.system(VENV_PYTHON + ' -m pip install --upgrade pip') | |
990 | 1008 | # 1) install/update Sphinx requirements (only if not yet installed) |
991 | 1009 | venv_pip_install2(DOC_RST_PATH+'requirements.txt', '-r') |
992 | 1010 | # 2) make html doc from RST doc |
... | ... | @@ -1006,7 +1024,7 @@ def _update_api_doc(): |
1006 | 1024 | def _migrate(): |
1007 | 1025 | change_dir(PYROS_DJANGO_BASE_DIR) |
1008 | 1026 | # Migrate only migrations for the app "common" |
1009 | - #res = execProcessFromVenv("manage.py migrate common") | |
1027 | + # res = execProcessFromVenv("manage.py migrate common") | |
1010 | 1028 | # Migrate all migrations for ALL apps |
1011 | 1029 | res = execProcessFromVenv("manage.py migrate") |
1012 | 1030 | change_dir("PREVIOUS") |
... | ... | @@ -1015,8 +1033,8 @@ def _migrate(): |
1015 | 1033 | |
1016 | 1034 | def _makemigrations(): |
1017 | 1035 | change_dir(PYROS_DJANGO_BASE_DIR) |
1018 | - #execProcessFromVenv(self.venv_bin + " manage.py makemigrations") | |
1019 | - #res = execProcessFromVenv("manage.py makemigrations common") | |
1036 | + # execProcessFromVenv(self.venv_bin + " manage.py makemigrations") | |
1037 | + # res = execProcessFromVenv("manage.py makemigrations common") | |
1020 | 1038 | res = execProcessFromVenv("manage.py makemigrations") |
1021 | 1039 | change_dir("PREVIOUS") |
1022 | 1040 | return res |
... | ... | @@ -1026,7 +1044,7 @@ def _makemigrations(): |
1026 | 1044 | |
1027 | 1045 | def _loaddata(): |
1028 | 1046 | change_dir(PYROS_DJANGO_BASE_DIR) |
1029 | - #execProcessFromVenv(self.venv_bin + " manage.py loaddata misc" + os.sep + "fixtures" + os.sep + self.INIT_FIXTURE) | |
1047 | + # execProcessFromVenv(self.venv_bin + " manage.py loaddata misc" + os.sep + "fixtures" + os.sep + self.INIT_FIXTURE) | |
1030 | 1048 | res = execProcessFromVenv( |
1031 | 1049 | "manage.py loaddata misc" + os.sep + "fixtures" + os.sep + INIT_FIXTURE) |
1032 | 1050 | change_dir("PREVIOUS") |
... | ... | @@ -1099,7 +1117,7 @@ def notused_install_required_ubuntu(): |
1099 | 1117 | install_dependency_ubuntu("zlib1g-dev", 'i') |
1100 | 1118 | install_dependency_ubuntu("update", 'u') |
1101 | 1119 | install_dependency_ubuntu("rabbitmq-server", 'i') |
1102 | - #install_dependency_ubuntu("libmysqlclient-dev", 'i') | |
1120 | + # install_dependency_ubuntu("libmysqlclient-dev", 'i') | |
1103 | 1121 | |
1104 | 1122 | |
1105 | 1123 | def notused_install_dependency_centos(command, mode): |
... | ... | @@ -1161,12 +1179,19 @@ def notused_install_required(): |
1161 | 1179 | |
1162 | 1180 | |
1163 | 1181 | def venv_pip_install(package_name: str, options: str = ''): |
1164 | - os.system(VENV_PIP + ' install --user ' + options + ' ' + package_name) | |
1182 | + if WITH_DOCKER: | |
1183 | + os.system(VENV_PIP + ' install --user ' + options + ' ' + package_name) | |
1184 | + else: | |
1185 | + os.system(VENV_PIP + ' install ' + options + ' ' + package_name) | |
1165 | 1186 | |
1166 | 1187 | |
1167 | 1188 | def venv_pip_install2(package_name: str, options: str = ''): |
1168 | - os.system(VENV_PYTHON + ' -m ' + VENV_PIP + ' install --user ' | |
1169 | - + options + ' ' + package_name) | |
1189 | + if WITH_DOCKER: | |
1190 | + os.system(VENV_PYTHON + ' -m pip install --user ' | |
1191 | + + options + ' ' + package_name) | |
1192 | + else: | |
1193 | + os.system(VENV_PYTHON + ' -m pip install ' | |
1194 | + + options + ' ' + package_name) | |
1170 | 1195 | |
1171 | 1196 | |
1172 | 1197 | def install_venv(EVEN_IF_ALREADY_EXISTS: bool = False): |
... | ... | @@ -1203,7 +1228,7 @@ def install_venv(EVEN_IF_ALREADY_EXISTS: bool = False): |
1203 | 1228 | # -------------------------------------------- |
1204 | 1229 | # --- (if EVEN_IF_ALREADY_EXISTS) Delete venv dir if already exist |
1205 | 1230 | # -------------------------------------------- |
1206 | - #print(Colors.LOG_BLUE + "-----------------------------cd venv-----------------------------" + Colors.END) | |
1231 | + # print(Colors.LOG_BLUE + "-----------------------------cd venv-----------------------------" + Colors.END) | |
1207 | 1232 | if EVEN_IF_ALREADY_EXISTS: |
1208 | 1233 | while True: |
1209 | 1234 | try: |
... | ... | @@ -1238,7 +1263,10 @@ def install_packages(): |
1238 | 1263 | print(Colors.LOG_BLUE + "-----------------------------Upgrade pip, wheel, and setuptools" + |
1239 | 1264 | "-----------------------------"+END_OF_LINE + Colors.END) |
1240 | 1265 | # Upgrade pip |
1241 | - os.system(VENV_PYTHON + ' -m pip install --user --upgrade pip') | |
1266 | + if WITH_DOCKER: | |
1267 | + os.system(VENV_PYTHON + ' -m pip install --user --upgrade pip') | |
1268 | + else: | |
1269 | + os.system(VENV_PYTHON + ' -m pip install --upgrade pip') | |
1242 | 1270 | ''' |
1243 | 1271 | if (platform.system() == "Windows"): |
1244 | 1272 | os.system(venv + '\Scripts\python -m pip install --upgrade pip') |
... | ... | @@ -1248,10 +1276,13 @@ def install_packages(): |
1248 | 1276 | |
1249 | 1277 | # Pip upgrade wheel and setuptools |
1250 | 1278 | venv_pip_install('wheel', '--upgrade') |
1251 | - #os.system(VENV_PIP+' install --upgrade wheel') | |
1279 | + # os.system(VENV_PIP+' install --upgrade wheel') | |
1252 | 1280 | # Not working with python 3.8 (on 17/02/2022) |
1253 | 1281 | # venv_pip_install('setuptools', '--upgrade') |
1254 | - os.system(VENV_PIP+' install --user setuptools==58') | |
1282 | + if WITH_DOCKER: | |
1283 | + os.system(VENV_PIP+' install --user setuptools==58') | |
1284 | + else: | |
1285 | + os.system(VENV_PIP+' install setuptools==58') | |
1255 | 1286 | |
1256 | 1287 | # Pip install required packages from REQUIREMENTS file |
1257 | 1288 | print() |
... | ... | @@ -1259,16 +1290,16 @@ def install_packages(): |
1259 | 1290 | # General normal packages |
1260 | 1291 | print(Colors.LOG_BLUE + "-----------------------------Installing python packages via pip-----------------------------" + Colors.END) |
1261 | 1292 | venv_pip_install('../install/'+REQUIREMENTS, '-r') |
1262 | - #os.system(VENV_PIP+' install -r ../install' + os.sep + REQUIREMENTS) | |
1293 | + # os.system(VENV_PIP+' install -r ../install' + os.sep + REQUIREMENTS) | |
1263 | 1294 | |
1264 | 1295 | # DEV only packages |
1265 | 1296 | if DEV: |
1266 | 1297 | print(Colors.LOG_BLUE + "-----------------------------Installing DEV python packages via pip-----------------------------" + Colors.END) |
1267 | 1298 | venv_pip_install('../install/'+REQUIREMENTS_DEV, '-r') |
1268 | 1299 | print("FIN INSTALL PACKAGES") |
1269 | - exit() | |
1300 | + return None | |
1270 | 1301 | |
1271 | - #print(Colors.LOG_BLUE + "-----------------------------cd ../install-----------------------------" + Colors.END) | |
1302 | + # print(Colors.LOG_BLUE + "-----------------------------cd ../install-----------------------------" + Colors.END) | |
1272 | 1303 | |
1273 | 1304 | if IS_WINDOWS: |
1274 | 1305 | os.chdir("../install") |
... | ... | @@ -1332,7 +1363,7 @@ def install_database(venv): |
1332 | 1363 | f"CREATE DATABASE IF NOT EXISTS {SQL_DATABASE}; " +\ |
1333 | 1364 | f"CREATE DATABASE IF NOT EXISTS {SQL_DATABASE_SIMU}; " |
1334 | 1365 | if sql_version < 5.5: |
1335 | - #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;" | |
1366 | + # 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;" | |
1336 | 1367 | sql_query = \ |
1337 | 1368 | f"DROP DATABASE {SQL_DATABASE}; CREATE DATABASE {SQL_DATABASE}; " +\ |
1338 | 1369 | f"DROP DATABASE {SQL_DATABASE_SIMU}; CREATE DATABASE {SQL_DATABASE_SIMU}; " |
... | ... | @@ -1355,13 +1386,13 @@ def install_database(venv): |
1355 | 1386 | # "CREATE USER "+SQL_USER+"; " +\ |
1356 | 1387 | # Donc, il faut ruser |
1357 | 1388 | # Mysql >= 5.7 only: |
1358 | - #sql_query_elem = "CREATE USER IF NOT EXISTS "+SQL_USER+"; " | |
1389 | + # sql_query_elem = "CREATE USER IF NOT EXISTS "+SQL_USER+"; " | |
1359 | 1390 | # Si user n'existe pas => est crรฉรฉ ; Si user existe => pas d'erreur ; DONC ok dans les 2 cas |
1360 | - #sql_query_elem = "GRANT ALL ON "+SQL_DATABASE+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"'; " | |
1391 | + # sql_query_elem = "GRANT ALL ON "+SQL_DATABASE+".* TO '"+SQL_USER+"'@'localhost' IDENTIFIED BY '"+SQL_PSWD+"'; " | |
1361 | 1392 | |
1362 | 1393 | if WITH_DOCKER: |
1363 | 1394 | # we will use this later (at the end of development) |
1364 | - #host = os.environ["IP_PYROS_USER"] | |
1395 | + # host = os.environ["IP_PYROS_USER"] | |
1365 | 1396 | host = "%" |
1366 | 1397 | else: |
1367 | 1398 | host = "localhost" |
... | ... | @@ -1381,7 +1412,7 @@ def install_database(venv): |
1381 | 1412 | # FOR MYSQL 8: |
1382 | 1413 | if sql_version >= 8: |
1383 | 1414 | sql_query += "FLUSH PRIVILEGES; " |
1384 | - #"GRANT USAGE ON *.* TO '"+SQL_USER+"'@localhost ; " | |
1415 | + # "GRANT USAGE ON *.* TO '"+SQL_USER+"'@localhost ; " | |
1385 | 1416 | |
1386 | 1417 | ''' |
1387 | 1418 | # (EP) AVANT, y avait tout รงa..., vraiment utile ? |
... | ... | @@ -1394,15 +1425,15 @@ def install_database(venv): |
1394 | 1425 | ''' |
1395 | 1426 | # NEWER MYSQL: |
1396 | 1427 | # OLDER MYSQL: Try this instead for OLDER mysql (works on CentOS 6.4 and Centos 7.5 with mysql 5.5): |
1397 | - #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'" | |
1398 | - #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;" | |
1428 | + # 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'" | |
1429 | + # 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;" | |
1399 | 1430 | # (EP) ok for CENTOS 7 I suppose (but not for CentOS 6): |
1400 | - #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;" | |
1431 | + # 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;" | |
1401 | 1432 | |
1402 | 1433 | # --- Prepare the SQL query to create and initialize the pyros database if needed |
1403 | 1434 | # if platform.dist()[0] == "centos": |
1404 | 1435 | # req = sql_query |
1405 | - #mysql_call_root = '"' + MYSQL_EXE_PATH + 'mysql" -u root -p' | |
1436 | + # mysql_call_root = '"' + MYSQL_EXE_PATH + 'mysql" -u root -p' | |
1406 | 1437 | |
1407 | 1438 | # if the mysql_root_password isn't defined, it will ask to enter the password |
1408 | 1439 | try: |
... | ... | @@ -1440,7 +1471,7 @@ def install_database(venv): |
1440 | 1471 | if user_ros_is_created: |
1441 | 1472 | # --- The user pyros must be created in the database |
1442 | 1473 | print(Colors.LOG_BLUE + "-----------------------------Please enter your MYSQL root password-----------------------------" + Colors.END) |
1443 | - #process = subprocess.Popen("echo \"" + sql_query + "\" |"+ mysql_call_root, shell=True) | |
1474 | + # process = subprocess.Popen("echo \"" + sql_query + "\" |"+ mysql_call_root, shell=True) | |
1444 | 1475 | sql_cmd = 'echo "' + sql_query + '" | ' + mysql_call_root |
1445 | 1476 | print("Executing sql cmd: ", sql_cmd) |
1446 | 1477 | process = subprocess.Popen(sql_cmd, shell=True) |
... | ... | @@ -1457,9 +1488,9 @@ def install_database(venv): |
1457 | 1488 | # -------------------------------------------- |
1458 | 1489 | print(Colors.LOG_BLUE + "-----------------------------setting MYSQL = True in settings-----------------------------" + Colors.END) |
1459 | 1490 | replacePatternInFile("MYSQL = False", "MYSQL = True", os.path.normpath( |
1460 | - "src/core/pyros_django/pyros/settings.py")) | |
1491 | + f"{PYROS_DJANGO_BASE_DIR}/pyros/settings.py")) | |
1461 | 1492 | |
1462 | - #print(Colors.LOG_BLUE + "\r\n-----------------------------cd ..-----------------------------" + Colors.END) | |
1493 | + # print(Colors.LOG_BLUE + "\r\n-----------------------------cd ..-----------------------------" + Colors.END) | |
1463 | 1494 | # 2021 : no need to change folder in order to init the database (maybe the next line was forget to be commented because the previous line is commented) |
1464 | 1495 | # os.chdir("..") |
1465 | 1496 | |
... | ... | @@ -1470,7 +1501,7 @@ def install_database(venv): |
1470 | 1501 | print(Colors.LOG_BLUE + "\r\n\r\n-----------------------------Migrate : executing pyros.py init_database-----------------------------" + Colors.END) |
1471 | 1502 | # TODO: from venv !!! |
1472 | 1503 | try: |
1473 | - #os.system(GLOBAL_PYTHON+" pyros.py init_database") | |
1504 | + # os.system(GLOBAL_PYTHON+" pyros.py init_database") | |
1474 | 1505 | res = os.system(GLOBAL_PYTHON+" pyros.py initdb") |
1475 | 1506 | return res |
1476 | 1507 | ''' |
... | ... | @@ -1565,7 +1596,7 @@ if __name__ == "__main__": |
1565 | 1596 | """ INSTALLATION main function |
1566 | 1597 | if __name__ == '__main__': |
1567 | 1598 | if len(sys.argv) > 2: _help() ; sys.exit(1) |
1568 | - #print(sys.argv) | |
1599 | + # print(sys.argv) | |
1569 | 1600 | if len(sys.argv) == 2: |
1570 | 1601 | INSTALL_VENV = INSTALL_DB = False |
1571 | 1602 | if sys.argv[1] == '-p': INSTALL_VENV=True | ... | ... |