file: Implement is_compressed method and simplify choosemethod

This commit is contained in:
Fatih Aşıcı
2010-07-13 09:31:21 +00:00
parent a6331b4e14
commit 5eb3cbb408
+13 -8
View File
@@ -55,6 +55,10 @@ class File:
(xz, bz2, gzip, auto) = range(4) # compress enums
(detached, whatelse) = range(2)
__compressed_file_extensions = {".xz": xz,
".bz2": bz2,
".gz": gzip}
@staticmethod
def make_uri(uri):
"handle URI arg"
@@ -67,17 +71,18 @@ class File:
@staticmethod
def choose_method(filename, compress):
if compress == File.auto:
if filename.endswith('.xz'):
return File.xz
elif filename.endswith('.bz2'):
return File.bz2
elif filename.endswith('.gz'):
return File.gzip
else:
return None
for ext, method in File.__compressed_file_extensions.items():
if filename.endswith(ext):
return method
return None
else:
return compress
@staticmethod
def is_compressed(filename):
return filename.endswith(tuple(File.__compressed_file_extensions))
@staticmethod
def decompress(localfile, compress):
compress = File.choose_method(localfile, compress)