Пример #1
0
 def read_process_status(self):
     successReadCount = 0
     failedReadCount = 0
     users = Users()
     userTable = users.user_id_name_table()
     allProcFiles = os.listdir(PF.proc)
     currentProcList = []
     for eachProcFile in allProcFiles:
         try:
             successReadCount += 1
             processId = string.atoi(eachProcFile)
             processFolder = "%s%s%s" % (PF.proc, os.path.sep, processId)
             processCmdlineFile = "%s%s%s" % (processFolder, os.path.sep, 'cmdline')
             processStatusFile = "%s%s%s" % (processFolder, os.path.sep, 'status')
             cmd = open(processCmdlineFile, 'r').readlines()
             processStatus = open(processStatusFile, 'r').readlines()
             procOwner, procCurrStatus = '', ''
             #Save contents of files, in case process has been finished.
             if cmd and processStatus:
                 for eachProcessStatus in processStatus:
                     eps = eachProcessStatus.strip().split()
                     epsKey = eps[0]
                     if epsKey.startswith('Uid:'):
                         procOwner = userTable[string.atoi(eps[1])]
                     if epsKey.startswith('State:'):
                         procCurrStatus = eps[1]
                 tmpProcess = Process(cmd, procOwner, processId, procCurrStatus)
                 currentProcList.append(tmpProcess)
         except:
             failedReadCount += 1
     return currentProcList
Пример #2
0
 def disk_usage_users(self, defaultUnit='GB'):
     users_disk_result_dict = OrderedDict()
     user_name_home_table = Users.user_name_home_table()
     unitStr, unitVal = UR.unitStr, UR.unitVal
     val = unitVal[unitStr.index(defaultUnit)]
     for eKey in user_name_home_table:
         tmpPath = user_name_home_table[eKey]
         #print tmpPath
         if os.path.isfile(tmpPath) or os.path.isdir(tmpPath):
             freeSize, totalSize, usedSize, usedPercent = self.count_disk_usage_vfs(tmpPath, val)
             key_info = "%s\t|%s\t|Free: %s%s\t|Used: %s%s\t|Total: %s%s\t|%s%s" % (eKey, tmpPath, freeSize, defaultUnit, usedSize, defaultUnit, totalSize, defaultUnit, usedPercent, '%')
             users_disk_result_dict['%s%s'%('disk_',eKey)] = key_info
     return users_disk_result_dict