python tarinfo 权限位
我正在使用 tarfile
模块来检查我 tar.gz 文件中包的权限。我的问题有两个方面。
首先,权限位的值和通过 ls -l
命令得到的值不一样。从 list
命令中,我得到的值是 755
,但在我的程序中却得到了 488
。我使用了下面这个命令函数 -
def checkAndExtratZipFile (value,packageElementInfoList):
try:
tar = tarfile.open(value,"r:gz")
for tarinfo in tar:
global elementType
# Populate all information about the element
name = tarinfo.name
size = tarinfo.size
perm = tarinfo.mode
if tarinfo.isdir():
eleType = elementType.Directory
elif tarinfo.issym():
eleType = elementType.SymbolicLink
else:
eleType = elementType.File
# Populate into list
packageElementInfoList.append(packageElementInfo(name,eleType,perm,size))
tar.close()
except:
print "Verification of package %s failed.\n Reason : Not able to read contents in the tar package." % value
sys.exit(1)
我的系统(在 SUSE Linux 上工作)需要验证的包是由 SUSE/AIX 和 HP 平台创建的。所以我需要在 Linux 服务器上验证在 AIX/HP/Linux 平台上构建的包。
在 Linux 上,AIX/HP 包的权限位非常奇怪。一个 755
的权限位在这里显示为 33256
。
任何帮助都非常感谢。
1 个回答
10
你看到的是一个八进制数字用十进制表示的样子:
>>> oct(488)
'0750'
你需要通过stat
模块中的属性来检查标志:
>>> tarinfo.mode
488
>>> tarinfo.mode & stat.S_IXGRP != 0
True
>>> tarinfo.mode & stat.S_IXOTH != 0
False