Commit 82b3357abf8212c7cd2f8edb2c91f4a398053997

Authored by Alexis Koralewski
1 parent dd27c2bc
Exists in dev

Adding foreground flag for new-start command in pyros.py

Showing 1 changed file with 13 additions and 9 deletions   Show diff stats
@@ -245,14 +245,17 @@ def die(msg: str = ""): @@ -245,14 +245,17 @@ def die(msg: str = ""):
245 245
246 246
247 # TODO: implement is_async 247 # TODO: implement is_async
248 -def execProcess(command, from_venv=False, is_async=False): 248 +def execProcess(command, from_venv=False, is_async=False,foreground=False):
249 from_venv_str = " from venv ("+VENV_PYTHON+")" if from_venv else "" 249 from_venv_str = " from venv ("+VENV_PYTHON+")" if from_venv else ""
250 # printFullTerm(Colors.BLUE, "Executing command" + " [" + command + "]" + from_venv_str) 250 # printFullTerm(Colors.BLUE, "Executing command" + " [" + command + "]" + from_venv_str)
251 log.debug("Executing command" + " [" + command + "]" + from_venv_str) 251 log.debug("Executing command" + " [" + command + "]" + from_venv_str)
252 if from_venv: 252 if from_venv:
253 command = VENV_PYTHON+' ' + command 253 command = VENV_PYTHON+' ' + command
254 print(f"EXECUTING {command}") 254 print(f"EXECUTING {command}")
255 - process = subprocess.Popen(command, shell=True) 255 + if foreground:
  256 + process = subprocess.Popen(command, shell=True)
  257 + else:
  258 + process = subprocess.Popen(command, shell=True,stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT)
256 if is_async: 259 if is_async:
257 # current_processes.append(process) 260 # current_processes.append(process)
258 return process 261 return process
@@ -268,15 +271,15 @@ def execProcess(command, from_venv=False, is_async=False): @@ -268,15 +271,15 @@ def execProcess(command, from_venv=False, is_async=False):
268 return True if process.returncode == 0 else False 271 return True if process.returncode == 0 else False
269 272
270 273
271 -def execProcessFromVenv(command: str, is_async=False): 274 +def execProcessFromVenv(command: str, is_async=False,foreground=False):
272 # return execProcess(command, from_venv=True, is_async) 275 # return execProcess(command, from_venv=True, is_async)
273 - return execProcess(command, True, is_async) 276 + return execProcess(command, True, is_async,foreground)
274 277
275 # TODO: fusionner dans execProcess avec param is_async 278 # TODO: fusionner dans execProcess avec param is_async
276 279
277 280
278 -def execProcessFromVenvAsync(command: str):  
279 - return execProcessFromVenv(command, True) 281 +def execProcessFromVenvAsync(command: str,foreground=False):
  282 + return execProcessFromVenv(command, True,foreground)
280 """ 283 """
281 args = command.split() 284 args = command.split()
282 printFullTerm( 285 printFullTerm(
@@ -998,13 +1001,14 @@ def start(agent: str, configfile: str, observatory: str, unit: str, computer_hos @@ -998,13 +1001,14 @@ def start(agent: str, configfile: str, observatory: str, unit: str, computer_hos
998 1001
999 1002
1000 1003
1001 -@pyros_launcher.command(help="Launch an agent") 1004 +@pyros_launcher.command(help="Launch agentSST")
1002 # @global_test_options 1005 # @global_test_options
1003 @click.option('--configfile', '-c', help='the configuration file to be used') 1006 @click.option('--configfile', '-c', help='the configuration file to be used')
1004 @click.option('--observatory', '-o', help='the observatory name to be used') 1007 @click.option('--observatory', '-o', help='the observatory name to be used')
1005 @click.option('--unit', '-u', help='the unit name to be used') 1008 @click.option('--unit', '-u', help='the unit name to be used')
1006 @click.option("--computer_hostname","-cp", help="The name of simulated computer hostname") 1009 @click.option("--computer_hostname","-cp", help="The name of simulated computer hostname")
1007 -def new_start(configfile: str, observatory: str, unit: str, computer_hostname: str): 1010 +@click.option("--foreground","-fg", is_flag=True, help="Print stdout and error in terminal")
  1011 +def new_start(configfile: str, observatory: str, unit: str, computer_hostname: str,foreground:bool):
1008 log.debug("Running start command") 1012 log.debug("Running start command")
1009 try: 1013 try:
1010 from config.pyros.config_pyros import ConfigPyros 1014 from config.pyros.config_pyros import ConfigPyros
@@ -1110,7 +1114,7 @@ def new_start(configfile: str, observatory: str, unit: str, computer_hostname: s @@ -1110,7 +1114,7 @@ def new_start(configfile: str, observatory: str, unit: str, computer_hostname: s
1110 # Append this process ( [process id, agent_name, result=failure] ) 1114 # Append this process ( [process id, agent_name, result=failure] )
1111 # ("result" will be updated at the end of execution) 1115 # ("result" will be updated at the end of execution)
1112 current_processes.append( 1116 current_processes.append(
1113 - [execProcessFromVenvAsync(cmd), agent_name, -1]) 1117 + [execProcessFromVenvAsync(cmd,foreground), agent_name, -1])
1114 # self.change_dir("..") 1118 # self.change_dir("..")
1115 os.chdir(current_dir) 1119 os.chdir(current_dir)
1116 1120