From 5accf3f08eae830647cb70faae274c21d8309d1f Mon Sep 17 00:00:00 2001 From: paulojamorim Date: Mon, 11 Jan 2010 13:13:04 +0000 Subject: [PATCH] ADD: Function to get the amount of memory installed in the system. --- invesalius/utils.py | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 8 deletions(-) diff --git a/invesalius/utils.py b/invesalius/utils.py index a2d58f3..d397829 100755 --- a/invesalius/utils.py +++ b/invesalius/utils.py @@ -16,6 +16,10 @@ # PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais # detalhes. #-------------------------------------------------------------------------- +import subprocess +import re +import os + def debug(error_str): from project import Project @@ -35,7 +39,7 @@ class Singleton(type): cls.instance=super(Singleton,cls).__call__(*args,**kw) return cls.instance -# Another possible implementation +# Another possible implementation #class Singleton(object): # def __new__(cls, *args, **kwargs): # if '_inst' not in vars(cls): @@ -49,13 +53,13 @@ class TwoWaysDictionary(dict): """ def __init__(self, items=[]): dict.__init__(self, items) - + def get_key(self, value): """ Find the key(s) as a list given a value. """ return [item[0] for item in self.items() if item[1] == value] - + def get_value(self, key): """ Find the value given a key. @@ -80,25 +84,28 @@ def frange(start, end=None, inc=None): elif inc < 0 and next <= end: break L.append(next) - + return L + def PredictingMemory(qtd, x, y, p): m = qtd * (x * y * p) - + #314859200 = 350 MB - #house 25 MB increases the + #house 25 MB increases the #factor 0.4 if (m >= 314859200): porcent = 1.5 + (m - 314859200) / 26999999 * 0.04 x = x/porcent y = y/porcent return x + else: - return x - + return x + return x + def BytesConvert(bytes): if bytes >= 1073741824: return str(bytes / 1024 / 1024 / 1024) + ' GB' @@ -109,3 +116,64 @@ def BytesConvert(bytes): elif bytes < 1024: return str(bytes) + ' bytes' + +def GetWindowsInformation(): + + command = "systeminfo" + + startupinfo = subprocess.STARTUPINFO() + startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW + info = subprocess.Popen([command], startupinfo=startupinfo, + stdout=subprocess.PIPE).communicate() + + lines = info[0].splitlines() + + #Architecture of the system, x86 or x64 + architecture = lines[14] + architecture = re.findall('[0-9]+', architecture)[0] + architecture = "x" + architecture + + #Number of processors or number of nucleus + number_processors = lines[15] + number_processors = re.findall('[0-9]+', number_processors)[0] + + #Clock of the processor in Mhz + processor_clock = lines[16] + processor_clock = re.findall('~[0-9]+', processor_clock)[0] + processor_clock = float(re.findall('[0-9]+', processor_clock)[0]) + + #Total of Physical Memory in MB + total_physical_memory = lines[24 + (int(number_processors) - 1)] + total_physical_memory = float(re.findall('[0-9.]+', total_physical_memory)[0]) + + #Total of Physical Memory Avaliable in MB + available_physical_memory = lines[25 + (int(number_processors) - 1)] + available_physical_memory = float(re.findall('[0-9.]+', + available_physical_memory)[0]) + + return (architecture, number_processors, + processor_clock, total_physical_memory, + available_physical_memory) + + +def GetLinuxInformation(): + + #Architecture of the system, x86 or x64 + architecture = LinuxCommand("uname -m") + architecture = architecture[0].splitlines()[0] + + #Clock of the processor in Mhz + processor_clock = LinuxCommand("more /proc/cpuinfo") + processor_clock = processor_clock[0].splitlines() + processor_clock = float(re.findall('[0-9.]+', processor_clock[6])[0]) + + + #processor_clock = float(re.findall('[0-9]+', processor_clock)[0]) + print architecture + print processor_clock + + +def LinuxCommand(command): + return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).communicate() + + -- libgit2 0.21.2