patches/gdesklets-01-Solaris-support.diff
author bewitche
Tue, 20 Feb 2007 03:56:13 +0000
changeset 9331 98b62f2400bf
parent 9320 76bb2cde96ad
child 9332 54fcb5f27e0e
permissions -rw-r--r--
2007-02-20 Chris Wang <[email protected]> * patch/gdesklets-01-solaris-support.diff, replace uname to uname -p
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
     1
diff -Nrup gDesklets-old/configure.in gDesklets-0.35.3/configure.in
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
     2
--- gDesklets-old/configure.in	2006-01-11 04:37:54.000000000 +0800
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
     3
+++ gDesklets-0.35.3/configure.in	2007-02-14 14:39:40.805129000 +0800
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
     4
@@ -136,6 +136,7 @@ libdesklets/system/Linux/Makefile
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
     5
 libdesklets/system/Makefile
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
     6
 libdesklets/system/NetBSD/Makefile
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
     7
 libdesklets/system/OpenBSD/Makefile
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
     8
+libdesklets/system/Solaris/Makefile
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
     9
 main/Makefile
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    10
 plugin/Makefile
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    11
 po/Makefile.in
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    12
diff -Nrup gDesklets-old/libdesklets/system/ArchFactory.py gDesklets-0.35.3/libdesklets/system/ArchFactory.py
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    13
--- gDesklets-old/libdesklets/system/ArchFactory.py	2005-01-22 23:33:31.000000000 +0800
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    14
+++ gDesklets-0.35.3/libdesklets/system/ArchFactory.py	2007-02-14 14:53:05.619030000 +0800
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    15
@@ -10,7 +10,7 @@ def __detect_arch():
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    16
     if (HAVE_WIN32):
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    17
         import Windows
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    18
         return Windows.Win32()
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    19
-
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    20
+    
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    21
     import os
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    22
     uname = os.uname()
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    23
 
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    24
@@ -49,7 +49,18 @@ def __detect_arch():
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    25
         import NetBSD
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    26
 
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    27
         return NetBSD.Generic()
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    28
-
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    29
+    
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    30
+    elif (uname[0] == 'SunOS'):
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    31
+        
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    32
+        import Solaris
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    33
+        r = os.popen('/usr/bin/uname -p').read()
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    34
+        if (r[:-1] in ('i386')):
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    35
+            return Solaris.X86()
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    36
+
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    37
+        if (r[:-1] in ('sparc')):
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    38
+            return Solaris.Sparc()
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    39
+        
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    40
+        return Solaris.Generic()
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    41
 
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    42
     log("OS/Architecture not found!")
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    43
 
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    44
diff -Nrup gDesklets-old/libdesklets/system/Makefile.am gDesklets-0.35.3/libdesklets/system/Makefile.am
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    45
--- gDesklets-old/libdesklets/system/Makefile.am	2005-08-01 05:29:36.000000000 +0800
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    46
+++ gDesklets-0.35.3/libdesklets/system/Makefile.am	2007-02-14 14:40:27.794268000 +0800
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    47
@@ -20,6 +20,7 @@ SUBDIRS = \
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    48
 	Linux \
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    49
 	FreeBSD \
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    50
 	NetBSD \
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    51
+	Solaris \
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    52
 	OpenBSD
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    53
 
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    54
 
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    55
diff -Nrup gDesklets-old/libdesklets/system/Solaris/Generic.py gDesklets-0.35.3/libdesklets/system/Solaris/Generic.py
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    56
--- gDesklets-old/libdesklets/system/Solaris/Generic.py	1970-01-01 08:00:00.000000000 +0800
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    57
+++ gDesklets-0.35.3/libdesklets/system/Solaris/Generic.py	2007-02-14 14:40:15.314517000 +0800
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    58
@@ -0,0 +1,62 @@
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    59
+from libdesklets.system.Arch import Arch
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    60
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    61
+import re
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    62
+import struct
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    63
+import os
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    64
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    65
+class Generic(Arch):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    66
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    67
+    def __init__(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    68
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    69
+        Arch.__init__(self)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    70
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    71
+        self.__bogomips    = re.compile('^bogomips\s+:\s+(\d+\.\d+)$', re.M)
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    72
+        self.__net_devices = re.compile('^\s*(\w+):.*mtu', re.M).findall( os.popen('/usr/sbin/ifconfig -a').read())
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    73
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    74
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    75
+ 
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    76
+    def net_devices(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    77
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    78
+        @return : all available network devices
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    79
+        @rtype  : list
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    80
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    81
+
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    82
+        return self.__net_devices
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    83
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    84
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    85
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    86
+    def cpu_bogomips(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    87
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    88
+        @return : bogomips of installed processor
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    89
+        @rtype  : float
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    90
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    91
+
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    92
+        return float(5000)
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    93
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    94
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    95
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    96
+    def users(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    97
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    98
+        @return : number of connected users
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    99
+        @rtype  : int
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   100
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   101
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   102
+        # man utmp
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   103
+        # don't know if
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   104
+        # sizeof(struct utmp) == 384
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   105
+        # sizeof(short) == 2
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   106
+        # on every Linux arch
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   107
+        # http://gnomesupport.org/forums/viewtopic.php?p=33686
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   108
+        # X86, X86_64 : ok
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   109
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   110
+        count = 0
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   111
+        data = open('/var/adm/utmpx', 'rb').read()
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   112
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   113
+        for i in range(0, len(data), 384):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   114
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   115
+            ut_type = struct.unpack('h', data[i:i+2])[0]
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   116
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   117
+            if (ut_type == 7):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   118
+                count += 1
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   119
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   120
+        return count
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   121
diff -Nrup gDesklets-old/libdesklets/system/Solaris/Makefile.am gDesklets-0.35.3/libdesklets/system/Solaris/Makefile.am
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   122
--- gDesklets-old/libdesklets/system/Solaris/Makefile.am	1970-01-01 08:00:00.000000000 +0800
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   123
+++ gDesklets-0.35.3/libdesklets/system/Solaris/Makefile.am	2007-02-14 14:40:15.325847000 +0800
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   124
@@ -0,0 +1,11 @@
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   125
+installdir = ${coredir}/libdesklets/system/Solaris
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   126
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   127
+install_DATA = \
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   128
+	__init__.py	\
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   129
+	Generic.py \
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   130
+	Sparc.py \
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   131
+	X86.py
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   132
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   133
+EXTRA_DIST = $(install_DATA)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   134
+install_PYTHON = $(install_DATA)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   135
+CLEANFILES = *.pyc
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   136
diff -Nrup gDesklets-old/libdesklets/system/Solaris/Sparc.py gDesklets-0.35.3/libdesklets/system/Solaris/Sparc.py
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   137
--- gDesklets-old/libdesklets/system/Solaris/Sparc.py	1970-01-01 08:00:00.000000000 +0800
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   138
+++ gDesklets-0.35.3/libdesklets/system/Solaris/Sparc.py	2007-02-14 14:40:15.326112000 +0800
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   139
@@ -0,0 +1,67 @@
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   140
+from Generic import Generic
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   141
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   142
+import os
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   143
+import re
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   144
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   145
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   146
+class Sparc(Generic):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   147
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   148
+    def __init__(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   149
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   150
+        Generic.__init__(self)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   151
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   152
+        def _get_model():
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   153
+            r = re.compile('brand\s+(.+)$', re.M)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   154
+            m = r.findall( self._read_cpuinfo() )
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   155
+            return m[0]
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   156
+        
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   157
+        def _get_cache():
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   158
+            r = re.compile('^\s+ecache-size:+\s+(.+)$',re.M)
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   159
+            m = r.findall(os.popen('/usr/sbin/prtconf -vp').read())
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   160
+            m_int = int(m[0],16)
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   161
+            return int(round(m_int/1000))
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   162
+
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   163
+        def _read_cpu_speed():
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   164
+            r = re.compile('clock_MHz\s+(\d+)$', re.M)
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   165
+            m = r.findall(self._read_cpuinfo())
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   166
+            return float(int(m[0]))
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   167
+        
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   168
+        # CPU model and cache size never changes
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   169
+        self.__model_name = _get_model()
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   170
+        self.__cache_size = _get_cache()
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   171
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   172
+        # the cpu speed might change (laptops have mobile CPUs)
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   173
+        self.__speed = _read_cpu_speed()
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   174
+
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   175
+    def _read_cpuinfo(self):
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   176
+            """
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   177
+            @return : content of cpu_info
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   178
+            @rtype  : str
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   179
+            """
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   180
+            return os.popen('/usr/bin/kstat cpu_info').read()
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   181
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   182
+    def cpu_speed(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   183
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   184
+        @return : current clock of installed processor
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   185
+        @rtype  : float
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   186
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   187
+
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   188
+        return self.__speed
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   189
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   190
+        
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   191
+    def cpu_cache(self):
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   192
+        """
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   193
+        @return : 2nd level cache of installed processor
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   194
+        @rtype  : int
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   195
+        """
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   196
+
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   197
+        return self.__cache_size
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   198
+
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   199
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   200
+    def cpu_model(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   201
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   202
+        @return : model/type of installed processor
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   203
+        @rtype  : str
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   204
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   205
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   206
+        return self.__model_name
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   207
diff -Nrup gDesklets-old/libdesklets/system/Solaris/X86.py gDesklets-0.35.3/libdesklets/system/Solaris/X86.py
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   208
--- gDesklets-old/libdesklets/system/Solaris/X86.py	1970-01-01 08:00:00.000000000 +0800
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   209
+++ gDesklets-0.35.3/libdesklets/system/Solaris/X86.py	2007-02-14 14:40:15.326279000 +0800
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   210
@@ -0,0 +1,96 @@
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   211
+from Generic import Generic
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   212
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   213
+import re
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   214
+import struct
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   215
+import os
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   216
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   217
+# Also works for x86_64
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   218
+# it seems that there's no difference
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   219
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   220
+class X86(Generic):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   221
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   222
+    def __init__(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   223
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   224
+        Generic.__init__(self)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   225
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   226
+        
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   227
+        def _get_model():
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   228
+            r = re.compile('^.*brand-string.*\n\s+value=(.+)$', re.M)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   229
+            m = r.findall( self._read_cpuinfo() )
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   230
+            return m[0]
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   231
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   232
+        def _get_cache():
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   233
+            r = re.compile('^.*l2-cache-size.*\n\s+value=(.+)$', re.M)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   234
+            m = r.findall( self._read_cpuinfo())
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   235
+            m_int = int(m[0],16)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   236
+            return int(round(m_int/1000))
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   237
+        
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   238
+        def _read_cpu_speed():
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   239
+            
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   240
+            r = re.compile('^.*cpu-mhz.*\n\s+value=(.+)$', re.M)
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   241
+            m = r.findall(self._read_cpuinfo())
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   242
+            return float(int(m[0],16))
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   243
+        
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   244
+        # CPU model and cache size never changes
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   245
+        self.__model_name = _get_model()
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   246
+        self.__cache_size = _get_cache()
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   247
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   248
+        # the cpu speed might change (laptops have mobile CPUs)
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   249
+        self.__speed = _read_cpu_speed()
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   250
+
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   251
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   252
+    def _read_cpuinfo(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   253
+            """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   254
+            @return : content of cpu_info
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   255
+            @rtype  : str
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   256
+            """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   257
+            return os.popen('/usr/sbin/prtconf -v').read()
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   258
+    
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   259
+    def cpu_cache(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   260
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   261
+        @return : 2nd level cache of installed processor
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   262
+        @rtype  : int
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   263
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   264
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   265
+        return self.__cache_size
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   266
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   267
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   268
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   269
+    def cpu_model(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   270
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   271
+        @return : model/type of installed processor
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   272
+        @rtype  : str
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   273
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   274
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   275
+        return self.__model_name
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   276
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   277
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   278
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   279
+    def cpu_speed(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   280
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   281
+        @return : current clock of installed processor
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   282
+        @rtype  : float
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   283
+        """
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   284
+        return self.__speed
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   285
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   286
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   287
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   288
+    def users(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   289
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   290
+        # man utmp
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   291
+        # don't know if
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   292
+        # sizeof(struct utmp) == 384
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   293
+        # sizeof(short) == 2
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   294
+        # on every Linux arch
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   295
+        # http://gnomesupport.org/forums/viewtopic.php?p=33686
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   296
+        # X86, X86_64 : ok
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   297
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   298
+        count = 0
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   299
+        data = open('/var/adm/utmpx', 'rb').read()
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   300
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   301
+        for i in range(0, len(data), 384):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   302
+            ut_type = struct.unpack('h', data[i:i+2])[0]
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   303
+            if (ut_type == 7): count += 1
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   304
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   305
+        return count
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   306
+
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   307
diff -Nrup gDesklets-old/libdesklets/system/Solaris/__init__.py gDesklets-0.35.3/libdesklets/system/Solaris/__init__.py
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   308
--- gDesklets-old/libdesklets/system/Solaris/__init__.py	1970-01-01 08:00:00.000000000 +0800
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   309
+++ gDesklets-0.35.3/libdesklets/system/Solaris/__init__.py	2007-02-14 14:40:15.326454000 +0800
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   310
@@ -0,0 +1,3 @@
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   311
+from X86 import X86
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   312
+from Sparc import Sparc
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   313
+from Generic import Generic
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   314
diff -Nrup gDesklets-old/shell/plugins/Shell/__init__.py gDesklets-0.35.3/shell/plugins/Shell/__init__.py
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   315
--- gDesklets-old/shell/plugins/Shell/__init__.py	2005-03-23 10:07:29.000000000 +0800
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   316
+++ gDesklets-0.35.3/shell/plugins/Shell/__init__.py	2007-02-20 11:51:00.589517000 +0800
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   317
@@ -150,5 +150,5 @@ try:
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   318
 except:
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   319
     pass
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   320
 
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   321
-gtk.threads_init()
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   322
+gtk.gdk.threads_init()
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   323