本文整理汇总了Python中tarfile.LNKTYPE属性的典型用法代码示例。如果您正苦于以下问题:Python tarfile.LNKTYPE属性的具体用法?Python tarfile.LNKTYPE怎么用?Python tarfile.LNKTYPE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类tarfile
的用法示例。
在下文中一共展示了tarfile.LNKTYPE属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import LNKTYPE [as 别名]
def _test(self, name, link=None):
# See GNUWriteTest.
tarinfo = tarfile.TarInfo(name)
if link:
tarinfo.linkname = link
tarinfo.type = tarfile.LNKTYPE
tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT)
try:
tar.addfile(tarinfo)
finally:
tar.close()
tar = tarfile.open(tmpname)
try:
if link:
l = tar.getmembers()[0].linkname
self.assertTrue(link == l, "PAX longlink creation failed")
else:
n = tar.getmembers()[0].name
self.assertTrue(name == n, "PAX longname creation failed")
finally:
tar.close()
示例2: _test
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import LNKTYPE [as 别名]
def _test(self, name, link=None):
tarinfo = tarfile.TarInfo(name)
if link:
tarinfo.linkname = link
tarinfo.type = tarfile.LNKTYPE
tar = tarfile.open(tmpname, "w")
tar.format = tarfile.GNU_FORMAT
tar.addfile(tarinfo)
v1 = self._calc_size(name, link)
v2 = tar.offset
self.assertTrue(v1 == v2, "GNU longname/longlink creation failed")
tar.close()
tar = tarfile.open(tmpname)
member = tar.next()
self.assertIsNotNone(member,
"unable to read longname member")
self.assertEqual(tarinfo.name, member.name,
"unable to read longname member")
self.assertEqual(tarinfo.linkname, member.linkname,
"unable to read longname member")
示例3: _test
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import LNKTYPE [as 别名]
def _test(self, name, link=None):
# See GNUWriteTest.
tarinfo = tarfile.TarInfo(name)
if link:
tarinfo.linkname = link
tarinfo.type = tarfile.LNKTYPE
tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT)
try:
tar.addfile(tarinfo)
finally:
tar.close()
tar = tarfile.open(tmpname)
try:
if link:
l = tar.getmembers()[0].linkname
self.assertEqual(link, l, "PAX longlink creation failed")
else:
n = tar.getmembers()[0].name
self.assertEqual(name, n, "PAX longname creation failed")
finally:
tar.close()
示例4: _test
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import LNKTYPE [as 别名]
def _test(self, name, link=None):
tarinfo = tarfile.TarInfo(name)
if link:
tarinfo.linkname = link
tarinfo.type = tarfile.LNKTYPE
tar = tarfile.open(tmpname(), "w")
tar.posix = False
tar.addfile(tarinfo)
v1 = self._calc_size(name, link)
v2 = tar.offset
self.assertEqual(v1, v2, "GNU longname/longlink creation failed")
tar.close()
tar = tarfile.open(tmpname())
member = tar.next()
self.failIf(member is None, "unable to read longname member")
self.assert_(tarinfo.name == member.name and \
tarinfo.linkname == member.linkname, \
"unable to read longname member")
tar.close()
示例5: test_add_hardlink
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import LNKTYPE [as 别名]
def test_add_hardlink(self):
tarinfo = self.tar.gettarinfo(self.bar)
self.assertTrue(tarinfo.type == tarfile.LNKTYPE,
"add file as hardlink failed")
示例6: test_add_hardlink
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import LNKTYPE [as 别名]
def test_add_hardlink(self):
tarinfo = self.tar.gettarinfo(self.bar)
self.assertEqual(tarinfo.type, tarfile.LNKTYPE,
"add file as hardlink failed")
示例7: create_layer
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import LNKTYPE [as 别名]
def create_layer(*file_pairs):
output = BytesIO()
with tarfile.open(fileobj=output, mode="w:gz") as tar:
for current_filename, current_contents in file_pairs:
if current_contents is None:
# This is a deleted file.
if current_filename.endswith("/"):
current_filename = current_filename[:-1]
parts = current_filename.split("/")
if len(parts) > 1:
current_filename = "/".join(parts[:-1]) + "/" + AUFS_WHITEOUT + parts[-1]
else:
current_filename = AUFS_WHITEOUT + parts[-1]
current_contents = b""
if current_contents.startswith(b"linkto:"):
info = tarfile.TarInfo(name=current_filename)
info.linkname = current_contents[len(b"linkto:") :].decode("utf-8")
info.type = tarfile.LNKTYPE
tar.addfile(info)
else:
info = tarfile.TarInfo(name=current_filename)
info.size = len(current_contents)
tar.addfile(info, fileobj=BytesIO(current_contents))
return output.getvalue()
示例8: _convertFileType
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import LNKTYPE [as 别名]
def _convertFileType(type):
return {
tarfile.REGTYPE: S_IFREG,
tarfile.LNKTYPE: S_IFLNK,
tarfile.SYMTYPE: S_IFLNK,
tarfile.CHRTYPE: S_IFCHR,
tarfile.BLKTYPE: S_IFBLK,
tarfile.DIRTYPE: S_IFDIR,
tarfile.FIFOTYPE: S_IFIFO,
}.get(type, S_IFREG)
示例9: test_hardlink
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import LNKTYPE [as 别名]
def test_hardlink(self):
"""Test hardlink extraction (bug #857297)
"""
# Prevent errors from being caught
self.tar.errorlevel = 1
self.tar.extract("0-REGTYPE", dirname())
try:
# Extract 1-LNKTYPE which is a hardlink to 0-REGTYPE
self.tar.extract("1-LNKTYPE", dirname())
except EnvironmentError, e:
import errno
if e.errno == errno.ENOENT:
self.fail("hardlink not extracted properly")
示例10: test_add_hardlink
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import LNKTYPE [as 别名]
def test_add_hardlink(self):
# If st_nlink > 1 then the same file will be added as
# LNKTYPE.
os.link(self.foo, self.bar)
tarinfo = self.tar.gettarinfo(self.foo)
self.assertEqual(tarinfo.type, tarfile.LNKTYPE,
"add file as hardlink failed")
tarinfo = self.tar.gettarinfo(self.bar)
self.assertEqual(tarinfo.type, tarfile.LNKTYPE,
"add file as hardlink failed")