diff --git a/CHANGELOG b/CHANGELOG index 93c17f9..64ddb27 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,12 @@ -06-07-2022 (AKo): v0.4.13.0 +16-06-2022 (AKo): v0.4.14.0 + - Improving / Fixing PYROSW script and PYROS.bat + - Fixing obsconfig_class that made PyROS rewrite pickle when trying to read invalid value in pickle + +07-06-2022 (AKo): v0.4.13.0 - Adding foreground option for start command - -06-03-2022 (AKo): V0.4.12.0 + +03-06-2022 (AKo): V0.4.12.0 - Adding pyros stop command - Better implementation of do_things_before_exit for AgentSST diff --git a/PYROS.bat b/PYROS.bat index 6d30f3d..8f30b04 100755 --- a/PYROS.bat +++ b/PYROS.bat @@ -1,5 +1,2 @@ -python PYROSW.py @PSBoundParameters - -#python PYROSW.py $* -#python PYROSW.py @* +python PYROSW.py %* diff --git a/PYROSW.py b/PYROSW.py index 1862785..fe646d9 100755 --- a/PYROSW.py +++ b/PYROSW.py @@ -5,82 +5,95 @@ Shell scripting with python : - https://www.freecodecamp.org/news/python-for-system-administration-tutorial - https://github.com/ninjaaron/replacing-bash-scripting-with-python#if-the-shell-is-so-great-what-s-the-problem - https://linuxize.com/post/python-get-change-current-working-directory -''' -DEBUG = False -#DEBUG = True -#print(DEBUG) -import sys -import os -from shutil import which -import subprocess +USAGE: + ON WINDOWS: + Via PyROS Wrapper + .\PYROS --docker start agentScheduler -o tnc -fg + -- docker option as FIRST parameter -> force script to use docker (Useful when you have PyROS and Docker installed locally) + OR + .\PYROS start agentScheduler -o tnc -fg + To use PyROS locally +''' +import subprocess +from shutil import which +import os +import sys +from time import sleep +DEBUG = False +#DEBUG = True +# print(DEBUG) -def run(command: str) : +def run(command: str): #print(command.split(' ')) return subprocess.run(command.split(' ')) #result = subprocess.run(command.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE) -# Guess Context (3 possibilities) : -# - NO DOCKER, +# Guess Context (3 possibilities) : +# - NO DOCKER, # or -# - DOCKER OUT of container, +# - DOCKER OUT of container, # or # - or DOCKER IN container WITH_DOCKER_IS_SET = False if os.getenv('WITH_DOCKER') is None else True -#print(WITH_DOCKER_IS_SET) +# print(WITH_DOCKER_IS_SET) -#APP_FOLDER=False -#[ -d ../app/ ] && APP_FOLDER=true +# APP_FOLDER=False +# [ -d ../app/ ] && APP_FOLDER=true APP_FOLDER = os.path.exists('../app/') VENV = os.path.exists('./venv/') -# test if docker is installed -#[ -x "$(command -v docker)" ] && DOCKER_CMD=true +args = sys.argv[1:] +if args[0] == "--docker": + VENV = False + args.pop(0) +args = ' '.join(args) +# test if docker is installed +# [ -x "$(command -v docker)" ] && DOCKER_CMD=true DOCKER_CMD = which('docker') is not None # Pas utile vu qu'on va redémarrer systématiquement le container # test if container is running -##DOCKER_CONTAINER_STARTED=false -##$DOCKER_CMD && [ $(docker ps | grep 'pyros' | wc -l) -eq 2 ] && DOCKER_CONTAINER_STARTED=true +# DOCKER_CONTAINER_STARTED=false +# $DOCKER_CMD && [ $(docker ps | grep 'pyros' | wc -l) -eq 2 ] && DOCKER_CONTAINER_STARTED=true # # SYNTHESIS # -#DOCKER=false -#[[ $VENV == false && $DOCKER_CMD == true ]] && DOCKER=true +# DOCKER=false +# [[ $VENV == false && $DOCKER_CMD == true ]] && DOCKER=true DOCKER = DOCKER_CMD and not VENV DOCKER_OUT_CONTAINER = DOCKER and not WITH_DOCKER_IS_SET -#[[ $DOCKER == false && $WITH_DOCKER_IS_SET == true ]] && DOCKER_IN_CONTAINER=true +# [[ $DOCKER == false && $WITH_DOCKER_IS_SET == true ]] && DOCKER_IN_CONTAINER=true -if DEBUG : - print(APP_FOLDER) - print(VENV) - print(DOCKER_CMD) - #print(container) - # Synthesis - print(DOCKER) - print(DOCKER_OUT_CONTAINER) +if DEBUG: + print(APP_FOLDER) + print(VENV) + print(DOCKER_CMD) + # print(container) + # Synthesis + print(DOCKER) + print(DOCKER_OUT_CONTAINER) - print(sys.argv) - exit(0) + print(sys.argv) + exit(0) # no container ? => start container first -#[ $container == false ] && cd docker/ && docker-compose up -d +# [ $container == false ] && cd docker/ && docker-compose up -d -args = sys.argv[1:] -args = ' '.join(args) -#print(args) + +# print(args) #PYROS_CMD = "python3 pyros.py --help" #PYROS_CMD = "python3 pyros.py $*" @@ -88,16 +101,19 @@ PYROS_CMD = "python3 pyros.py " + args PYROS_CMD = PYROS_CMD.rstrip() # DOCKER_OUT_CONTAINER true ? => docker exec -#docker exec -it pyros python3 pyros.py $* -#[ $DOCKER_OUT_CONTAINER == true ] && cd docker/ && docker-compose up -d && PREFIX='docker exec -it pyros' -if DOCKER_OUT_CONTAINER : - #cd docker/ - os.chdir('docker') - #docker-compose up -d - run('docker-compose up -d') +# docker exec -it pyros python3 pyros.py $* +# [ $DOCKER_OUT_CONTAINER == true ] && cd docker/ && docker-compose up -d && PREFIX='docker exec -it pyros' +if DOCKER_OUT_CONTAINER: + # cd docker/ + os.chdir('docker') + # docker-compose up -d + res = subprocess.run("docker exec -it pyros python3 pyros.py",stdout=subprocess.DEVNULL) + if res.returncode != 0: + run('docker-compose up -d') + sleep(5) PYROS_CMD = 'docker exec -it pyros ' + PYROS_CMD -#PYROS_CMD +# PYROS_CMD print("\n Executing command :", PYROS_CMD, "\n") res = run(PYROS_CMD) @@ -111,11 +127,6 @@ print() print(result.stderr) ''' - - - - - ''' ########################## diff --git a/VERSION b/VERSION index bfdef33..334a04a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.13.0 \ No newline at end of file +0.4.14.0 \ No newline at end of file diff --git a/src/core/pyros_django/obsconfig/obsconfig_class.py b/src/core/pyros_django/obsconfig/obsconfig_class.py index a821894..42f21a0 100644 --- a/src/core/pyros_django/obsconfig/obsconfig_class.py +++ b/src/core/pyros_django/obsconfig/obsconfig_class.py @@ -114,7 +114,7 @@ class OBSConfig: self.devices_links = pickle_dict["devices_links"] self.obs_config_file_content = pickle_dict["obs_config_file_content"] self.raw_config = pickle_dict["raw_config"] - self.agents = pickle_dict["agents"] + #self.agents = pickle_dict["agents"] except: # we rewrite the pickle file, the content will be the same otherwise we would be in the else case print( -- libgit2 0.21.2