2011-05-06 27 views
1

我正在使用tarfile模塊檢查tar.gz文件中包的權限。 我的問題是兩個褶皺。python tarinfo權限位

權限位值與從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軟件包的權限位非常奇怪.A 755權限位給出爲33256

任何幫助表示讚賞。

回答

6

你看到一個八進制數的底數爲10的表示:

>>> oct(488) 
'0750' 

您需要檢查使用屬性的標誌的stat模塊:

>>> tarinfo.mode 
488 
>>> tarinfo.mode & stat.S_IXGRP != 0 
True 
>>> tarinfo.mode & stat.S_IXOTH != 0 
False