Make bz2file dependency conditional on python being below version 3.3

This commit is contained in:
mvdbeek
2017-09-05 18:30:25 +02:00
parent 4de0ec59f3
commit cccf79ac5f
9 changed files with 41 additions and 18 deletions
+7 -7
View File
@@ -25,12 +25,12 @@ from galaxy.util.checkers import check_binary, check_bz2, check_gzip, check_html
from galaxy.util.image_util import get_image_ext
try:
import bz2file
except:
bz2file = None
if sys.version_info < (3, 3):
import bz2file as bz2
else:
import bz2
assert sys.version_info[:2] >= (2, 4)
assert sys.version_info[:2] >= (2, 7)
def stop_err(msg, ret=1):
@@ -165,7 +165,7 @@ def add_file(dataset, registry, json_file, output_path):
os.chmod(dataset.path, 0o644)
dataset.name = dataset.name.rstrip('.gz')
data_type = 'gzip'
if not data_type and bz2file is not None:
if not data_type:
# See if we have a bz2 file, much like gzip
is_bzipped, is_valid = check_bz2(dataset.path, check_content)
if is_bzipped and not is_valid:
@@ -176,7 +176,7 @@ def add_file(dataset, registry, json_file, output_path):
# We need to uncompress the temp_name file
CHUNK_SIZE = 2 ** 20 # 1Mb
fd, uncompressed = tempfile.mkstemp(prefix='data_id_%s_upload_bunzip2_' % dataset.dataset_id, dir=os.path.dirname(output_path), text=False)
bzipped_file = bz2file.BZ2File(dataset.path, 'rb')
bzipped_file = bz2.BZ2File(dataset.path, 'rb')
while 1:
try:
chunk = bzipped_file.read(CHUNK_SIZE)