Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
diffoscope
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Reproducible Builds
diffoscope
Commits
355ea40e
Commit
355ea40e
authored
7 years ago
by
Chris Lamb
Browse files
Options
Downloads
Patches
Plain Diff
Tidy diffoscope.progress a little.
parent
30782cb5
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
diffoscope/progress.py
+21
-15
21 additions, 15 deletions
diffoscope/progress.py
with
21 additions
and
15 deletions
diffoscope/progress.py
+
21
−
15
View file @
355ea40e
...
...
@@ -24,26 +24,26 @@ import logging
logger
=
logging
.
getLogger
(
__name__
)
class
ProgressLoggingHandler
(
logging
.
StreamHandler
):
class
ProgressLoggingHandler
(
logging
.
StreamHandler
):
def
__init__
(
self
,
progressbar
):
self
.
progressbar
=
progressbar
super
().
__init__
()
def
emit
(
self
,
record
):
try
:
#
d
elete the current line (i.e. the progress bar)
#
D
elete the current line (i.e. the progress bar)
self
.
stream
.
write
(
"
\r\033
[K
"
)
self
.
flush
()
super
().
emit
(
record
)
if
not
self
.
progressbar
.
bar
.
finished
:
self
.
progressbar
.
bar
.
update
()
except
Exception
:
# have to do this try-except wrapping otherwise tests fail
# due to test_progress.py running main() several times.
# this mirrors the super() implementation.
# Wrap otherwise tests fail due to test_progress.py call main()
# several times. This mirrors the super() implementation.
self
.
handleError
(
record
)
class
ProgressManager
(
object
):
_singleton
=
{}
...
...
@@ -115,6 +115,7 @@ class ProgressManager(object):
for
x
in
self
.
observers
:
x
.
finish
()
class
Progress
(
object
):
def
__init__
(
self
,
total
=
None
):
self
.
done
=
[]
...
...
@@ -141,17 +142,20 @@ class Progress(object):
if
self
.
current_steps
:
if
self
.
current_child_steps_done
or
cur_child_estimate
:
# something is in-progress, the calculation is slightly more complex
# Something is in-progress, the calculation is slightly more
# complex
cur_child_done
,
cur_child_total
=
cur_child_estimate
or
(
0
,
0
)
own_done
+=
self
.
current_steps
all_done
+=
self
.
current_steps
+
self
.
current_child_steps_done
+
cur_child_done
# cost of what we expect will have been done, once the current in-progress
# step plus all of its children, have completed
expected_all_done
=
all_done
+
(
cur_child_total
-
cur_child_done
)
assert
own_done
# non-zero
return
all_done
,
int
(
float
(
self
.
total
)
/
own_done
*
expected_all_done
)
else
:
pass
# nothing in progress
all_done
+=
self
.
current_steps
+
\
self
.
current_child_steps_done
+
\
cur_child_done
# Cost of what we expect will have been done, once the current
# in-progress step plus all of its children, have completed
expected_all_done
=
all_done
+
\
(
cur_child_total
-
cur_child_done
)
assert
own_done
# non-zero
return
all_done
,
int
(
float
(
self
.
total
)
/
own_done
\
*
expected_all_done
)
else
:
# nothing in progress
assert
not
cur_child_estimate
...
...
@@ -182,6 +186,7 @@ class Progress(object):
def
child_done
(
self
,
total
):
self
.
current_child_steps_done
+=
total
class
ProgressBar
(
object
):
def
__init__
(
self
):
import
progressbar
...
...
@@ -202,7 +207,7 @@ class ProgressBar(object):
class
OurProgressBar
(
progressbar
.
ProgressBar
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
# Remove after https://github.com/niltonvolpato/python-progressbar/pull/57 is fixed.
kwargs
.
setdefault
(
"
fd
"
,
sys
.
stderr
)
kwargs
.
setdefault
(
'
fd
'
,
sys
.
stderr
)
super
().
__init__
(
*
args
,
**
kwargs
)
def
_need_update
(
self
):
...
...
@@ -231,6 +236,7 @@ class ProgressBar(object):
def
finish
(
self
):
self
.
bar
.
finish
()
class
StatusFD
(
object
):
def
__init__
(
self
,
fileobj
):
self
.
fileobj
=
fileobj
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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