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