Author: bugman Date: Tue Mar 6 17:11:02 2012 New Revision: 15444 URL: http://svn.gna.org/viewcvs/relax?rev=15444&view=rev Log: Added support for the memory size on MS Windows to the relax info print out. Modified: 1.3/info.py Modified: 1.3/info.py URL: http://svn.gna.org/viewcvs/relax/1.3/info.py?rev=15444&r1=15443&r2=15444&view=diff ============================================================================== --- 1.3/info.py (original) +++ 1.3/info.py Tue Mar 6 17:11:02 2012 @@ -24,6 +24,9 @@ """Module containing the introductory text container.""" # Python module imports. +import ctypes +if hasattr(ctypes, 'windll'): + import ctypes.wintypes import numpy from os import popen3 import platform @@ -332,6 +335,17 @@ # The swap size. if row[0] == 'Swap:': text += format % ("Total swap size: ", row[1], "Mb") + + # Windows systems (supported by ctypes.windll). + if not text and hasattr(ctypes, 'windll'): + # Initialise the memory info class. + mem = MemoryStatusEx() + + # The RAM size. + text += format % ("Total RAM size: ", mem.ullTotalPhys / 1024.**2, "Mb") + + # The swap size. + text += format % ("Total swap size: ", mem.ullTotalVirtual / 1024.**2, "Mb") # Unknown. if not text: @@ -423,6 +437,32 @@ +class MemoryStatusEx(ctypes.Structure): + """Special object for obtaining hardware info in MS Windows.""" + + if hasattr(ctypes, 'windll'): + _fields_ = [ + ('dwLength', ctypes.wintypes.DWORD), + ('dwMemoryLoad', ctypes.wintypes.DWORD), + ('ullTotalPhys', ctypes.c_ulonglong), + ('ullAvailPhys', ctypes.c_ulonglong), + ('ullTotalPageFile', ctypes.c_ulonglong), + ('ullAvailPageFile', ctypes.c_ulonglong), + ('ullTotalVirtual', ctypes.c_ulonglong), + ('ullAvailVirtual', ctypes.c_ulonglong), + ('ullExtendedVirtual', ctypes.c_ulonglong), + ] + + def __init__(self): + """Set up the information and handle non MS Windows systems.""" + + # Get the required info (for MS Windows only). + if hasattr(ctypes, 'windll'): + self.dwLength = ctypes.sizeof(self) + ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(self)) + + + class Ref: """Reference base class."""