mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 18:03:56 -04:00
untabify
This commit is contained in:
parent
ef0cb39c1d
commit
b765ec473e
@ -23,112 +23,112 @@ s.refresh() # If you need to refresh the dynamic data
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
class SystemInformation:
|
class SystemInformation:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
# Just in case sombody called this class by accident, we should
|
# Just in case sombody called this class by accident, we should
|
||||||
# check to make sure the OS is Linux before continuing
|
# check to make sure the OS is Linux before continuing
|
||||||
|
|
||||||
assert sys.platform == 'linux2', "Not a Linux based system. This class should not be called"
|
assert sys.platform == 'linux2', "Not a Linux based system. This class should not be called"
|
||||||
|
|
||||||
self.os = self.__getOS()
|
self.os = self.__getOS()
|
||||||
self.cpu = self.__getCPU()
|
self.cpu = self.__getCPU()
|
||||||
self.totalRAM, self.availableRAM, self.totalVM, self.availableVM = self.__getMemory()
|
self.totalRAM, self.availableRAM, self.totalVM, self.availableVM = self.__getMemory()
|
||||||
self.loadAvg = self.__getLoadAvg()
|
self.loadAvg = self.__getLoadAvg()
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
self.totalRAM, self.availableRAM, self.totalVM, self.availableVM = self.__getMemory()
|
self.totalRAM, self.availableRAM, self.totalVM, self.availableVM = self.__getMemory()
|
||||||
self.loadAvg = self.__getLoadAvg()
|
self.loadAvg = self.__getLoadAvg()
|
||||||
|
|
||||||
def __getloadAvg(self):
|
def __getloadAvg(self):
|
||||||
loadAvg = open('/proc/loadavg')
|
loadAvg = open('/proc/loadavg')
|
||||||
procloadAvg = loadAvg.read()
|
procloadAvg = loadAvg.read()
|
||||||
loadAvg.close()
|
loadAvg.close()
|
||||||
# Lets remove the \n from the raw string
|
# Lets remove the \n from the raw string
|
||||||
procloadAvg = procloadAvg.replace('\n','')
|
procloadAvg = procloadAvg.replace('\n','')
|
||||||
return procloadAvg
|
return procloadAvg
|
||||||
|
|
||||||
def __getOS(self):
|
def __getOS(self):
|
||||||
procOS = open('/proc/version')
|
procOS = open('/proc/version')
|
||||||
procOSRaw = procOS.read()
|
procOSRaw = procOS.read()
|
||||||
procOS.close()
|
procOS.close()
|
||||||
# Lets remove the \n before returning the version string
|
# Lets remove the \n before returning the version string
|
||||||
procOSRaw = procOSRaw.replace('\n', '')
|
procOSRaw = procOSRaw.replace('\n', '')
|
||||||
return procOSRaw
|
return procOSRaw
|
||||||
|
|
||||||
def __getCPU(self):
|
def __getCPU(self):
|
||||||
procCPU = open('/proc/cpuinfo')
|
procCPU = open('/proc/cpuinfo')
|
||||||
procCPURaw = procCPU.read()
|
procCPURaw = procCPU.read()
|
||||||
procCPU.close()
|
procCPU.close()
|
||||||
del procCPU
|
del procCPU
|
||||||
procCPURaw = procCPURaw.split('\n')
|
procCPURaw = procCPURaw.split('\n')
|
||||||
# Lets first figure out how many CPUs are in the system
|
# Lets first figure out how many CPUs are in the system
|
||||||
cpuCount = 0
|
cpuCount = 0
|
||||||
modelName = ''
|
modelName = ''
|
||||||
cpuMHz = ''
|
cpuMHz = ''
|
||||||
for element in procCPURaw:
|
for element in procCPURaw:
|
||||||
if element.find('processor') != -1:
|
if element.find('processor') != -1:
|
||||||
cpuCount += 1
|
cpuCount += 1
|
||||||
# cpuCount now has the total number of CPUs
|
# cpuCount now has the total number of CPUs
|
||||||
|
|
||||||
# Next, on to the Model of the Processor
|
# Next, on to the Model of the Processor
|
||||||
for element in procCPURaw:
|
for element in procCPURaw:
|
||||||
if element.find('model name') != -1:
|
if element.find('model name') != -1:
|
||||||
modelName = element[element.find(':')+2:]
|
modelName = element[element.find(':')+2:]
|
||||||
break
|
break
|
||||||
|
|
||||||
# Next, on to the clock speed
|
# Next, on to the clock speed
|
||||||
for element in procCPURaw:
|
for element in procCPURaw:
|
||||||
if element.find('cpu MHz') != -1:
|
if element.find('cpu MHz') != -1:
|
||||||
cpuMHz = element[element.find(':')+2:]
|
cpuMHz = element[element.find(':')+2:]
|
||||||
break
|
break
|
||||||
# Now that we have the info, time to return a string
|
# Now that we have the info, time to return a string
|
||||||
|
|
||||||
return "%s\t%d @ %s MHz" % (modelName, cpuCount, cpuMHz)
|
return "%s\t%d @ %s MHz" % (modelName, cpuCount, cpuMHz)
|
||||||
|
|
||||||
|
|
||||||
def __getMemory(self):
|
def __getMemory(self):
|
||||||
procMemory = open('/proc/meminfo')
|
procMemory = open('/proc/meminfo')
|
||||||
procMemoryRaw = procMemory.read()
|
procMemoryRaw = procMemory.read()
|
||||||
procMemory.close()
|
procMemory.close()
|
||||||
del procMemory
|
del procMemory
|
||||||
procMemoryRaw = procMemoryRaw.split('\n')
|
procMemoryRaw = procMemoryRaw.split('\n')
|
||||||
# We are looking for the following:
|
# We are looking for the following:
|
||||||
# MemTotal, MemFree, SwapTotal, SwapFree
|
# MemTotal, MemFree, SwapTotal, SwapFree
|
||||||
|
|
||||||
# Lets start with MemTotal first
|
# Lets start with MemTotal first
|
||||||
|
|
||||||
memTotal = ''
|
memTotal = ''
|
||||||
for element in procMemoryRaw:
|
for element in procMemoryRaw:
|
||||||
if element.find('MemTotal:') != -1:
|
if element.find('MemTotal:') != -1:
|
||||||
memTotal = element.split(':')[1].replace(' ','')
|
memTotal = element.split(':')[1].replace(' ','')
|
||||||
break
|
break
|
||||||
# Next MemFree:
|
# Next MemFree:
|
||||||
|
|
||||||
memFree = ''
|
memFree = ''
|
||||||
for element in procMemoryRaw:
|
for element in procMemoryRaw:
|
||||||
if element.find('MemFree:') != -1:
|
if element.find('MemFree:') != -1:
|
||||||
memFree = element.split(':')[1].replace(' ','')
|
memFree = element.split(':')[1].replace(' ','')
|
||||||
break
|
break
|
||||||
|
|
||||||
# SwapTotal:
|
# SwapTotal:
|
||||||
|
|
||||||
swapTotal = ''
|
swapTotal = ''
|
||||||
for element in procMemoryRaw:
|
for element in procMemoryRaw:
|
||||||
if element.find('SwapTotal:') != -1:
|
if element.find('SwapTotal:') != -1:
|
||||||
memFree = element.split(':')[1].replace(' ','')
|
memFree = element.split(':')[1].replace(' ','')
|
||||||
break
|
break
|
||||||
|
|
||||||
# SwapFree:
|
# SwapFree:
|
||||||
|
|
||||||
swapFree = ''
|
swapFree = ''
|
||||||
for element in procMemoryRaw:
|
for element in procMemoryRaw:
|
||||||
if element.find('SwapFree:') != -1:
|
if element.find('SwapFree:') != -1:
|
||||||
memFree = element.split(':')[1].replace(' ','')
|
memFree = element.split(':')[1].replace(' ','')
|
||||||
break
|
break
|
||||||
return memTotal, memFree, swapTotal, swapFree
|
return memTotal, memFree, swapTotal, swapFree
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
s = SystemInformation()
|
s = SystemInformation()
|
||||||
print s.cpu
|
print s.cpu
|
||||||
print s.totalRAM
|
print s.totalRAM
|
||||||
print s.os
|
print s.os
|
||||||
|
Loading…
x
Reference in New Issue
Block a user