2007-02-20 Chris Wang <
[email protected]>
* patch/gdesklets-01-solaris-support.diff, replace uname to uname -p
diff -Nrup gDesklets-old/configure.in gDesklets-0.35.3/configure.in
--- gDesklets-old/configure.in 2006-01-11 04:37:54.000000000 +0800
+++ gDesklets-0.35.3/configure.in 2007-02-14 14:39:40.805129000 +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-old/libdesklets/system/ArchFactory.py gDesklets-0.35.3/libdesklets/system/ArchFactory.py
--- gDesklets-old/libdesklets/system/ArchFactory.py 2005-01-22 23:33:31.000000000 +0800
+++ gDesklets-0.35.3/libdesklets/system/ArchFactory.py 2007-02-14 14:53:05.619030000 +0800
@@ -10,7 +10,7 @@ def __detect_arch():
if (HAVE_WIN32):
import Windows
return Windows.Win32()
-
+
import os
uname = os.uname()
@@ -49,7 +49,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-old/libdesklets/system/Makefile.am gDesklets-0.35.3/libdesklets/system/Makefile.am
--- gDesklets-old/libdesklets/system/Makefile.am 2005-08-01 05:29:36.000000000 +0800
+++ gDesklets-0.35.3/libdesklets/system/Makefile.am 2007-02-14 14:40:27.794268000 +0800
@@ -20,6 +20,7 @@ SUBDIRS = \
Linux \
FreeBSD \
NetBSD \
+ Solaris \
OpenBSD
diff -Nrup gDesklets-old/libdesklets/system/Solaris/Generic.py gDesklets-0.35.3/libdesklets/system/Solaris/Generic.py
--- gDesklets-old/libdesklets/system/Solaris/Generic.py 1970-01-01 08:00:00.000000000 +0800
+++ gDesklets-0.35.3/libdesklets/system/Solaris/Generic.py 2007-02-14 14:40:15.314517000 +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).findall( os.popen('/usr/sbin/ifconfig -a').read())
+
+
+
+ def net_devices(self):
+ """
+ @return : all available network devices
+ @rtype : list
+ """
+
+ return self.__net_devices
+
+
+
+ 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-old/libdesklets/system/Solaris/Makefile.am gDesklets-0.35.3/libdesklets/system/Solaris/Makefile.am
--- gDesklets-old/libdesklets/system/Solaris/Makefile.am 1970-01-01 08:00:00.000000000 +0800
+++ gDesklets-0.35.3/libdesklets/system/Solaris/Makefile.am 2007-02-14 14:40:15.325847000 +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-old/libdesklets/system/Solaris/Sparc.py gDesklets-0.35.3/libdesklets/system/Solaris/Sparc.py
--- gDesklets-old/libdesklets/system/Solaris/Sparc.py 1970-01-01 08:00:00.000000000 +0800
+++ gDesklets-0.35.3/libdesklets/system/Solaris/Sparc.py 2007-02-14 14:40:15.326112000 +0800
@@ -0,0 +1,67 @@
+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)
+ m = r.findall(os.popen('/usr/sbin/prtconf -vp').read())
+ m_int = int(m[0],16)
+ return int(round(m_int/1000))
+
+ def _read_cpu_speed():
+ r = re.compile('clock_MHz\s+(\d+)$', re.M)
+ m = r.findall(self._read_cpuinfo())
+ return float(int(m[0]))
+
+ # 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 = _read_cpu_speed()
+
+ def _read_cpuinfo(self):
+ """
+ @return : content of cpu_info
+ @rtype : str
+ """
+ return os.popen('/usr/bin/kstat cpu_info').read()
+
+ def cpu_speed(self):
+ """
+ @return : current clock of installed processor
+ @rtype : float
+ """
+
+ return self.__speed
+
+
+ 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
diff -Nrup gDesklets-old/libdesklets/system/Solaris/X86.py gDesklets-0.35.3/libdesklets/system/Solaris/X86.py
--- gDesklets-old/libdesklets/system/Solaris/X86.py 1970-01-01 08:00:00.000000000 +0800
+++ gDesklets-0.35.3/libdesklets/system/Solaris/X86.py 2007-02-14 14:40:15.326279000 +0800
@@ -0,0 +1,96 @@
+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))
+
+ def _read_cpu_speed():
+
+ r = re.compile('^.*cpu-mhz.*\n\s+value=(.+)$', re.M)
+ m = r.findall(self._read_cpuinfo())
+ return float(int(m[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 = _read_cpu_speed()
+
+
+ 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
+ """
+ return self.__speed
+
+
+
+ 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-old/libdesklets/system/Solaris/__init__.py gDesklets-0.35.3/libdesklets/system/Solaris/__init__.py
--- gDesklets-old/libdesklets/system/Solaris/__init__.py 1970-01-01 08:00:00.000000000 +0800
+++ gDesklets-0.35.3/libdesklets/system/Solaris/__init__.py 2007-02-14 14:40:15.326454000 +0800
@@ -0,0 +1,3 @@
+from X86 import X86
+from Sparc import Sparc
+from Generic import Generic
diff -Nrup gDesklets-old/shell/plugins/Shell/__init__.py gDesklets-0.35.3/shell/plugins/Shell/__init__.py
--- gDesklets-old/shell/plugins/Shell/__init__.py 2005-03-23 10:07:29.000000000 +0800
+++ gDesklets-0.35.3/shell/plugins/Shell/__init__.py 2007-02-20 11:51:00.589517000 +0800
@@ -150,5 +150,5 @@ try:
except:
pass
-gtk.threads_init()
+gtk.gdk.threads_init()