python tarinfo权限位

2024-09-28 03:22:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用tarfile模块检查我的焦油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。在

感谢任何帮助。在


Tags: name命令权限sizevaluelinuxtarlist
1条回答
网友
1楼 · 发布于 2024-09-28 03:22:04

你看到的是以10为基数的八进制数表示:

>>> oct(488)
'0750'

您需要使用stat模块上的属性检查标志:

^{pr2}$

相关问题 更多 >

    热门问题