Commit 8e35a65d authored by Maxime Hubert's avatar Maxime Hubert
Browse files

Add support for environement variables available from one step to another.

parent e15406ab
Pipeline #143164 passed with stage
in 34 seconds
......@@ -9,3 +9,6 @@
# Virtual environments
python_env/
# Temporary environments
*.tmp
......@@ -9,6 +9,7 @@ import abc
import logging
import sys
from diva_evaluation_cli.bin.private_src.implementation.utils.actev_cli_environment import activate_environment
from diva_evaluation_cli.bin.private_src.implementation.resources_monitoring.monitor import Monitor
from diva_evaluation_cli.bin.private_src.implementation.status.status_factory import StatusFactory
......@@ -83,6 +84,10 @@ class ActevCommand():
try:
logging.info("Starting %s" % self.command)
logging.debug('Loading environment')
activate_environment()
StatusFactory.generate_status(self, 'start', args.__dict__)
self.before_command(args)
......
......@@ -3,6 +3,9 @@
This file should not be modified.
"""
import os
from diva_evaluation_cli.bin.private_src.implementation.utils.actev_cli_environment import init_environment, export_variable
from diva_evaluation_cli.bin.private_src.implementation.get_system.system_types_definition import system_types
def entry_point(url, system_type, location=None, user=None, password=None, token=None, install_cli=False, name=False):
......@@ -25,14 +28,36 @@ def entry_point(url, system_type, location=None, user=None, password=None, token
except:
raise Exception("Unknown system type")
# Init the actev_cli_environemnt variables
init_environment()
# Add variables into the actev_cli_environemnt
export_variable('ACTEV_GET_SYSTEM_URL', url)
# Destination of the software
if not location:
location = "None"
if not user:
# Username
if user:
export_variable('ACTEV_GET_SYSTEM_USER', user)
else:
user = "None"
if not password:
# Password
if password:
export_variable('ACTEV_GET_SYSTEM_PASSWORD', password)
else:
password = "None"
if not token:
# Token
if token:
export_variable('ACTEV_GET_SYSTEM_TOKEN', token)
else:
token = "None"
# Whether installing the CLI
if install_cli:
install_cli = "True"
else:
......
"""Utils module
Can be used by any other module of the CLI
Implements functions to store a bash environment between commands
"""
import logging, os
from dotenv import load_dotenv
current_dir=os.path.dirname(os.path.realpath(__file__))
ACTEV_CLI_ENVIRONMENT_FILEPATH=os.path.join(current_dir, 'actev_cli_environment.env')
def export_variable(name, value):
'''Increment the bash environment file with a key and a value
'''
append_environment('export {}="{}";'.format(name, value))
def append_environment(content='', mode='w'):
'''Increment the bash environment file with some str content.
'''
init_environment(content, mode='a')
def init_environment(content='', mode='w'):
'''Overwrite or create the bash environment file with some str content.
'''
with open(ACTEV_CLI_ENVIRONMENT_FILEPATH, 'w') as env_file:
env_file.write(content)
def activate_environment():
'''Loads the environment variables from ACTEV_CLI_ENVIRONMENT_FILEPATH
into the current environment.
'''
load_dotenv(dotenv_path=ACTEV_CLI_ENVIRONMENT_FILEPATH)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment