Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dedal
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Wiki
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EBRAINS RI
Tech Hub
Platform
EBRAINS Software Distribution
dedal
Commits
e66a2e08
Commit
e66a2e08
authored
11 months ago
by
Eric Müller
Browse files
Options
Downloads
Patches
Plain Diff
feat: Add support for stdout forwarding in run()
Change-Id: Ie0937143bdd8fcc05898e38d8785daadb1fa7816
parent
6ccaf3a5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/yashchiki
+26
-21
26 additions, 21 deletions
bin/yashchiki
with
26 additions
and
21 deletions
bin/yashchiki
+
26
−
21
View file @
e66a2e08
...
...
@@ -5,6 +5,7 @@ import os
import
pathlib
import
subprocess
import
shutil
import
sys
import
tempfile
import
textwrap
import
yaml
...
...
@@ -179,33 +180,37 @@ pathlib.Path(env["TMPDIR"]).mkdir(exist_ok=True, parents=True)
def
run
(
script
:
str
,
env
:
dict
,
script_args
:
list
=
[]):
"""
Execute the given script.
If global args.debug is set, we pass stdout through line-wise.
:param script: Script to execute.
:param env: Enviroment to use for execution.
:param script_args: Arguments to supply to the script.
"""
stdout
=
""
try
:
if
args
.
debug
:
print
(
f
"
executing:
{
script
}
{
script_args
}
"
)
out
=
subprocess
.
run
(
[
"
bash
"
,
os
.
path
.
join
(
root_dir
,
script
)]
+
script_args
,
env
=
env
,
check
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
,
encoding
=
"
utf-8
"
)
stdout
=
out
.
stdout
if
args
.
debug
:
stdout
=
b
""
if
args
.
debug
:
print
(
f
"
executing:
{
script
}
{
script_args
}
"
)
cmd
=
[
"
bash
"
,
os
.
path
.
join
(
root_dir
,
script
)]
+
script_args
out
=
subprocess
.
Popen
(
cmd
,
env
=
env
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
while
True
:
line
=
out
.
stdout
.
readline
()
if
line
:
if
args
.
debug
:
sys
.
stdout
.
buffer
.
write
(
line
)
sys
.
stdout
.
flush
()
stdout
+=
line
else
:
break
out
.
wait
()
stdout
=
str
(
stdout
,
encoding
=
"
utf-8
"
)
with
args
.
log_dir
.
joinpath
(
script
.
replace
(
"
/
"
,
"
_
"
)
+
"
.log
"
).
open
(
"
w+
"
)
as
file
:
file
.
write
(
stdout
)
if
out
.
returncode
!=
0
:
if
not
args
.
debug
:
print
(
stdout
)
except
subprocess
.
CalledProcessError
as
error
:
stdout
=
error
.
stdout
print
(
stdout
)
with
args
.
log_dir
.
joinpath
(
script
.
replace
(
"
/
"
,
"
_
"
)
+
"
.log
"
).
open
(
"
w+
"
)
as
file
:
file
.
write
(
stdout
)
raise
else
:
with
args
.
log_dir
.
joinpath
(
script
.
replace
(
"
/
"
,
"
_
"
)
+
"
.log
"
).
open
(
"
w+
"
)
as
file
:
file
.
write
(
stdout
)
raise
subprocess
.
CalledProcessError
(
out
.
returncode
,
cmd
)
with
tempfile
.
TemporaryDirectory
(
prefix
=
"
spack-
"
,
dir
=
env
[
"
TMPDIR
"
])
\
...
...
This diff is collapsed.
Click to expand it.
Preview
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!
Save comment
Cancel
Please
register
or
sign in
to comment