# * Used builtin function (W0141)
# * Invalid name for type (C0103)
# * Popen has no '%s' member (E1101)
-# pylint: disable=W0142, W0612, W0141, C0103, E1101
+# pylint: disable= W0612, C0103, E1101
""" Compression and Archiving
@retval: the path of the compressed file
"""
if not os.path.isfile(file_path):
- raise OSError, "can't compress a file not existed: '%s'" % file_path
+ raise OSError ("can't compress a file not existed: '%s'" % file_path)
try:
func = _COMPRESS_FORMATS[compress_format]
except KeyError:
- raise ValueError, "unknown compress format '%s'" % compress_format
+ raise ValueError ("unknown compress format '%s'" % compress_format)
return func(file_path, True)
def decompress(file_path, decompress_format=None):
@retval: the path of the decompressed file
"""
if not os.path.isfile(file_path):
- raise OSError, "can't decompress a file not existed: '%s'" % file_path
+ raise OSError ("can't decompress a file not existed: '%s'" % file_path)
(file_name, file_ext) = os.path.splitext(file_path)
for key, suffixes in _COMPRESS_SUFFIXES.iteritems():
try:
func = _COMPRESS_FORMATS[decompress_format]
except KeyError:
- raise ValueError, "unknown decompress format '%s'" % decompress_format
+ raise ValueError ("unknown decompress format '%s'" % decompress_format)
return func(file_path, False)
cmdln = ["tar", "-C", target_dir, "-xf", archive_name]
(returncode, stdout, stderr) = _call_external(cmdln)
if returncode != 0:
- raise OSError, os.linesep.join([stdout, stderr])
+ raise OSError (os.linesep.join([stdout, stderr]))
def _imp_tarfile(archive_name, target_name):
""" Archive the directory or the file with tarfile module
@retval: the archiving result
"""
if not os.path.exists(target_name):
- raise OSError, "archive object does not exist: '%s'" % target_name
+ raise OSError ("archive object does not exist: '%s'" % target_name)
for aformat, suffixes in _ARCHIVE_SUFFIXES.iteritems():
if filter(archive_name.endswith, suffixes):
archive_format = aformat
break
else:
- raise ValueError, "unknown archive suffix '%s'" % archive_name
+ raise ValueError ("unknown archive suffix '%s'" % archive_name)
try:
func, kwargs = _ARCHIVE_FORMATS[archive_format]
except KeyError:
- raise ValueError, "unknown archive format '%s'" % archive_format
+ raise ValueError ("unknown archive format '%s'" % archive_format)
archive_name = os.path.abspath(archive_name)
target_name = os.path.abspath(target_name)
raise exception if fail to extract archive
"""
if not os.path.exists(archive_name):
- raise OSError, "archived object does not exist: '%s'" % archive_name
+ raise OSError ("archived object does not exist: '%s'" % archive_name)
archive_name = os.path.abspath(archive_name)
target_name = os.path.abspath(target_name)
if os.path.exists(target_name) and not os.path.isdir(target_name):
- raise OSError, "%s should be directory where extracted files locate"\
- % target_name
+ raise OSError ("%s should be directory where extracted files locate"\
+ % target_name)
if not os.path.exists(target_name):
os.makedirs(target_name)