Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ID11
id11
Commits
1a6e4149
Commit
1a6e4149
authored
Dec 10, 2019
by
bliss administrator
Browse files
* script func moved to user_script_*
parent
6d1890b6
Changes
1
Hide whitespace changes
Inline
Side-by-side
id11/script.py
→
id11/
user_
script.py
View file @
1a6e4149
...
...
@@ -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
]
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment