Author: jerome
Date: 2009-03-14 19:56:24 +0100 (Sat, 14 Mar 2009)
New Revision: 4082

Modified:
   
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/tuxdroid-gadget-system.py
Log:
* Fixed a bug on windblows xp.

Modified: 
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/tuxdroid-gadget-system.py
===================================================================
--- 
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/tuxdroid-gadget-system.py
        2009-03-14 17:47:59 UTC (rev 4081)
+++ 
software_suite_v2/software/gadgets/tuxdroid-gadget-system/trunk/tuxdroid-gadget-system/executables/tuxdroid-gadget-system.py
        2009-03-14 18:56:24 UTC (rev 4082)
@@ -1,220 +1,220 @@
-'''
-This file is part of "tuxdroid-gadget-system".
- *    Copyright 2008, kysoh
- *    Author : Conan Jerome
- *    eMail  : [email protected]
- *    Site   : http://www.kysoh.com/
- *
- * "tuxdroid-gadget-system" is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * "tuxdroid-gadget-system" is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with "tuxdroid-gadget-system"; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
- '''
- 
-import commands
-import os
-import platform
-import subprocess
-import string
-from time import sleep
- 
- 
-class pcMonitor(object):
-    '''
-    This class manage the tuxdroid-gadget-pcMoitor.
-    '''
-    
-    #User parameters.
-    tgp_giveCPU = True
-    tgp_giveMem = True
-    tgp_useCpuThreshold = False
-    tgp_useMemThreshold = False
-    tgp_cpuThreshold = "90"
-    tgp_memThreshold = "90"
-    
-    
-    if "tgp_giveCPU" in os.environ:
-        tgp_giveCPU = os.environ["tgp_giveCPU"]
-    
-    if "tgp_giveMem" in os.environ:
-        tgp_giveMem = os.environ["tgp_giveMem"]
-    
-    if "tgp_useCpuThreshold" in os.environ:
-        if os.environ["tgp_useCpuThreshold"] == "true":
-            tgp_useCpuThreshold = True
-        else:
-            tgp_useCpuThreshold = False
-        
-    
-    if "tgp_useMemThreshold" in os.environ:
-        if os.environ["tgp_useMemThreshold"] == "true":
-            tgp_useMemThreshold = True
-        else:
-            tgp_useMemThreshold = False
-    
-    if "tgp_cpuThreshold" in os.environ:
-        tgp_cpuThreshold = os.environ["tgp_cpuThreshold"]
-        tgp_cpuThreshold = string.replace(tgp_cpuThreshold, r"%", "")
-    
-    if "tgp_memThreshold" in os.environ:
-        tgp_memThreshold = os.environ["tgp_memThreshold"]
-        tgp_memThreshold = string.replace(tgp_memThreshold, r"%", "")
-    
-    
-       
-    def __init__(self):
-        '''
-        Init the gadget.
-        '''
-        if self.tgp_giveCPU :
-            
-            if not self.isWindows():
-                #linux system.
-                cpu = self.__getLinuxCPULoad()
-            else:
-                #windows system.
-                cpu = self.__getWindowsCPULoad()
-                
-                if self.tgp_useCpuThreshold:
-                    #check threshold.
-                    if (float(cpu) > float(self.tgp_cpuThreshold)):
-                        print("message \"c p u meltdown\"")
-                else:   
-                    print("message \"Your c p u load is " + str(cpu) + " 
percent\"")
-                 
-        
-        if self.tgp_giveMem:
-            
-            if not self.isWindows():
-                #linux system.
-                memory = self.__getLinuxMemoryUsage()
-            else:
-                memory = self.__getWindowsMemoryUsage()
-                
-                if self.tgp_useMemThreshold:
-                    if (float(memory) > float(self.tgp_memThreshold)):
-                        print("message \"memory is up\"")
-                else:    
-                    print("message \"Your used memory is " + str(memory) + " 
percent\"")
-            
-            
-
-
-    
-    def __getPlatform(self):
-         '''
-         Return the plateform name of this current computer.
-         '''
-         return platform.system()
-
-
-
-
-    def isWindows(self):
-        '''
-        Return true if plateform is windows.
-        '''
-        platform = self.__getPlatform()
-        return (platform == 'Windows' ) or (platform == 'windows') or 
(platform == "Microsoft")
-         
-         
-         
-    
-    def __getLinuxCPULoad(self):
-        '''
-        Return the current cpu load for linux systems.
-        '''
-        data = commands.getoutput("cat /proc/stat")
-        u1 = float( data.split()[1] )
-        n1 = float( data.split()[2] )
-        s1 = float( data.split()[3] )
-        i1 = float( data.split()[4] )
-        sleep(2)
-        datas = commands.getoutput("cat /proc/stat")
-        u2 = float( datas.split()[1] )
-        n2 = float( datas.split()[2] )
-        s2 = float( datas.split()[3] )
-        i2 = float( datas.split()[4] )
-        usage = (u2-u1) + (n2 - n1) + (s2 - s1)
-        total = (u2-u1) + (n2 - n1) + (s2 - s1) + (i2 -i1)
-        lo = (usage/total)* 100
-        return lo
-    
-    
-    
-    
-    def __getWindowsCPULoad(self):
-        '''
-        Return the cpu load for windows operating systems.
-        '''
-        process = subprocess.Popen(["wmic", "CPU", "GET", "LoadPercentage"], 
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
-        result = process.stdout.read()
-        return (result[result.find("LoadPercentage") + 
len("LoadPercentage"):]).split()[0]
-        
-
-
-
-
-    def __getLinuxMemoryUsage(self):
-        '''
-        Return the current memory usage for linux systems.
-        '''
-        def get_freemem():
-            """
-            Get free memory
-            """
-            cached = commands.getoutput("""cat /proc/meminfo | grep Cached | 
awk 'BEGIN {FS=":"} {print $2}' | awk '{print $1, $9}'""")
-            buffers = commands.getoutput("""cat /proc/meminfo | grep Buffers | 
awk 'BEGIN {FS=":"} {print $2}' | awk '{print $1, $9}'""")
-            free = commands.getoutput("""cat /proc/meminfo | grep MemFree | 
awk 'BEGIN {FS=":"} {print $2}' | awk '{print $1, $9}'""")
-            return str(int(cached.split()[0])/1024 + int(buffers)/1024 + 
int(free)/1024)
-            
-        
-        def get_usedmem():
-            """
-            Get used memory
-            """
-            total = commands.getoutput("""cat /proc/meminfo | grep MemTotal | 
awk 'BEGIN {FS=":"} {print $2}' | awk '{print $1, $9}'""")
-            cached = commands.getoutput("""cat /proc/meminfo | grep Cached | 
awk 'BEGIN {FS=":"} {print $2}' | awk '{print $1, $9}'""")
-            buffers = commands.getoutput("""cat /proc/meminfo | grep Buffers | 
awk 'BEGIN {FS=":"} {print $2}' | awk '{print $1, $9}'""")
-            free = commands.getoutput("""cat /proc/meminfo | grep MemFree | 
awk 'BEGIN {FS=":"} {print $2}' | awk '{print $1, $9}'""")
-            return str(int(total)/1024 - int(cached.split()[0])/1024 - 
int(buffers)/1024 - int(free)/1024)
-        
-        free = get_freemem()
-        used = get_usedmem()
-
-        return str(float((float(used) / (float(used) + float(free))) * 100.0))
-    
-    
-    
-    def __getWindowsMemoryUsage(self):
-        ''''
-        Return the windows memory usage.
-        '''
-        process = subprocess.Popen("systeminfo", stdin=subprocess.PIPE, 
stdout=subprocess.PIPE)
-        result = process.stdout.read()
-        totalIndex = result.find("Total Physical Memory")
-        totalAvailable = result.find("Available Physical Memory")
-        totalMem = result.find("MB", totalIndex, totalAvailable)
-        totalMem = result[ totalIndex + len("Total Physical Memory:") : 
totalMem ]
-        freeMem = result.find("MB", totalAvailable)
-        freeMem = result[ totalAvailable + len("Available Physical Memory:") : 
freeMem ]
-        totalMem = string.replace(totalMem.strip(), ".", "")
-        freeMem = string.replace(freeMem.strip(), ".", "")
-        value = str(float( float(int(totalMem) - int(freeMem)) / 
float(totalMem) ) * 100)
-        if value.find("."):
-            value = value[ : value.find(".")]
-        return value 
-        
-
-tuxdroid_gadget_pcMonitor = pcMonitor()
+'''
+This file is part of "tuxdroid-gadget-system".
+ *    Copyright 2008, kysoh
+ *    Author : Conan Jerome
+ *    eMail  : [email protected]
+ *    Site   : http://www.kysoh.com/
+ *
+ * "tuxdroid-gadget-system" is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "tuxdroid-gadget-system" is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "tuxdroid-gadget-system"; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+ '''
+ 
+import commands
+import os
+import platform
+import subprocess
+import string
+from time import sleep
+ 
+ 
+class pcMonitor(object):
+    '''
+    This class manage the tuxdroid-gadget-pcMoitor.
+    '''
+    
+    #User parameters.
+    tgp_giveCPU = True
+    tgp_giveMem = True
+    tgp_useCpuThreshold = False
+    tgp_useMemThreshold = False
+    tgp_cpuThreshold = "90"
+    tgp_memThreshold = "90"
+    
+    
+    if "tgp_giveCPU" in os.environ:
+        tgp_giveCPU = os.environ["tgp_giveCPU"]
+    
+    if "tgp_giveMem" in os.environ:
+        tgp_giveMem = os.environ["tgp_giveMem"]
+    
+    if "tgp_useCpuThreshold" in os.environ:
+        if os.environ["tgp_useCpuThreshold"] == "true":
+            tgp_useCpuThreshold = True
+        else:
+            tgp_useCpuThreshold = False
+        
+    
+    if "tgp_useMemThreshold" in os.environ:
+        if os.environ["tgp_useMemThreshold"] == "true":
+            tgp_useMemThreshold = True
+        else:
+            tgp_useMemThreshold = False
+    
+    if "tgp_cpuThreshold" in os.environ:
+        tgp_cpuThreshold = os.environ["tgp_cpuThreshold"]
+        tgp_cpuThreshold = string.replace(tgp_cpuThreshold, r"%", "")
+    
+    if "tgp_memThreshold" in os.environ:
+        tgp_memThreshold = os.environ["tgp_memThreshold"]
+        tgp_memThreshold = string.replace(tgp_memThreshold, r"%", "")
+    
+    
+       
+    def __init__(self):
+        '''
+        Init the gadget.
+        '''
+        if self.tgp_giveCPU :
+            
+            if not self.isWindows():
+                #linux system.
+                cpu = self.__getLinuxCPULoad()
+            else:
+                #windows system.
+                cpu = self.__getWindowsCPULoad()
+                
+                if self.tgp_useCpuThreshold:
+                    #check threshold.
+                    if (float(cpu) > float(self.tgp_cpuThreshold)):
+                        print("message \"c p u meltdown\"")
+                else:   
+                    print("message \"Your c p u load is " + str(cpu) + " 
percent\"")
+                 
+        
+        if self.tgp_giveMem:
+            
+            if not self.isWindows():
+                #linux system.
+                memory = self.__getLinuxMemoryUsage()
+            else:
+                memory = self.__getWindowsMemoryUsage()
+                
+                if self.tgp_useMemThreshold:
+                    if (float(memory) > float(self.tgp_memThreshold)):
+                        print("message \"memory is up\"")
+                else:    
+                    print("message \"Your used memory is " + str(memory) + " 
percent\"")
+            
+            
+
+
+    
+    def __getPlatform(self):
+         '''
+         Return the plateform name of this current computer.
+         '''
+         return platform.system()
+
+
+
+
+    def isWindows(self):
+        '''
+        Return true if plateform is windows.
+        '''
+        platform = self.__getPlatform()
+        return (platform == 'Windows' ) or (platform == 'windows') or 
(platform == "Microsoft")
+         
+         
+         
+    
+    def __getLinuxCPULoad(self):
+        '''
+        Return the current cpu load for linux systems.
+        '''
+        data = commands.getoutput("cat /proc/stat")
+        u1 = float( data.split()[1] )
+        n1 = float( data.split()[2] )
+        s1 = float( data.split()[3] )
+        i1 = float( data.split()[4] )
+        sleep(2)
+        datas = commands.getoutput("cat /proc/stat")
+        u2 = float( datas.split()[1] )
+        n2 = float( datas.split()[2] )
+        s2 = float( datas.split()[3] )
+        i2 = float( datas.split()[4] )
+        usage = (u2-u1) + (n2 - n1) + (s2 - s1)
+        total = (u2-u1) + (n2 - n1) + (s2 - s1) + (i2 -i1)
+        lo = (usage/total)* 100
+        return lo
+    
+    
+    
+    
+    def __getWindowsCPULoad(self):
+        '''
+        Return the cpu load for windows operating systems.
+        '''
+        process = subprocess.Popen("wmic CPU GET LoadPercentage", 
stdout=subprocess.PIPE)
+        result = process.stdout.read()
+        return (result[result.find("LoadPercentage") + 
len("LoadPercentage"):]).split()[0]
+        
+
+
+
+
+    def __getLinuxMemoryUsage(self):
+        '''
+        Return the current memory usage for linux systems.
+        '''
+        def get_freemem():
+            """
+            Get free memory
+            """
+            cached = commands.getoutput("""cat /proc/meminfo | grep Cached | 
awk 'BEGIN {FS=":"} {print $2}' | awk '{print $1, $9}'""")
+            buffers = commands.getoutput("""cat /proc/meminfo | grep Buffers | 
awk 'BEGIN {FS=":"} {print $2}' | awk '{print $1, $9}'""")
+            free = commands.getoutput("""cat /proc/meminfo | grep MemFree | 
awk 'BEGIN {FS=":"} {print $2}' | awk '{print $1, $9}'""")
+            return str(int(cached.split()[0])/1024 + int(buffers)/1024 + 
int(free)/1024)
+            
+        
+        def get_usedmem():
+            """
+            Get used memory
+            """
+            total = commands.getoutput("""cat /proc/meminfo | grep MemTotal | 
awk 'BEGIN {FS=":"} {print $2}' | awk '{print $1, $9}'""")
+            cached = commands.getoutput("""cat /proc/meminfo | grep Cached | 
awk 'BEGIN {FS=":"} {print $2}' | awk '{print $1, $9}'""")
+            buffers = commands.getoutput("""cat /proc/meminfo | grep Buffers | 
awk 'BEGIN {FS=":"} {print $2}' | awk '{print $1, $9}'""")
+            free = commands.getoutput("""cat /proc/meminfo | grep MemFree | 
awk 'BEGIN {FS=":"} {print $2}' | awk '{print $1, $9}'""")
+            return str(int(total)/1024 - int(cached.split()[0])/1024 - 
int(buffers)/1024 - int(free)/1024)
+        
+        free = get_freemem()
+        used = get_usedmem()
+
+        return str(float((float(used) / (float(used) + float(free))) * 100.0))
+    
+    
+    
+    def __getWindowsMemoryUsage(self):
+        ''''
+        Return the windows memory usage.
+        '''
+        process = subprocess.Popen("systeminfo", stdin=subprocess.PIPE, 
stdout=subprocess.PIPE)
+        result = process.stdout.read()
+        totalIndex = result.find("Total Physical Memory")
+        totalAvailable = result.find("Available Physical Memory")
+        totalMem = result.find("MB", totalIndex, totalAvailable)
+        totalMem = result[ totalIndex + len("Total Physical Memory:") : 
totalMem ]
+        freeMem = result.find("MB", totalAvailable)
+        freeMem = result[ totalAvailable + len("Available Physical Memory:") : 
freeMem ]
+        totalMem = string.replace(totalMem.strip(), ".", "")
+        freeMem = string.replace(freeMem.strip(), ".", "")
+        value = str(float( float(int(totalMem) - int(freeMem)) / 
float(totalMem) ) * 100)
+        if value.find("."):
+            value = value[ : value.find(".")]
+        return value 
+        
+
+tuxdroid_gadget_pcMonitor = pcMonitor()


------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to