patches/gdesklets-01-Solaris-support.diff
author bewitche
Mon, 05 Feb 2007 09:09:03 +0000
changeset 9174 3d241770391c
child 9295 1b5d896b593b
permissions -rw-r--r--
2007-02-05 Chris Wang <[email protected]> * gdesklets.spec: Add spec file for gdesklets * gdesklets-extra.spec: Add spec file for gdesklets extra widgets * gdesklets-01-Solaris-support.diff: Patch to add Solaris support

diff -Nrup gDesklets-0.35.3/configure.in gDesklets-old/configure.in
--- gDesklets-0.35.3/configure.in	2006-01-11 04:37:54.000000000 +0800
+++ gDesklets-old/configure.in	2007-01-26 19:19:50.658599000 +0800
@@ -136,6 +136,7 @@ libdesklets/system/Linux/Makefile
 libdesklets/system/Makefile
 libdesklets/system/NetBSD/Makefile
 libdesklets/system/OpenBSD/Makefile
+libdesklets/system/Solaris/Makefile
 main/Makefile
 plugin/Makefile
 po/Makefile.in
diff -Nrup gDesklets-0.35.3/gdesklets gDesklets-old/gdesklets
--- gDesklets-0.35.3/gdesklets	2005-05-12 06:47:55.000000000 +0800
+++ gDesklets-old/gdesklets	2007-02-01 14:24:39.760787000 +0800
@@ -58,8 +58,8 @@ def check_system():
           _("GTK python bindings (pygtk2) version >= 2.4.0 and "
             "GTK+ version >= 2.4.0 are required.")
         ),
-        ( ("ORBit",), lambda m : m.__version__ == (2, 0, 1),
-          _("ORBit python bindings (pyorbit) version == 2.0.1 are required.")
+        ( ("ORBit",), lambda m : m.__version__ >= (2, 0, 1),
+          _("ORBit python bindings (pyorbit) version >= 2.0.1 are required.")
         ),
         ( ("bonobo.ui",), lambda m : m,
           _("bonobo python bindings are required.")
diff -Nrup gDesklets-0.35.3/libdesklets/system/ArchFactory.py gDesklets-old/libdesklets/system/ArchFactory.py
--- gDesklets-0.35.3/libdesklets/system/ArchFactory.py	2005-01-22 23:33:31.000000000 +0800
+++ gDesklets-old/libdesklets/system/ArchFactory.py	2007-01-29 14:34:10.291845000 +0800
@@ -7,10 +7,6 @@ def create_arch():
 
 def __detect_arch():
 
-    if (HAVE_WIN32):
-        import Windows
-        return Windows.Win32()
-
     import os
     uname = os.uname()
 
@@ -49,7 +45,18 @@ def __detect_arch():
         import NetBSD
 
         return NetBSD.Generic()
-
+    
+    elif (uname[0] == 'SunOS'):
+        
+        import Solaris
+        r = os.popen('/usr/bin/uname -p').read()
+        if (r[:-1] in ('i386')):
+            return Solaris.X86()
+
+        if (r[:-1] in ('sparc')):
+            return Solaris.Sparc()
+        
+        return Solaris.Generic()
 
     log("OS/Architecture not found!")
 
diff -Nrup gDesklets-0.35.3/libdesklets/system/Makefile.am gDesklets-old/libdesklets/system/Makefile.am
--- gDesklets-0.35.3/libdesklets/system/Makefile.am	2005-08-01 05:29:36.000000000 +0800
+++ gDesklets-old/libdesklets/system/Makefile.am	2007-01-26 19:18:00.452263000 +0800
@@ -20,6 +20,7 @@ SUBDIRS = \
 	Linux \
 	FreeBSD \
 	NetBSD \
+	Solaris \
 	OpenBSD
 
 
diff -Nrup gDesklets-0.35.3/libdesklets/system/Solaris/Generic.py gDesklets-old/libdesklets/system/Solaris/Generic.py
--- gDesklets-0.35.3/libdesklets/system/Solaris/Generic.py	1970-01-01 08:00:00.000000000 +0800
+++ gDesklets-old/libdesklets/system/Solaris/Generic.py	2007-01-26 19:16:37.374504000 +0800
@@ -0,0 +1,62 @@
+from libdesklets.system.Arch import Arch
+
+import re
+import struct
+import os
+
+class Generic(Arch):
+
+    def __init__(self):
+
+        Arch.__init__(self)
+
+        self.__bogomips    = re.compile('^bogomips\s+:\s+(\d+\.\d+)$', re.M)
+        self.__net_devices = re.compile('^\s*(\w+):.*mtu', re.M)
+
+
+ 
+    def net_devices(self):
+        """
+        @return : all available network devices
+        @rtype  : list
+        """
+
+        return self.__net_devices.findall( os.popen('/usr/sbin/ifconfig -a').read())
+
+
+
+    def cpu_bogomips(self):
+        """
+        @return : bogomips of installed processor
+        @rtype  : float
+        """
+
+        return float(5000)
+
+
+
+    def users(self):
+        """
+        @return : number of connected users
+        @rtype  : int
+        """
+
+        # man utmp
+        # don't know if
+        # sizeof(struct utmp) == 384
+        # sizeof(short) == 2
+        # on every Linux arch
+        # http://gnomesupport.org/forums/viewtopic.php?p=33686
+        # X86, X86_64 : ok
+
+        count = 0
+        data = open('/var/adm/utmpx', 'rb').read()
+
+        for i in range(0, len(data), 384):
+
+            ut_type = struct.unpack('h', data[i:i+2])[0]
+
+            if (ut_type == 7):
+                count += 1
+
+        return count
diff -Nrup gDesklets-0.35.3/libdesklets/system/Solaris/Makefile.am gDesklets-old/libdesklets/system/Solaris/Makefile.am
--- gDesklets-0.35.3/libdesklets/system/Solaris/Makefile.am	1970-01-01 08:00:00.000000000 +0800
+++ gDesklets-old/libdesklets/system/Solaris/Makefile.am	2007-01-26 19:16:37.355351000 +0800
@@ -0,0 +1,11 @@
+installdir = ${coredir}/libdesklets/system/Solaris
+
+install_DATA = \
+	__init__.py	\
+	Generic.py \
+	Sparc.py \
+	X86.py
+
+EXTRA_DIST = $(install_DATA)
+install_PYTHON = $(install_DATA)
+CLEANFILES = *.pyc
diff -Nrup gDesklets-0.35.3/libdesklets/system/Solaris/Sparc.py gDesklets-old/libdesklets/system/Solaris/Sparc.py
--- gDesklets-0.35.3/libdesklets/system/Solaris/Sparc.py	1970-01-01 08:00:00.000000000 +0800
+++ gDesklets-old/libdesklets/system/Solaris/Sparc.py	2007-01-26 19:16:37.381956000 +0800
@@ -0,0 +1,55 @@
+from Generic import Generic
+
+import os
+import re
+
+
+class Sparc(Generic):
+
+    def __init__(self):
+
+        Generic.__init__(self)
+
+        def _get_model():
+            r = re.compile('brand\s+(.+)$', re.M)
+            m = r.findall( self._read_cpuinfo() )
+            return m[0]
+        
+        def _get_cache():
+            r = re.compile('^\s+ecache-size:+\s+(.+)$',re.M).findall(os.popen('/usr/sbin/prtconf -vp').read())
+            return int(r[0],16)
+        
+        # CPU model and cache size never changes
+        self.__model_name = _get_model()
+        self.__cache_size = _get_cache()
+
+        # the cpu speed might change (laptops have mobile CPUs)
+        self.__speed = re.compile('clock_MHz\s+(\d+)$', re.M)
+
+
+
+    def cpu_speed(self):
+        """
+        @return : current clock of installed processor
+        @rtype  : float
+        """
+
+        m = self.__speed.search( self._read_cpuinfo() )
+        return float(int(m[0]))
+
+
+    def _read_cpuinfo(self):
+            """
+            @return : content of cpu_info
+            @rtype  : str
+            """
+            return os.popen('/usr/bin/kstat cpu_info').read()
+        
+
+    def cpu_model(self):
+        """
+        @return : model/type of installed processor
+        @rtype  : str
+        """
+
+        return self.__model_name
diff -Nrup gDesklets-0.35.3/libdesklets/system/Solaris/X86.py gDesklets-old/libdesklets/system/Solaris/X86.py
--- gDesklets-0.35.3/libdesklets/system/Solaris/X86.py	1970-01-01 08:00:00.000000000 +0800
+++ gDesklets-old/libdesklets/system/Solaris/X86.py	2007-01-26 19:16:37.386927000 +0800
@@ -0,0 +1,92 @@
+from Generic import Generic
+
+import re
+import struct
+import os
+
+# Also works for x86_64
+# it seems that there's no difference
+
+class X86(Generic):
+
+    def __init__(self):
+
+        Generic.__init__(self)
+
+        
+        def _get_model():
+            r = re.compile('^.*brand-string.*\n\s+value=(.+)$', re.M)
+            m = r.findall( self._read_cpuinfo() )
+            return m[0]
+
+        def _get_cache():
+            r = re.compile('^.*l2-cache-size.*\n\s+value=(.+)$', re.M)
+            m = r.findall( self._read_cpuinfo())
+            m_int = int(m[0],16)
+            return int(round(m_int/1000))
+        
+        # CPU model and cache size never changes
+        self.__model_name = _get_model()
+        self.__cache_size = _get_cache()
+
+        # the cpu speed might change (laptops have mobile CPUs)
+        self.__speed      = re.compile('^.*cpu-mhz.*\n\s+value=(.+)$', re.M)
+
+    def _read_cpuinfo(self):
+            """
+            @return : content of cpu_info
+            @rtype  : str
+            """
+            return os.popen('/usr/sbin/prtconf -v').read()
+        
+    
+    def cpu_cache(self):
+        """
+        @return : 2nd level cache of installed processor
+        @rtype  : int
+        """
+
+        return self.__cache_size
+
+
+
+    def cpu_model(self):
+        """
+        @return : model/type of installed processor
+        @rtype  : str
+        """
+
+        return self.__model_name
+
+
+
+    def cpu_speed(self):
+        """
+        @return : current clock of installed processor
+        @rtype  : float
+        """
+
+        m = self.__speed.findall( self._read_cpuinfo() )
+        return float(int(m[0],16))
+
+
+
+    def users(self):
+
+        # man utmp
+        # don't know if
+        # sizeof(struct utmp) == 384
+        # sizeof(short) == 2
+        # on every Linux arch
+        # http://gnomesupport.org/forums/viewtopic.php?p=33686
+        # X86, X86_64 : ok
+
+        count = 0
+        data = open('/var/adm/utmpx', 'rb').read()
+
+        for i in range(0, len(data), 384):
+            ut_type = struct.unpack('h', data[i:i+2])[0]
+            if (ut_type == 7): count += 1
+
+        return count
+
diff -Nrup gDesklets-0.35.3/libdesklets/system/Solaris/__init__.py gDesklets-old/libdesklets/system/Solaris/__init__.py
--- gDesklets-0.35.3/libdesklets/system/Solaris/__init__.py	1970-01-01 08:00:00.000000000 +0800
+++ gDesklets-old/libdesklets/system/Solaris/__init__.py	2007-01-26 19:16:37.382350000 +0800
@@ -0,0 +1,3 @@
+from X86 import X86
+from Sparc import Sparc
+from Generic import Generic
diff -Nrup gDesklets-0.35.3/shell/plugins/Shell/__init__.py gDesklets-old/shell/plugins/Shell/__init__.py
--- gDesklets-0.35.3/shell/plugins/Shell/__init__.py	2005-03-23 10:07:29.000000000 +0800
+++ gDesklets-old/shell/plugins/Shell/__init__.py	2007-01-26 19:19:17.252365000 +0800
@@ -150,5 +150,5 @@ try:
 except:
     pass
 
-gtk.threads_init()
+gtk.gdk.threads_init()