Commit 5accf3f08eae830647cb70faae274c21d8309d1f
1 parent
269f2ab5
Exists in
master
and in
68 other branches
ADD: Function to get the amount of memory installed in the system.
Showing
1 changed file
with
76 additions
and
8 deletions
Show diff stats
invesalius/utils.py
| ... | ... | @@ -16,6 +16,10 @@ |
| 16 | 16 | # PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais |
| 17 | 17 | # detalhes. |
| 18 | 18 | #-------------------------------------------------------------------------- |
| 19 | +import subprocess | |
| 20 | +import re | |
| 21 | +import os | |
| 22 | + | |
| 19 | 23 | |
| 20 | 24 | def debug(error_str): |
| 21 | 25 | from project import Project |
| ... | ... | @@ -35,7 +39,7 @@ class Singleton(type): |
| 35 | 39 | cls.instance=super(Singleton,cls).__call__(*args,**kw) |
| 36 | 40 | return cls.instance |
| 37 | 41 | |
| 38 | -# Another possible implementation | |
| 42 | +# Another possible implementation | |
| 39 | 43 | #class Singleton(object): |
| 40 | 44 | # def __new__(cls, *args, **kwargs): |
| 41 | 45 | # if '_inst' not in vars(cls): |
| ... | ... | @@ -49,13 +53,13 @@ class TwoWaysDictionary(dict): |
| 49 | 53 | """ |
| 50 | 54 | def __init__(self, items=[]): |
| 51 | 55 | dict.__init__(self, items) |
| 52 | - | |
| 56 | + | |
| 53 | 57 | def get_key(self, value): |
| 54 | 58 | """ |
| 55 | 59 | Find the key(s) as a list given a value. |
| 56 | 60 | """ |
| 57 | 61 | return [item[0] for item in self.items() if item[1] == value] |
| 58 | - | |
| 62 | + | |
| 59 | 63 | def get_value(self, key): |
| 60 | 64 | """ |
| 61 | 65 | Find the value given a key. |
| ... | ... | @@ -80,25 +84,28 @@ def frange(start, end=None, inc=None): |
| 80 | 84 | elif inc < 0 and next <= end: |
| 81 | 85 | break |
| 82 | 86 | L.append(next) |
| 83 | - | |
| 87 | + | |
| 84 | 88 | return L |
| 85 | 89 | |
| 90 | + | |
| 86 | 91 | def PredictingMemory(qtd, x, y, p): |
| 87 | 92 | m = qtd * (x * y * p) |
| 88 | - | |
| 93 | + | |
| 89 | 94 | #314859200 = 350 MB |
| 90 | - #house 25 MB increases the | |
| 95 | + #house 25 MB increases the | |
| 91 | 96 | #factor 0.4 |
| 92 | 97 | if (m >= 314859200): |
| 93 | 98 | porcent = 1.5 + (m - 314859200) / 26999999 * 0.04 |
| 94 | 99 | x = x/porcent |
| 95 | 100 | y = y/porcent |
| 96 | 101 | return x |
| 102 | + | |
| 97 | 103 | else: |
| 98 | - return x | |
| 99 | - | |
| 104 | + return x | |
| 105 | + | |
| 100 | 106 | return x |
| 101 | 107 | |
| 108 | + | |
| 102 | 109 | def BytesConvert(bytes): |
| 103 | 110 | if bytes >= 1073741824: |
| 104 | 111 | return str(bytes / 1024 / 1024 / 1024) + ' GB' |
| ... | ... | @@ -109,3 +116,64 @@ def BytesConvert(bytes): |
| 109 | 116 | elif bytes < 1024: |
| 110 | 117 | return str(bytes) + ' bytes' |
| 111 | 118 | |
| 119 | + | |
| 120 | +def GetWindowsInformation(): | |
| 121 | + | |
| 122 | + command = "systeminfo" | |
| 123 | + | |
| 124 | + startupinfo = subprocess.STARTUPINFO() | |
| 125 | + startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW | |
| 126 | + info = subprocess.Popen([command], startupinfo=startupinfo, | |
| 127 | + stdout=subprocess.PIPE).communicate() | |
| 128 | + | |
| 129 | + lines = info[0].splitlines() | |
| 130 | + | |
| 131 | + #Architecture of the system, x86 or x64 | |
| 132 | + architecture = lines[14] | |
| 133 | + architecture = re.findall('[0-9]+', architecture)[0] | |
| 134 | + architecture = "x" + architecture | |
| 135 | + | |
| 136 | + #Number of processors or number of nucleus | |
| 137 | + number_processors = lines[15] | |
| 138 | + number_processors = re.findall('[0-9]+', number_processors)[0] | |
| 139 | + | |
| 140 | + #Clock of the processor in Mhz | |
| 141 | + processor_clock = lines[16] | |
| 142 | + processor_clock = re.findall('~[0-9]+', processor_clock)[0] | |
| 143 | + processor_clock = float(re.findall('[0-9]+', processor_clock)[0]) | |
| 144 | + | |
| 145 | + #Total of Physical Memory in MB | |
| 146 | + total_physical_memory = lines[24 + (int(number_processors) - 1)] | |
| 147 | + total_physical_memory = float(re.findall('[0-9.]+', total_physical_memory)[0]) | |
| 148 | + | |
| 149 | + #Total of Physical Memory Avaliable in MB | |
| 150 | + available_physical_memory = lines[25 + (int(number_processors) - 1)] | |
| 151 | + available_physical_memory = float(re.findall('[0-9.]+', | |
| 152 | + available_physical_memory)[0]) | |
| 153 | + | |
| 154 | + return (architecture, number_processors, | |
| 155 | + processor_clock, total_physical_memory, | |
| 156 | + available_physical_memory) | |
| 157 | + | |
| 158 | + | |
| 159 | +def GetLinuxInformation(): | |
| 160 | + | |
| 161 | + #Architecture of the system, x86 or x64 | |
| 162 | + architecture = LinuxCommand("uname -m") | |
| 163 | + architecture = architecture[0].splitlines()[0] | |
| 164 | + | |
| 165 | + #Clock of the processor in Mhz | |
| 166 | + processor_clock = LinuxCommand("more /proc/cpuinfo") | |
| 167 | + processor_clock = processor_clock[0].splitlines() | |
| 168 | + processor_clock = float(re.findall('[0-9.]+', processor_clock[6])[0]) | |
| 169 | + | |
| 170 | + | |
| 171 | + #processor_clock = float(re.findall('[0-9]+', processor_clock)[0]) | |
| 172 | + print architecture | |
| 173 | + print processor_clock | |
| 174 | + | |
| 175 | + | |
| 176 | +def LinuxCommand(command): | |
| 177 | + return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).communicate() | |
| 178 | + | |
| 179 | + | ... | ... |