From f91765a8c68d6056af3e262a8e012878ccd23ab0 Mon Sep 17 00:00:00 2001 From: paulojamorim Date: Wed, 13 Jan 2010 10:44:21 +0000 Subject: [PATCH] ENH: Implemented get physical memory amount with sigar lib --- invesalius/utils.py | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/invesalius/utils.py b/invesalius/utils.py index eb0eeac..811dcd6 100755 --- a/invesalius/utils.py +++ b/invesalius/utils.py @@ -20,6 +20,7 @@ import os import platform import subprocess import re +import sigar import sys if sys.platform == 'win32': @@ -95,12 +96,11 @@ def frange(start, end=None, inc=None): def PredictingMemory(qtd, x, y, p): m = qtd * (x * y * p) + #physical_memory in Byte + physical_memory = GetPhysicalMemoryAmount() if (sys.platform == 'win32'): - #physical_memory in Byte - physical_memory = GetWindowsInformation()[0] - if (platform.architecture()[0] == '32bit'): #(314859200 = 300 MB) #(26999999 = 25 MB) @@ -133,8 +133,6 @@ def PredictingMemory(qtd, x, y, p): elif(sys.platform == 'linux2'): - physical_memory = GetLinuxInformation()[0] - if (platform.architecture()[0] == '32bit'): # 839000000 = 800 MB if (m <= 839000000) and (physical_memory <= 2147483648): @@ -171,27 +169,15 @@ def BytesConvert(bytes): return str(bytes) + ' bytes' -def GetWindowsInformation(): - computer = wmi.WMI() - for i in computer.Win32_ComputerSystem (): - memory = int(i.TotalPhysicalMemory) - - information = (memory,) - - return information - +def GetPhysicalMemoryAmount(): + """ + Return physical memory amount in bytes + """ + sg = sigar.open() + mem = sg.mem() + sg.close() + return int(mem.total()) -def GetDarwinInformation(): - memory = 2.0 - return (memory) -def GetLinuxInformation(): - #Getting memory - with open('/proc/meminfo') as f: - for i in f: - if i.startswith('MemTotal'): - # To translate from KB to Bytes - mem = int(i.split()[1]) * 1024 - return (mem,) -- libgit2 0.21.2