本文整理匯總了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")