Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __env_to_variables(environment: list) -> dict:
variables = {}
for env in environment:
if '=' not in env:
warning('Skip not kv env param ' + env)
else:
[k, v] = env.split('=')
variables[k] = v
return variables
:param cmd: to run
:param variables: variables
:param env: custom environment
:param libraries: additional libraries used for source compilation
:return: output in json (if can be parsed) or plaintext
"""
env = _prepare_env(variables, env=env)
cmd, cwd = _prepare_cmd(cmd, args, variables, libraries=libraries)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, cwd=cwd)
if p.wait() == 0:
out = p.stdout.read().decode()
debug(out)
return _parse_output(out)
else:
out = p.stdout.read().decode()
warning(out)
raise Exception('Execution failed.')
def __form_files(self, variables) -> Optional[list]:
if self.files is not None:
if isinstance(self.files, dict):
return [self.__prepare_file(self.files, variables)]
elif isinstance(self.files, list):
return [self.__prepare_file(f, variables) for f in self.files]
else:
warning('Don\'t know how to prepare ' + type(self.files))
return None
def add_package_to_globals(package: str, glob=None, warn_missing_package=True) -> dict:
if glob is None:
glob = globals()
try:
mod = importlib.import_module(package)
glob[package] = mod
except ImportError as e:
if warn_missing_package:
warning(str(e))
else:
debug(str(e))
return glob
"""
Scan all paths for external modules and form key-value dict.
:param module_paths: list of external modules (either python packages or third-party scripts)
:param available: dict of all registered python modules (can contain python modules from module_paths)
:return: dict of external modules, where keys are filenames (same as stepnames) and values are the paths
"""
indexed = {}
for path in module_paths:
if not os.path.exists(path) and path not in available:
err = 'No such path: ' + path
error(err)
else:
for f in os.listdir(path):
mod_path = join(path, f)
if f in indexed:
warning('Override ' + indexed[f] + ' with ' + mod_path)
indexed[f] = mod_path
return indexed