Compare View
Commits (2)
Showing
3 changed files
Show diff stats
docker/PYROS_DOCKER_INSTALL_DB
docker/PYROS_DOCKER_UPDATE
1 | 1 | #!/usr/bin/env bash |
2 | 2 | |
3 | +# PRE-CONDITION : pyros container must be running | |
4 | + | |
3 | 5 | # If no container is running Start it |
4 | 6 | if ! [ $(docker ps | grep 'pyros' | wc -l) -eq 4 ] |
5 | 7 | then |
... | ... | @@ -16,10 +18,12 @@ echo "Updating Guitastro source code" |
16 | 18 | echo "Updating PyROS source code" |
17 | 19 | git pull |
18 | 20 | |
19 | -echo "Updating observatory source code" | |
20 | -for dir in ../../PYROS_OBSERVATORY/* | |
21 | -do | |
22 | - git pull | |
21 | +# 3) Update all observatories with git repo | |
22 | +for dir in ../../PYROS_OBSERVATORY/* ; do | |
23 | + if [ -d .git ] ; then | |
24 | + echo "Updating observatory $dir source code" | |
25 | + git pull | |
26 | + fi | |
23 | 27 | done |
24 | 28 | |
25 | 29 | # 3) pyros.py update => update BD + doc + Guitastro requirements | ... | ... |
pyros.py
... | ... | @@ -534,7 +534,7 @@ def dbshell(): |
534 | 534 | |
535 | 535 | @pyros_launcher.command(help="Update (only if necessary) the python packages AND the source code AND the DB structure") |
536 | 536 | def update(): |
537 | - install_or_update(UPDATE=True) | |
537 | + _install_or_update(UPDATE=True) | |
538 | 538 | ''' |
539 | 539 | print("Running update command") |
540 | 540 | # 1) Update source code (git pull) |
... | ... | @@ -568,13 +568,14 @@ def update(): |
568 | 568 | def install(packages_only, database_only): |
569 | 569 | with_packages = not database_only |
570 | 570 | with_database = not packages_only |
571 | - install_or_update(UPDATE=False, with_packages=with_packages, | |
571 | + _install_or_update(UPDATE=False, with_packages=with_packages, | |
572 | 572 | with_database=with_database) |
573 | 573 | # install_or_update(UPDATE=False, with_packages=packages_only, with_database=database_only) |
574 | 574 | # install_or_update(UPDATE=False, packages_only=packages_only, database_only=database_only) |
575 | 575 | |
576 | + | |
576 | 577 | # def install_or_update(UPDATE: bool = False, with_packages: bool = False, with_database: bool = False): |
577 | -def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_database: bool = True): | |
578 | +def _install_or_update(UPDATE: bool = False, with_packages: bool = True, with_database: bool = True): | |
578 | 579 | SQL_USER = os.environ.get("MYSQL_PYROS_LOGIN").strip() |
579 | 580 | SQL_PSWD = os.environ.get("MYSQL_PYROS_PWD").strip() |
580 | 581 | os.environ["PATH_TO_OBSCONF_FOLDER"] = os.path.join(os.path.abspath( |
... | ... | @@ -583,7 +584,7 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat |
583 | 584 | PYROS_DJANGO_BASE_DIR), os.environ["PATH_TO_OBSCONF_FOLDER"] + "observatory.yml") |
584 | 585 | ACTION = "UPDATING" if UPDATE else "INSTALLING" |
585 | 586 | |
586 | - # if WITH_DOCKER: with_database = True | |
587 | + # if WITH_DOCKER: only install the DB (with_database = True) | |
587 | 588 | if WITH_DOCKER: |
588 | 589 | with_packages = False |
589 | 590 | |
... | ... | @@ -597,21 +598,22 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat |
597 | 598 | # if (os.path.basename(os.getcwd()) != "private"): |
598 | 599 | |
599 | 600 | num = 0 |
600 | - # 1) Update source code (git pull) | |
601 | + | |
601 | 602 | if UPDATE: |
603 | + # Update source code (git pull) | |
602 | 604 | num += 1 |
603 | - printFullTerm( | |
604 | - Colors.BLUE, f"{num}) UPDATING SOURCE CODE: Running git pull") | |
605 | + printFullTerm(Colors.BLUE, f"{num}) UPDATING SOURCE CODE: Running git pull") | |
605 | 606 | if not WITH_DOCKER: |
606 | 607 | _gitpull() or die() |
607 | 608 | |
608 | - # 2) Update python packages (pip upgrade AND pip install requirements) | |
609 | 609 | if with_packages: |
610 | + # Update python packages (pip upgrade AND pip install requirements) | |
610 | 611 | num += 1 |
611 | 612 | printFullTerm(Colors.BLUE, f"{num}) {ACTION} PYTHON PACKAGES") |
612 | 613 | # (UPDATE) Re-install VENV if disappeared |
613 | 614 | install_venv(EVEN_IF_ALREADY_EXISTS=not UPDATE) |
614 | 615 | install_packages() |
616 | + | |
615 | 617 | if UPDATE: |
616 | 618 | print("Running UPDATE command") |
617 | 619 | else: |
... | ... | @@ -621,13 +623,10 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat |
621 | 623 | from git import Repo |
622 | 624 | except: |
623 | 625 | pip = "pip" if IS_WINDOWS else "pip3" |
624 | - if WITH_DOCKER: | |
625 | - process = subprocess.Popen( | |
626 | - pip + " install --user --upgrade GitPython", shell=True) | |
627 | - else: | |
628 | - process = subprocess.Popen( | |
629 | - pip + " install --upgrade GitPython", shell=True) | |
626 | + usermode = '--user' if WITH_DOCKER else '' | |
627 | + process = subprocess.Popen(pip + f" install {usermode} --upgrade GitPython", shell=True) | |
630 | 628 | process.wait() |
629 | + # if run ok | |
631 | 630 | if process.returncode == 0: |
632 | 631 | # self.addExecuted(self.current_command, command) |
633 | 632 | from git import Repo |
... | ... | @@ -645,14 +644,16 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat |
645 | 644 | change_dir("PREVIOUS") |
646 | 645 | ''' |
647 | 646 | |
647 | + # | |
648 | 648 | # Guitastro |
649 | + # | |
649 | 650 | GUITASTRO_PATH = os.path.join(os.getcwd(), "./vendor/guitastro") |
650 | - if with_packages and not WITH_DOCKER : | |
651 | + if with_packages: # and not WITH_DOCKER: | |
651 | 652 | #GUITASTRO_PATH = os.path.join(os.getcwd(), "../vendor/guitastro") |
652 | 653 | change_dir("..") |
653 | 654 | print(os.getcwd()) |
654 | 655 | # 1) clone repo if not yet done |
655 | - if not os.path.exists(GUITASTRO_PATH) and not WITH_DOCKER : | |
656 | + if not WITH_DOCKER and not os.path.exists(GUITASTRO_PATH): | |
656 | 657 | print("Guitastro : Cloning repository") |
657 | 658 | cloned_repo = Repo.clone_from( |
658 | 659 | "https://gitlab.irap.omp.eu/guitastrolib/guitastro.git", GUITASTRO_PATH) |
... | ... | @@ -661,7 +662,7 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat |
661 | 662 | gitpull_guitastro() |
662 | 663 | change_dir("PREVIOUS") |
663 | 664 | # 2) install/update requirements & generate API doc |
664 | - if os.path.exists(GUITASTRO_PATH) and not WITH_DOCKER: | |
665 | + if not WITH_DOCKER and os.path.exists(GUITASTRO_PATH): | |
665 | 666 | # TODO: update guitastro (git pull from vendor/guitastro/) |
666 | 667 | print("\nGuitastro : Installing/Updating python package dependencies\n") |
667 | 668 | # Upgrade pip if new version available |
... | ... | @@ -703,9 +704,8 @@ def install_or_update(UPDATE: bool = False, with_packages: bool = True, with_dat |
703 | 704 | _updatedb() or die() |
704 | 705 | else: |
705 | 706 | res = install_database(VENV) |
706 | - if(res == 0): | |
707 | - print( | |
708 | - f"You can connect to PyROS as '{SQL_USER}' user with the password '{SQL_PSWD}' ") | |
707 | + if (res == 0): | |
708 | + print(f"You can connect to PyROS as '{SQL_USER}' user with the password '{SQL_PSWD}' ") | |
709 | 709 | return True |
710 | 710 | |
711 | 711 | |
... | ... | @@ -789,8 +789,7 @@ def gitpull_guitastro(): |
789 | 789 | change_dir("./vendor/guitastro/") |
790 | 790 | GIT = "git.exe" if IS_WINDOWS else "git" |
791 | 791 | if not test_mode(): |
792 | - return execProcess(f"{GIT} pull",foreground=True) | |
793 | - | |
792 | + return execProcess(f"{GIT} pull", foreground=True) | |
794 | 793 | return True |
795 | 794 | |
796 | 795 | ... | ... |