Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
storagedriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
4
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
67c57436
authored
Mar 01, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unzip downloaded file
parent
eed9c4e8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
2 deletions
+37
-2
disk.py
+37
-2
No files found.
disk.py
View file @
67c57436
...
...
@@ -3,6 +3,9 @@ import os
import
subprocess
import
re
import
logging
from
shutil
import
move
,
copyfileobj
from
zipfile
import
ZipFile
,
is_zipfile
import
requests
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -105,7 +108,7 @@ class Disk(object):
# Call subprocess
subprocess
.
check_output
(
cmdline
)
def
download
(
self
,
task
,
url
,
parent_id
=
None
):
def
download
(
self
,
task
,
url
,
parent_id
=
None
):
# noqa
''' Download image from url. '''
disk_path
=
self
.
get_path
()
logger
.
info
(
"Downloading image from
%
s to
%
s"
,
url
,
disk_path
)
...
...
@@ -140,9 +143,41 @@ class Disk(object):
self
.
name
,
self
.
size
)
except
AbortException
:
# Cleanup file:
os
.
unlink
(
self
.
get_path
()
)
os
.
unlink
(
disk_path
)
logger
.
info
(
"Download
%
s aborted
%
s removed."
,
url
,
disk_path
)
except
:
os
.
unlink
(
disk_path
)
logger
.
error
(
"Download
%
s failed,
%
s removed."
,
url
,
disk_path
)
raise
else
:
ext
=
url
.
split
(
'.'
)[
-
1
]
.
lower
()
if
ext
==
'zip'
and
is_zipfile
(
disk_path
):
task
.
update_state
(
task_id
=
parent_id
,
state
=
task
.
AsyncResult
(
parent_id
)
.
state
,
meta
=
{
'size'
:
actual_size
,
'extracting'
:
'zip'
,
'percent'
:
99
})
self
.
extract_iso_from_zip
(
disk_path
)
def
extract_iso_from_zip
(
self
,
disk_path
):
with
ZipFile
(
disk_path
,
'r'
)
as
z
:
isos
=
z
.
namelist
()
if
len
(
isos
)
!=
1
:
isos
=
[
i
for
i
in
isos
if
i
.
lower
()
.
endswith
(
'.iso'
)]
if
len
(
isos
)
==
1
:
logger
.
info
(
'Unzipping
%
s started.'
,
disk_path
)
f
=
open
(
disk_path
+
'~'
,
'wb'
)
zf
=
z
.
open
(
isos
[
0
])
with
zf
,
f
:
copyfileobj
(
zf
,
f
)
f
.
flush
()
move
(
disk_path
+
'~'
,
disk_path
)
else
:
logger
.
info
(
"Extracting
%
s failed, keeping original."
,
disk_path
)
def
snapshot
(
self
):
''' Creating qcow2 snapshot with base image.
...
...
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