Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
conda
installer
Commits
03e58ebf
Commit
03e58ebf
authored
Aug 12, 2021
by
Paul McCarthy
🚵
Browse files
ENH: monitor_progress accepts one or more commands
parent
0c540eb0
Changes
1
Hide whitespace changes
Inline
Side-by-side
fslinstaller.py
View file @
03e58ebf
...
...
@@ -921,37 +921,48 @@ class Process(object):
@
staticmethod
def
monitor_progress
(
cmd
,
total
=
None
,
*
args
,
**
kwargs
):
"""Runs the given command, and shows a progress bar under the
"""Runs the given command
(s)
, and shows a progress bar under the
assumption that cmd will produce "total" number of lines of output.
:arg cmd: The commmand to run as a string, or a sequence of
multiple commands.
:arg total: Total number of lines of standard output to expect.
"""
if
total
is
None
:
label
=
None
else
:
label
=
'%'
if
isinstance
(
cmd
,
str
):
cmds
=
[
cmd
]
else
:
cmds
=
cmd
with
Progress
(
label
=
label
,
fmt
=
'{:.0f}'
,
transform
=
Progress
.
percent
)
as
prog
:
proc
=
Process
(
cmd
,
*
args
,
**
kwargs
)
nlines
=
0
if
total
else
None
prog
.
update
(
nlines
,
total
)
for
cmd
in
cmds
:
while
proc
.
returncode
is
None
:
try
:
line
=
proc
.
stdoutq
.
get
(
timeout
=
0.5
)
nlines
=
(
nlines
+
1
)
if
total
else
None
except
queue
.
Empty
:
pass
proc
=
Process
(
cmd
,
*
args
,
**
kwargs
)
nlines
=
0
if
total
else
None
prog
.
update
(
nlines
,
total
)
proc
.
popen
.
poll
()
# force progress bar to 100% when finished
if
proc
.
returncode
==
0
:
prog
.
update
(
total
,
total
)
else
:
raise
RuntimeError
(
'This command returned an error: '
+
cmd
)
while
proc
.
returncode
is
None
:
try
:
line
=
proc
.
stdoutq
.
get
(
timeout
=
0.5
)
nlines
=
(
nlines
+
1
)
if
total
else
None
except
queue
.
Empty
:
pass
prog
.
update
(
nlines
,
total
)
proc
.
popen
.
poll
()
# force progress bar to 100% when finished
if
proc
.
returncode
==
0
:
prog
.
update
(
total
,
total
)
else
:
raise
RuntimeError
(
'This command returned '
'an error: '
+
cmd
)
@
staticmethod
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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