本文整理汇总了Python中tarfile.TarFile.read方法的典型用法代码示例。如果您正苦于以下问题:Python TarFile.read方法的具体用法?Python TarFile.read怎么用?Python TarFile.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tarfile.TarFile
的用法示例。
在下文中一共展示了TarFile.read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __handle_file
# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import read [as 别名]
def __handle_file(self, plugin_file):
# Uncompress the file.
temp_dir = tempfile.gettempdir()
if is_zipfile(plugin_file):
compress_fd = zipfile.ZipFile(plugin_file, allowZip64=True)
compress_fd.extractall(path=temp_dir)
elif is_bz2file(plugin_file):
#first check if we can handle as tar.bz2 (big chances)
try:
compress_fd = TarFile(name=plugin_file, mode="r:bz2")
compress_fd.extractall(path=temp_dir)
except CompressionError:
print "Upz!, fail in compressed file handling, Retrying"
try:
compress_fd = bz2.BZ2File(plugin_file)
tmp_fd = tempfile.TemporaryFile(suffix=".tar", prefix="ncmprs")
tmp_fd.file.write(compress_fd.read())
tmp_fd.file.flush()
tar_fd = TarFile.taropen(name=None, fileobj=tmp_fd)
tar_fd.extractall(path=temp_dir)
tar_fd.close()
tmp_fd.close()
except:
print "Upz!, fail in compressed file handling, Again! :("
return None
elif is_gzipfile(plugin_file):
#first check if we can handle as tar.gz (big chances)
try:
compress_fd = TarFile(name=plugin_file, mode="r:gz")
compress_fd.extractall(path=temp_dir)
except CompressionError:
print "Upz!, fail in compressed file handling, Retrying"
try:
compress_fd = gzip.GzipFile(plugin_file)
tmp_fd = tempfile.TemporaryFile(suffix=".tar", prefix="ncmprs")
tmp_fd.file.write(compress_fd.read())
tmp_fd.file.flush()
tar_fd = TarFile.taropen(name=None, fileobj=tmp_fd)
tar_fd.extractall(path=temp_dir)
tar_fd.close()
tmp_fd.close()
except:
print "Upz!, fail in compressed file handling, Again! :("
return None
return self.__handle_dir(temp_dir)