Commit 83b4b4b2d4d4a98f6946ee1dadbedc9c6aaa4305
1 parent
7138789e
Exists in
dev
Fixing PYROS.bat, PYROSW.py scripts to run PyROS on Windows. Fixing issue with o…
…bsconfig_class that was rewriting pickle when reading invalid value
Showing
5 changed files
with
70 additions
and
58 deletions
Show diff stats
CHANGELOG
1 | -06-07-2022 (AKo): v0.4.13.0 | 1 | +16-06-2022 (AKo): v0.4.14.0 |
2 | + - Improving / Fixing PYROSW script and PYROS.bat | ||
3 | + - Fixing obsconfig_class that made PyROS rewrite pickle when trying to read invalid value in pickle | ||
4 | + | ||
5 | +07-06-2022 (AKo): v0.4.13.0 | ||
2 | - Adding foreground option for start command | 6 | - Adding foreground option for start command |
3 | 7 | ||
4 | - | ||
5 | -06-03-2022 (AKo): V0.4.12.0 | 8 | + |
9 | +03-06-2022 (AKo): V0.4.12.0 | ||
6 | - Adding pyros stop command | 10 | - Adding pyros stop command |
7 | - Better implementation of do_things_before_exit for AgentSST | 11 | - Better implementation of do_things_before_exit for AgentSST |
8 | 12 |
PYROS.bat
PYROSW.py
@@ -5,82 +5,95 @@ Shell scripting with python : | @@ -5,82 +5,95 @@ Shell scripting with python : | ||
5 | - https://www.freecodecamp.org/news/python-for-system-administration-tutorial | 5 | - https://www.freecodecamp.org/news/python-for-system-administration-tutorial |
6 | - https://github.com/ninjaaron/replacing-bash-scripting-with-python#if-the-shell-is-so-great-what-s-the-problem | 6 | - https://github.com/ninjaaron/replacing-bash-scripting-with-python#if-the-shell-is-so-great-what-s-the-problem |
7 | - https://linuxize.com/post/python-get-change-current-working-directory | 7 | - https://linuxize.com/post/python-get-change-current-working-directory |
8 | -''' | ||
9 | 8 | ||
10 | -DEBUG = False | ||
11 | -#DEBUG = True | ||
12 | -#print(DEBUG) | ||
13 | 9 | ||
14 | 10 | ||
15 | -import sys | ||
16 | -import os | ||
17 | -from shutil import which | ||
18 | -import subprocess | 11 | +USAGE: |
12 | + ON WINDOWS: | ||
13 | + Via PyROS Wrapper | ||
14 | + .\PYROS --docker start agentScheduler -o tnc -fg | ||
15 | + -- docker option as FIRST parameter -> force script to use docker (Useful when you have PyROS and Docker installed locally) | ||
16 | + OR | ||
17 | + .\PYROS start agentScheduler -o tnc -fg | ||
18 | + To use PyROS locally | ||
19 | +''' | ||
19 | 20 | ||
21 | +import subprocess | ||
22 | +from shutil import which | ||
23 | +import os | ||
24 | +import sys | ||
25 | +from time import sleep | ||
26 | +DEBUG = False | ||
27 | +#DEBUG = True | ||
28 | +# print(DEBUG) | ||
20 | 29 | ||
21 | 30 | ||
22 | -def run(command: str) : | 31 | +def run(command: str): |
23 | #print(command.split(' ')) | 32 | #print(command.split(' ')) |
24 | return subprocess.run(command.split(' ')) | 33 | return subprocess.run(command.split(' ')) |
25 | #result = subprocess.run(command.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 34 | #result = subprocess.run(command.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
26 | 35 | ||
27 | 36 | ||
28 | -# Guess Context (3 possibilities) : | ||
29 | -# - NO DOCKER, | 37 | +# Guess Context (3 possibilities) : |
38 | +# - NO DOCKER, | ||
30 | # or | 39 | # or |
31 | -# - DOCKER OUT of container, | 40 | +# - DOCKER OUT of container, |
32 | # or | 41 | # or |
33 | # - or DOCKER IN container | 42 | # - or DOCKER IN container |
34 | 43 | ||
35 | WITH_DOCKER_IS_SET = False if os.getenv('WITH_DOCKER') is None else True | 44 | WITH_DOCKER_IS_SET = False if os.getenv('WITH_DOCKER') is None else True |
36 | -#print(WITH_DOCKER_IS_SET) | 45 | +# print(WITH_DOCKER_IS_SET) |
37 | 46 | ||
38 | 47 | ||
39 | -#APP_FOLDER=False | ||
40 | -#[ -d ../app/ ] && APP_FOLDER=true | 48 | +# APP_FOLDER=False |
49 | +# [ -d ../app/ ] && APP_FOLDER=true | ||
41 | APP_FOLDER = os.path.exists('../app/') | 50 | APP_FOLDER = os.path.exists('../app/') |
42 | 51 | ||
43 | VENV = os.path.exists('./venv/') | 52 | VENV = os.path.exists('./venv/') |
44 | 53 | ||
45 | -# test if docker is installed | ||
46 | -#[ -x "$(command -v docker)" ] && DOCKER_CMD=true | 54 | +args = sys.argv[1:] |
55 | +if args[0] == "--docker": | ||
56 | + VENV = False | ||
57 | + args.pop(0) | ||
58 | +args = ' '.join(args) | ||
59 | +# test if docker is installed | ||
60 | +# [ -x "$(command -v docker)" ] && DOCKER_CMD=true | ||
47 | DOCKER_CMD = which('docker') is not None | 61 | DOCKER_CMD = which('docker') is not None |
48 | 62 | ||
49 | 63 | ||
50 | # Pas utile vu qu'on va redémarrer systématiquement le container | 64 | # Pas utile vu qu'on va redémarrer systématiquement le container |
51 | # test if container is running | 65 | # test if container is running |
52 | -##DOCKER_CONTAINER_STARTED=false | ||
53 | -##$DOCKER_CMD && [ $(docker ps | grep 'pyros' | wc -l) -eq 2 ] && DOCKER_CONTAINER_STARTED=true | 66 | +# DOCKER_CONTAINER_STARTED=false |
67 | +# $DOCKER_CMD && [ $(docker ps | grep 'pyros' | wc -l) -eq 2 ] && DOCKER_CONTAINER_STARTED=true | ||
54 | 68 | ||
55 | # | 69 | # |
56 | # SYNTHESIS | 70 | # SYNTHESIS |
57 | # | 71 | # |
58 | 72 | ||
59 | -#DOCKER=false | ||
60 | -#[[ $VENV == false && $DOCKER_CMD == true ]] && DOCKER=true | 73 | +# DOCKER=false |
74 | +# [[ $VENV == false && $DOCKER_CMD == true ]] && DOCKER=true | ||
61 | DOCKER = DOCKER_CMD and not VENV | 75 | DOCKER = DOCKER_CMD and not VENV |
62 | 76 | ||
63 | DOCKER_OUT_CONTAINER = DOCKER and not WITH_DOCKER_IS_SET | 77 | DOCKER_OUT_CONTAINER = DOCKER and not WITH_DOCKER_IS_SET |
64 | -#[[ $DOCKER == false && $WITH_DOCKER_IS_SET == true ]] && DOCKER_IN_CONTAINER=true | 78 | +# [[ $DOCKER == false && $WITH_DOCKER_IS_SET == true ]] && DOCKER_IN_CONTAINER=true |
65 | 79 | ||
66 | -if DEBUG : | ||
67 | - print(APP_FOLDER) | ||
68 | - print(VENV) | ||
69 | - print(DOCKER_CMD) | ||
70 | - #print(container) | ||
71 | - # Synthesis | ||
72 | - print(DOCKER) | ||
73 | - print(DOCKER_OUT_CONTAINER) | 80 | +if DEBUG: |
81 | + print(APP_FOLDER) | ||
82 | + print(VENV) | ||
83 | + print(DOCKER_CMD) | ||
84 | + # print(container) | ||
85 | + # Synthesis | ||
86 | + print(DOCKER) | ||
87 | + print(DOCKER_OUT_CONTAINER) | ||
74 | 88 | ||
75 | - print(sys.argv) | ||
76 | - exit(0) | 89 | + print(sys.argv) |
90 | + exit(0) | ||
77 | 91 | ||
78 | # no container ? => start container first | 92 | # no container ? => start container first |
79 | -#[ $container == false ] && cd docker/ && docker-compose up -d | 93 | +# [ $container == false ] && cd docker/ && docker-compose up -d |
80 | 94 | ||
81 | -args = sys.argv[1:] | ||
82 | -args = ' '.join(args) | ||
83 | -#print(args) | 95 | + |
96 | +# print(args) | ||
84 | 97 | ||
85 | #PYROS_CMD = "python3 pyros.py --help" | 98 | #PYROS_CMD = "python3 pyros.py --help" |
86 | #PYROS_CMD = "python3 pyros.py $*" | 99 | #PYROS_CMD = "python3 pyros.py $*" |
@@ -88,16 +101,19 @@ PYROS_CMD = "python3 pyros.py " + args | @@ -88,16 +101,19 @@ PYROS_CMD = "python3 pyros.py " + args | ||
88 | PYROS_CMD = PYROS_CMD.rstrip() | 101 | PYROS_CMD = PYROS_CMD.rstrip() |
89 | 102 | ||
90 | # DOCKER_OUT_CONTAINER true ? => docker exec | 103 | # DOCKER_OUT_CONTAINER true ? => docker exec |
91 | -#docker exec -it pyros python3 pyros.py $* | ||
92 | -#[ $DOCKER_OUT_CONTAINER == true ] && cd docker/ && docker-compose up -d && PREFIX='docker exec -it pyros' | ||
93 | -if DOCKER_OUT_CONTAINER : | ||
94 | - #cd docker/ | ||
95 | - os.chdir('docker') | ||
96 | - #docker-compose up -d | ||
97 | - run('docker-compose up -d') | 104 | +# docker exec -it pyros python3 pyros.py $* |
105 | +# [ $DOCKER_OUT_CONTAINER == true ] && cd docker/ && docker-compose up -d && PREFIX='docker exec -it pyros' | ||
106 | +if DOCKER_OUT_CONTAINER: | ||
107 | + # cd docker/ | ||
108 | + os.chdir('docker') | ||
109 | + # docker-compose up -d | ||
110 | + res = subprocess.run("docker exec -it pyros python3 pyros.py",stdout=subprocess.DEVNULL) | ||
111 | + if res.returncode != 0: | ||
112 | + run('docker-compose up -d') | ||
113 | + sleep(5) | ||
98 | PYROS_CMD = 'docker exec -it pyros ' + PYROS_CMD | 114 | PYROS_CMD = 'docker exec -it pyros ' + PYROS_CMD |
99 | 115 | ||
100 | -#PYROS_CMD | 116 | +# PYROS_CMD |
101 | print("\n Executing command :", PYROS_CMD, "\n") | 117 | print("\n Executing command :", PYROS_CMD, "\n") |
102 | res = run(PYROS_CMD) | 118 | res = run(PYROS_CMD) |
103 | 119 | ||
@@ -111,11 +127,6 @@ print() | @@ -111,11 +127,6 @@ print() | ||
111 | print(result.stderr) | 127 | print(result.stderr) |
112 | ''' | 128 | ''' |
113 | 129 | ||
114 | - | ||
115 | - | ||
116 | - | ||
117 | - | ||
118 | - | ||
119 | 130 | ||
120 | ''' | 131 | ''' |
121 | ########################## | 132 | ########################## |
VERSION
src/core/pyros_django/obsconfig/obsconfig_class.py
@@ -114,7 +114,7 @@ class OBSConfig: | @@ -114,7 +114,7 @@ class OBSConfig: | ||
114 | self.devices_links = pickle_dict["devices_links"] | 114 | self.devices_links = pickle_dict["devices_links"] |
115 | self.obs_config_file_content = pickle_dict["obs_config_file_content"] | 115 | self.obs_config_file_content = pickle_dict["obs_config_file_content"] |
116 | self.raw_config = pickle_dict["raw_config"] | 116 | self.raw_config = pickle_dict["raw_config"] |
117 | - self.agents = pickle_dict["agents"] | 117 | + #self.agents = pickle_dict["agents"] |
118 | except: | 118 | except: |
119 | # we rewrite the pickle file, the content will be the same otherwise we would be in the else case | 119 | # we rewrite the pickle file, the content will be the same otherwise we would be in the else case |
120 | print( | 120 | print( |