GitLab will be upgraded on June 23rd evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

Commit 50e04745 authored by Emmanuel Papillon's avatar Emmanuel Papillon

remove user_script now in standard bliss

parent 33c81201
import importlib
import os
import sys
from bliss import current_session
from bliss.config.settings import SimpleSetting
USER_SCRIPT_HOME = SimpleSetting(
"%s:script_home" %,
default_value="%s/bliss_scripts" % os.getenv("HOME"),
__all__ = [
def user_script_directory(new_dir=None):
if new_dir is not None:
if not os.path.isdir(new_dir):
raise RuntimeError(f"Invalid directory [{new_dir}]")
return USER_SCRIPT_HOME.get()
def user_script_list():
rootdir = USER_SCRIPT_HOME.get()
print(f"Scripts found in [{rootdir}]:")
for (dirpath, dirnames, filenames) in os.walk(rootdir):
dirname = dirpath.replace(rootdir, "")
dirname = dirname.lstrip("/")
if len(dirname):
dirname += "/"
for filename in filenames:
print(f" - {dirname}{filename}")
def user_script_load(scriptname):
_user_script_exec(scriptname, export=True)
def user_script_run(scriptname):
_user_script_exec(scriptname, export=False)
def _user_script_exec(scriptname, export=False):
script_dir = os.path.abspath(USER_SCRIPT_HOME.get())
(filename, fileext) = os.path.splitext(scriptname)
if not fileext:
fileext = ".py"
filepath = os.path.join(script_dir, "".join((filename, fileext)))
if not os.path.isfile(filepath):
raise RuntimeError(f"Cannot find [{filepath}] !!")
script = open(filepath).read()
raise RuntimeError(f"Failed to read [{filepath}] !!")
print(f"Running [{filepath}] ...")
globals_dict = current_session.env_dict.copy()
exec(script, globals_dict)
if export is True:
for k in globals_dict.keys():
if k.startswith("_"):
current_session.env_dict[k] = globals_dict[k]
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