Commit 1a6e4149 authored by bliss administrator's avatar bliss administrator
Browse files

* script func moved to user_script_*

parent 6d1890b6
......@@ -5,25 +5,31 @@ import sys
from bliss import current_session
from bliss.config.settings import SimpleSetting
SCRIPT_HOME = SimpleSetting(
USER_SCRIPT_HOME = SimpleSetting(
"%s:script_home" % current_session.name,
default_value="%s/bliss_scripts" % os.getenv("HOME"),
)
__all__ = ["script_directory", "run_script"]
__all__ = ["user_script_directory", "user_script_run", "user_script_load"]
def script_directory(new_dir=None):
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}]")
SCRIPT_HOME.set(new_dir)
USER_SCRIPT_HOME.set(new_dir)
else:
return SCRIPT_HOME.get()
return USER_SCRIPT_HOME.get()
def run_script(scriptname):
script_dir = os.path.abspath(SCRIPT_HOME.get())
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"
......@@ -38,7 +44,8 @@ def run_script(scriptname):
globals_dict = current_session.env_dict.copy()
exec(script, globals_dict)
for k in globals_dict.keys():
if k.startswith("_"):
continue
current_session.env_dict[k] = globals_dict[k]
if export is True:
for k in globals_dict.keys():
if k.startswith("_"):
continue
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