本文整理汇总了Python中tarfile.SYMTYPE属性的典型用法代码示例。如果您正苦于以下问题:Python tarfile.SYMTYPE属性的具体用法?Python tarfile.SYMTYPE怎么用?Python tarfile.SYMTYPE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类tarfile
的用法示例。
在下文中一共展示了tarfile.SYMTYPE属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import SYMTYPE [as 别名]
def add(self, *, path, data, mode, islink=False):
if path.startswith('/'):
path = path[1:]
tar_info = tarfile.TarInfo(name=path)
if isinstance(data, str):
data_bytes = data.encode('utf-8')
else:
data_bytes = data
tar_info.size = len(data_bytes)
tar_info.mode = mode
tar_info.mtime = int(time.time())
if tar_info.size > 0:
# Ignore bandit false positive: B303:blacklist
# This is a basic checksum for debugging not a secure hash.
LOG.debug( # nosec
'Adding file path=%s size=%s md5=%s', path, tar_info.size,
hashlib.md5(data_bytes).hexdigest())
else:
LOG.warning('Zero length file added to path=%s', path)
if islink:
tar_info.type = tarfile.SYMTYPE
tar_info.linkname = data
self._tf.addfile(tar_info)
else:
self._tf.addfile(tar_info, io.BytesIO(data_bytes))
示例2: _convertFileType
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import SYMTYPE [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)
示例3: WriteSymlink
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import SYMTYPE [as 别名]
def WriteSymlink(self, src_arcname, dst_arcname):
"""Writes a symlink into the archive."""
info = self.tar_fd.tarinfo()
info.tarfile = self.tar_fd
info.name = SmartStr(dst_arcname)
info.size = 0
info.mtime = time.time()
info.type = tarfile.SYMTYPE
info.linkname = SmartStr(src_arcname)
self.tar_fd.addfile(info)
示例4: symlinkarchivestream
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import SYMTYPE [as 别名]
def symlinkarchivestream(self, ticket, data_path):
for filepath, arcpath, cont_name, cont_id, _ in ticket['target']:
t = tarfile.TarInfo(name=arcpath)
t.type = tarfile.SYMTYPE
t.linkname = os.path.relpath(filepath, data_path)
yield t.tobuf()
self.log_user_access(AccessType.download_file, cont_name=cont_name, cont_id=cont_id, filename=os.path.basename(arcpath), multifile=True, origin_override=ticket['origin']) # log download
stream = cStringIO.StringIO()
with tarfile.open(mode='w|', fileobj=stream) as _:
pass
yield stream.getvalue() # get tar stream trailer
stream.close()