file: Implement is_compressed method and simplify choosemethod
This commit is contained in:
+13
-8
@@ -55,6 +55,10 @@ class File:
|
|||||||
(xz, bz2, gzip, auto) = range(4) # compress enums
|
(xz, bz2, gzip, auto) = range(4) # compress enums
|
||||||
(detached, whatelse) = range(2)
|
(detached, whatelse) = range(2)
|
||||||
|
|
||||||
|
__compressed_file_extensions = {".xz": xz,
|
||||||
|
".bz2": bz2,
|
||||||
|
".gz": gzip}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def make_uri(uri):
|
def make_uri(uri):
|
||||||
"handle URI arg"
|
"handle URI arg"
|
||||||
@@ -67,17 +71,18 @@ class File:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def choose_method(filename, compress):
|
def choose_method(filename, compress):
|
||||||
if compress == File.auto:
|
if compress == File.auto:
|
||||||
if filename.endswith('.xz'):
|
for ext, method in File.__compressed_file_extensions.items():
|
||||||
return File.xz
|
if filename.endswith(ext):
|
||||||
elif filename.endswith('.bz2'):
|
return method
|
||||||
return File.bz2
|
|
||||||
elif filename.endswith('.gz'):
|
return None
|
||||||
return File.gzip
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
else:
|
else:
|
||||||
return compress
|
return compress
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def is_compressed(filename):
|
||||||
|
return filename.endswith(tuple(File.__compressed_file_extensions))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def decompress(localfile, compress):
|
def decompress(localfile, compress):
|
||||||
compress = File.choose_method(localfile, compress)
|
compress = File.choose_method(localfile, compress)
|
||||||
|
|||||||
Reference in New Issue
Block a user