Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
snf-image-creator
Commits
96171db1
Commit
96171db1
authored
Jun 11, 2012
by
Nikos Skalkotos
Browse files
Add size param in the Output.Progress constructor
parent
5f27b178
Changes
3
Hide whitespace changes
Inline
Side-by-side
image_creator/disk.py
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
:
...
...
image_creator/output.py
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
)
...
...
image_creator/util.py
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
)
...
...
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