Commit a56e6e0e2b1fb62fe0cf62015df78e941b15c6a2

Authored by Etienne Pallier
1 parent 63f2beb2
Exists in dev

comments and shortcuts in pyros.py and docker scripts

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