本文整理汇总了Python中tarfile.TarFile.extract方法的典型用法代码示例。如果您正苦于以下问题:Python TarFile.extract方法的具体用法?Python TarFile.extract怎么用?Python TarFile.extract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tarfile.TarFile
的用法示例。
在下文中一共展示了TarFile.extract方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_tar_experiment_download
# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import extract [as 别名]
def test_tar_experiment_download(self):
self.assertTrue(all(df.verified for df in self.dfs))
response = self.client.get(reverse(
'tardis.tardis_portal.download.streaming_download_experiment',
args=(self.exp.id, 'tar')))
with NamedTemporaryFile('w') as tarfile:
for c in response.streaming_content:
tarfile.write(c)
tarfile.flush()
self.assertEqual(int(response['Content-Length']),
os.stat(tarfile.name).st_size)
tf = TarFile(tarfile.name)
if settings.EXP_SPACES_TO_UNDERSCORES:
exp_title = self.exp.title.replace(' ', '_')
else:
exp_title = self.exp.title
exp_title = quote(exp_title,
safe=settings.SAFE_FILESYSTEM_CHARACTERS)
for df in self.dfs:
full_path = os.path.join(
exp_title,
quote(self.ds.description,
safe=settings.SAFE_FILESYSTEM_CHARACTERS),
df.directory, df.filename)
# docker has a file path limit of ~240 characters
if os.environ.get('DOCKER_BUILD', 'false') != 'true':
tf.extract(full_path, '/tmp')
self.assertEqual(
os.stat(os.path.join('/tmp', full_path)).st_size,
int(df.size))
示例2: test_tar_experiment_download
# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import extract [as 别名]
def test_tar_experiment_download(self):
self.assertTrue(all(df.verified for df in self.dfs))
response = self.client.get(
reverse("tardis.tardis_portal.download.streaming_download_experiment", args=(self.exp.id, "tar"))
)
with NamedTemporaryFile("w") as tarfile:
for c in response.streaming_content:
tarfile.write(c)
tarfile.flush()
self.assertEqual(int(response["Content-Length"]), os.stat(tarfile.name).st_size)
tf = TarFile(tarfile.name)
for df in self.dfs:
full_path = os.path.join(
self.exp.title.replace(" ", "_"), self.ds.description, df.directory, df.filename
)
tf.extract(full_path, "/tmp")
self.assertEqual(os.stat(os.path.join("/tmp", full_path)).st_size, int(df.size))
示例3: extract
# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import extract [as 别名]
def extract(self, package_filename, location, path):
tarfile = TarFile(package_filename, "r")
tarfile.extract(location, path)