Commit fb2b07f6 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Merge branch 'bz2download' into 'master'

Fixed issue with bz2 files

See merge request !83
parents b5c85f8b 1934da87
Pipeline #20900 passed with stages
in 8 minutes and 27 seconds
...@@ -14,13 +14,26 @@ def _unzip(zip_file, directory): ...@@ -14,13 +14,26 @@ def _unzip(zip_file, directory):
myzip.extractall(directory) myzip.extractall(directory)
def _untar(tar_file, directory, mode): def _untar(tar_file, directory, ext):
if ext in [".bz2" or ".tbz2"]:
mode = "r:bz2"
elif ext in [".gz" or ".tgz"]:
mode = "r:gz"
mode = "r"
import tarfile import tarfile
with, mode=mode) as t:
with, mode='r:'+mode) as t:
t.extractall(directory) t.extractall(directory)
def _unbz2(bz2_file):
import bz2
with bz2.BZ2File(bz2_file) as t:
open(os.path.splitext(bz2_file)[0], 'wb').write(
def download_file(url, out_file): def download_file(url, out_file):
"""Downloads a file from a given url """Downloads a file from a given url
...@@ -90,12 +103,16 @@ def download_and_unzip(urls, filename): ...@@ -90,12 +103,16 @@ def download_and_unzip(urls, filename):
# Uncompressing if it is the case # Uncompressing if it is the case
ext = os.path.splitext(filename)[-1].lower() ext = os.path.splitext(filename)[-1].lower()
header = os.path.splitext(filename)[0].lower()
if ext == ".zip": if ext == ".zip":"Unziping in {0}".format(filename))"Unziping in {0}".format(filename))
_unzip(filename, os.path.dirname(filename)) _unzip(filename, os.path.dirname(filename))
elif ext in [".gz", ".bz2"]: elif header[-4:] == ".tar" or ext in [".tgz", ".tbz2"]:"Untar/gzip in {0}".format(filename))"Untar/gzip in {0}".format(filename))
_untar(filename, os.path.dirname(filename), mode=ext[1:]) _untar(filename, os.path.dirname(filename), ext)
elif ext == ".bz2":"Unbz2 in {0}".format(filename))
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment