Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
4ab94cb7
Commit
4ab94cb7
authored
Dec 10, 2019
by
Surgan Jandial
Committed by
Francisco Massa
Dec 10, 2019
Browse files
add .tgz support to extract_archive (#1650)
* tgz updates * tgz updates * tgz updates
parent
598b61d9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
2 deletions
+6
-2
test/test_datasets_utils.py
test/test_datasets_utils.py
+1
-1
torchvision/datasets/utils.py
torchvision/datasets/utils.py
+5
-1
No files found.
test/test_datasets_utils.py
View file @
4ab94cb7
...
@@ -86,7 +86,7 @@ class Tester(unittest.TestCase):
...
@@ -86,7 +86,7 @@ class Tester(unittest.TestCase):
@
unittest
.
skipIf
(
'win'
in
sys
.
platform
,
'temporarily disabled on Windows'
)
@
unittest
.
skipIf
(
'win'
in
sys
.
platform
,
'temporarily disabled on Windows'
)
def
test_extract_tar
(
self
):
def
test_extract_tar
(
self
):
for
ext
,
mode
in
zip
([
'.tar'
,
'.tar.gz'
],
[
'w
'
,
'w:gz'
]):
for
ext
,
mode
in
zip
([
'.tar'
,
'.tar.gz'
,
'.tgz'
],
[
'w'
,
'w:gz
'
,
'w:gz'
]):
with
get_tmp_dir
()
as
temp_dir
:
with
get_tmp_dir
()
as
temp_dir
:
with
tempfile
.
NamedTemporaryFile
()
as
bf
:
with
tempfile
.
NamedTemporaryFile
()
as
bf
:
bf
.
write
(
"this is the content"
.
encode
())
bf
.
write
(
"this is the content"
.
encode
())
...
...
torchvision/datasets/utils.py
View file @
4ab94cb7
...
@@ -213,6 +213,10 @@ def _is_targz(filename):
...
@@ -213,6 +213,10 @@ def _is_targz(filename):
return
filename
.
endswith
(
".tar.gz"
)
return
filename
.
endswith
(
".tar.gz"
)
def
_is_tgz
(
filename
):
return
filename
.
endswith
(
".tgz"
)
def
_is_gzip
(
filename
):
def
_is_gzip
(
filename
):
return
filename
.
endswith
(
".gz"
)
and
not
filename
.
endswith
(
".tar.gz"
)
return
filename
.
endswith
(
".gz"
)
and
not
filename
.
endswith
(
".tar.gz"
)
...
@@ -228,7 +232,7 @@ def extract_archive(from_path, to_path=None, remove_finished=False):
...
@@ -228,7 +232,7 @@ def extract_archive(from_path, to_path=None, remove_finished=False):
if
_is_tar
(
from_path
):
if
_is_tar
(
from_path
):
with
tarfile
.
open
(
from_path
,
'r'
)
as
tar
:
with
tarfile
.
open
(
from_path
,
'r'
)
as
tar
:
tar
.
extractall
(
path
=
to_path
)
tar
.
extractall
(
path
=
to_path
)
elif
_is_targz
(
from_path
):
elif
_is_targz
(
from_path
)
or
_is_tgz
(
from_path
)
:
with
tarfile
.
open
(
from_path
,
'r:gz'
)
as
tar
:
with
tarfile
.
open
(
from_path
,
'r:gz'
)
as
tar
:
tar
.
extractall
(
path
=
to_path
)
tar
.
extractall
(
path
=
to_path
)
elif
_is_tarxz
(
from_path
)
and
PY3
:
elif
_is_tarxz
(
from_path
)
and
PY3
:
...
...
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