Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
snf-image-creator
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
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
itminedu
snf-image-creator
Commits
96171db1
Commit
96171db1
authored
12 years ago
by
Nikos Skalkotos
Browse files
Options
Downloads
Patches
Plain Diff
Add size param in the Output.Progress constructor
parent
5f27b178
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
image_creator/disk.py
+4
-6
4 additions, 6 deletions
image_creator/disk.py
image_creator/output.py
+7
-2
7 additions, 2 deletions
image_creator/output.py
image_creator/util.py
+5
-4
5 additions, 4 deletions
image_creator/util.py
with
16 additions
and
12 deletions
image_creator/disk.py
+
4
−
6
View file @
96171db1
...
...
@@ -195,9 +195,8 @@ class DiskDevice(object):
def
enable
(
self
):
"""
Enable a newly created DiskDevice
"""
self
.
progressbar
=
self
.
out
.
Progress
(
"
Launching helper VM
"
,
"
percent
"
)
self
.
progressbar
.
max
=
100
self
.
progressbar
.
goto
(
1
)
self
.
progressbar
=
self
.
out
.
Progress
(
100
,
"
Launching helper VM
"
,
"
percent
"
)
eh
=
self
.
g
.
set_event_callback
(
self
.
progress_callback
,
guestfs
.
EVENT_PROGRESS
)
self
.
g
.
launch
()
...
...
@@ -419,9 +418,8 @@ class DiskDevice(object):
MB
=
2
**
20
blocksize
=
4
*
MB
# 4MB
size
=
self
.
meta
[
'
SIZE
'
]
progress_size
=
(
size
+
MB
-
1
)
//
MB
# in MB
progressbar
=
self
.
out
.
Progress
(
"
Dumping image file
"
,
'
mb
'
)
progressbar
.
max
=
progress_size
progr_size
=
(
size
+
MB
-
1
)
//
MB
# in MB
progressbar
=
self
.
out
.
Progress
(
progr_size
,
"
Dumping image file
"
,
'
mb
'
)
with
open
(
self
.
real_device
,
'
r
'
)
as
src
:
with
open
(
outfile
,
"
w
"
)
as
dst
:
...
...
This diff is collapsed.
Click to expand it.
image_creator/output.py
+
7
−
2
View file @
96171db1
...
...
@@ -91,8 +91,9 @@ class Output(object):
Progress
=
property
(
_get_progress
)
class
_Progress
(
object
):
def
__init__
(
self
,
title
,
bar_type
=
'
default
'
):
def
__init__
(
self
,
size
,
title
,
bar_type
=
'
default
'
):
self
.
output
.
output
(
"
%s...
"
%
title
,
False
)
self
.
size
=
size
def
goto
(
self
,
dest
):
pass
...
...
@@ -140,7 +141,7 @@ class Output_wth_progress(Output_wth_colors):
'
mb
'
:
'
%(index)d/%(max)d MB
'
}
def
__init__
(
self
,
title
,
bar_type
=
'
default
'
):
def
__init__
(
self
,
size
,
title
,
bar_type
=
'
default
'
):
super
(
Output_wth_progress
.
_Progress
,
self
).
__init__
()
self
.
title
=
title
self
.
fill
=
'
#
'
...
...
@@ -148,6 +149,10 @@ class Output_wth_progress(Output_wth_colors):
self
.
bar_suffix
=
'
]
'
self
.
message
=
(
"
%s:
"
%
self
.
title
).
ljust
(
self
.
MESSAGE_LENGTH
)
self
.
suffix
=
self
.
template
[
bar_type
]
self
.
max
=
size
# print empty progress bar workaround
self
.
goto
(
1
)
def
success
(
self
,
result
):
self
.
output
.
output
(
"
\r
%s...
\033
[K
"
%
self
.
title
,
False
)
...
...
This diff is collapsed.
Click to expand it.
image_creator/util.py
+
5
−
4
View file @
96171db1
...
...
@@ -60,10 +60,11 @@ class MD5:
def
compute
(
self
,
filename
,
size
):
BLOCKSIZE
=
2
**
22
# 4MB
MB
=
2
**
20
BLOCKSIZE
=
4
*
MB
# 4MB
prog
ressbar
=
self
.
out
.
Progress
(
"
Calculating md5sum:
"
,
'
mb
'
)
progressbar
.
max
=
((
size
+
2
**
20
-
1
)
//
(
2
**
20
)
)
prog
_size
=
((
size
+
MB
-
1
)
//
MB
)
# in MB
progressbar
=
self
.
out
.
Progress
(
prog_size
,
"
Calculating md5sum:
"
,
'
mb
'
)
md5
=
hashlib
.
md5
()
with
open
(
filename
,
"
r
"
)
as
src
:
left
=
size
...
...
@@ -72,7 +73,7 @@ class MD5:
data
=
src
.
read
(
length
)
md5
.
update
(
data
)
left
-=
length
progressbar
.
goto
((
size
-
left
)
//
(
2
**
20
)
)
progressbar
.
goto
((
size
-
left
)
//
MB
)
checksum
=
md5
.
hexdigest
()
progressbar
.
success
(
checksum
)
...
...
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