patches/gdesklets-01-Solaris-support.diff
author bewitche
Thu, 22 Nov 2007 07:11:07 +0000
changeset 11231 0079405625d1
parent 9332 54fcb5f27e0e
permissions -rw-r--r--
Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
     1
diff -Nrup gDesklets-0.36beta/configure.in gDesklets-0.36/configure.in
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
     2
--- gDesklets-0.36beta/configure.in	2007-10-04 19:22:08.000000000 +0800
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
     3
+++ gDesklets-0.36/configure.in	2007-10-08 13:13:10.232393000 +0800
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
     4
@@ -125,6 +125,7 @@ libdesklets/system/Linux/Makefile
9174
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
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    12
diff -Nrup gDesklets-0.36beta/libdesklets/system/Makefile.am gDesklets-0.36/libdesklets/system/Makefile.am
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    13
--- gDesklets-0.36beta/libdesklets/system/Makefile.am	2007-10-04 19:22:11.000000000 +0800
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    14
+++ gDesklets-0.36/libdesklets/system/Makefile.am	2007-10-08 13:12:22.576595000 +0800
9332
54fcb5f27e0e 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9331
diff changeset
    15
@@ -20,7 +20,8 @@ SUBDIRS = \
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    16
 	Linux \
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    17
 	FreeBSD \
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    18
 	NetBSD \
9332
54fcb5f27e0e 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9331
diff changeset
    19
-	OpenBSD
54fcb5f27e0e 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9331
diff changeset
    20
+	OpenBSD \
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    21
+	Solaris 
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    22
 
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    23
 
9332
54fcb5f27e0e 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9331
diff changeset
    24
 gtop_la_LDFLAGS = -module -avoid-version -as-needed
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    25
diff -Nrup gDesklets-0.36beta/libdesklets/system/Solaris/Generic.py gDesklets-0.36/libdesklets/system/Solaris/Generic.py
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    26
--- gDesklets-0.36beta/libdesklets/system/Solaris/Generic.py	1970-01-01 08:00:00.000000000 +0800
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    27
+++ gDesklets-0.36/libdesklets/system/Solaris/Generic.py	2007-10-08 13:14:07.732202000 +0800
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    28
@@ -0,0 +1,54 @@
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    29
+from libdesklets.system.Arch import Arch
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    30
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    31
+import re
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    32
+import struct
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    33
+import os
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    34
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    35
+class Generic(Arch):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    36
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    37
+    def __init__(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    38
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    39
+        Arch.__init__(self)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    40
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    41
+        self.__bogomips    = re.compile('^bogomips\s+:\s+(\d+\.\d+)$', re.M)
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    42
+        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
    43
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    44
+
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    45
+
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    46
+    def net_devices(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    47
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    48
+        @return : all available network devices
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    49
+        @rtype  : list
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    50
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    51
+
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    52
+        return self.__net_devices
9174
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
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    55
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    56
+    def cpu_bogomips(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    57
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    58
+        @return : bogomips of installed processor
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    59
+        @rtype  : float
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
+
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
    62
+        return float(5000)
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    63
+
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
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    66
+    def users(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    67
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    68
+        @return : number of connected users
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    69
+        @rtype  : int
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
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    72
+        count = 0
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    73
+        data = open('/var/adm/utmpx', 'rb').read()
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
+        for i in range(0, len(data), 384):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    76
+            ut_type = struct.unpack('h', data[i:i+2])[0]
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
+            if (ut_type == 7):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    79
+                count += 1
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
+        return count
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    82
+
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    83
diff -Nrup gDesklets-0.36beta/libdesklets/system/Solaris/Makefile.am gDesklets-0.36/libdesklets/system/Solaris/Makefile.am
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    84
--- gDesklets-0.36beta/libdesklets/system/Solaris/Makefile.am	1970-01-01 08:00:00.000000000 +0800
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    85
+++ gDesklets-0.36/libdesklets/system/Solaris/Makefile.am	2007-10-08 13:14:07.732326000 +0800
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    86
@@ -0,0 +1,11 @@
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    87
+installdir = ${coredir}/libdesklets/system/Solaris
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    88
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    89
+install_DATA = \
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    90
+	__init__.py	\
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    91
+	Generic.py \
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    92
+	Sparc.py \
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    93
+	X86.py
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
+EXTRA_DIST = $(install_DATA)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    96
+install_PYTHON = $(install_DATA)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
    97
+CLEANFILES = *.pyc
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    98
diff -Nrup gDesklets-0.36beta/libdesklets/system/Solaris/Sparc.py gDesklets-0.36/libdesklets/system/Solaris/Sparc.py
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
    99
--- gDesklets-0.36beta/libdesklets/system/Solaris/Sparc.py	1970-01-01 08:00:00.000000000 +0800
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   100
+++ gDesklets-0.36/libdesklets/system/Solaris/Sparc.py	2007-10-08 13:14:07.732468000 +0800
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   101
@@ -0,0 +1,68 @@
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   102
+from Generic import Generic
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   103
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   104
+import os
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   105
+import re
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   106
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   107
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   108
+class Sparc(Generic):
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
+    def __init__(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   111
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   112
+        Generic.__init__(self)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   113
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   114
+        def _get_model():
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   115
+            r = re.compile('brand\s+(.+)$', re.M)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   116
+            m = r.findall( self._read_cpuinfo() )
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   117
+            return m[0]
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   118
+
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   119
+        def _get_cache():
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   120
+            r = re.compile('^\s+ecache-size:+\s+(.+)$',re.M)
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   121
+            m = r.findall(os.popen('/usr/sbin/prtconf -vp').read())
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   122
+            m_int = int(m[0],16)
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   123
+            return int(round(m_int/1000))
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   124
+
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   125
+        def _read_cpu_speed():
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   126
+            r = re.compile('clock_MHz\s+(\d+)$', re.M)
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   127
+            m = r.findall(self._read_cpuinfo())
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   128
+            return float(int(m[0]))
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   129
+
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   130
+        # CPU model and cache size never changes
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   131
+        self.__model_name = _get_model()
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   132
+        self.__cache_size = _get_cache()
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   133
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   134
+        # the cpu speed might change (laptops have mobile CPUs)
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   135
+        self.__speed = _read_cpu_speed()
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   136
+
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   137
+
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   138
+    def _read_cpuinfo(self):
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   139
+            """
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   140
+            @return : content of cpu_info
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   141
+            @rtype  : str
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   142
+            """
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   143
+            return os.popen('/usr/bin/kstat cpu_info').read()
9174
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
+    def cpu_speed(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   146
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   147
+        @return : current clock of installed processor
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   148
+        @rtype  : float
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
+
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   151
+        return self.__speed
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   152
+
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   153
+
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   154
+    def cpu_cache(self):
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   155
+        """
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   156
+        @return : 2nd level cache of installed processor
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   157
+        @rtype  : int
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   158
+        """
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   159
+
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   160
+        return self.__cache_size
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   161
+
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   162
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   163
+    def cpu_model(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   164
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   165
+        @return : model/type of installed processor
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   166
+        @rtype  : str
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
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   169
+        return self.__model_name
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   170
diff -Nrup gDesklets-0.36beta/libdesklets/system/Solaris/X86.py gDesklets-0.36/libdesklets/system/Solaris/X86.py
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   171
--- gDesklets-0.36beta/libdesklets/system/Solaris/X86.py	1970-01-01 08:00:00.000000000 +0800
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   172
+++ gDesklets-0.36/libdesklets/system/Solaris/X86.py	2007-10-08 13:14:07.732611000 +0800
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   173
@@ -0,0 +1,86 @@
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   174
+from Generic import Generic
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   175
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   176
+import re
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   177
+import struct
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   178
+import os
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   179
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   180
+# Also works for x86_64
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   181
+# it seems that there's no difference
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   182
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   183
+class X86(Generic):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   184
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   185
+    def __init__(self):
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
+        Generic.__init__(self)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   188
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   189
+        def _get_model():
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   190
+            r = re.compile('^.*brand-string.*\n\s+value=(.+)$', re.M)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   191
+            m = r.findall( self._read_cpuinfo() )
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   192
+            return m[0]
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   193
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   194
+        def _get_cache():
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   195
+            r = re.compile('^.*l2-cache-size.*\n\s+value=(.+)$', re.M)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   196
+            m = r.findall( self._read_cpuinfo())
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   197
+            m_int = int(m[0],16)
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   198
+            return int(round(m_int/1000))
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   199
+
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   200
+        def _read_cpu_speed():
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   201
+            r = re.compile('^.*cpu-mhz.*\n\s+value=(.+)$', re.M)
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   202
+            m = r.findall(self._read_cpuinfo())
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   203
+            return float(int(m[0],16))
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   204
+
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   205
+        # CPU model and cache size never changes
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   206
+        self.__model_name = _get_model()
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   207
+        self.__cache_size = _get_cache()
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   208
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   209
+        # the cpu speed might change (laptops have mobile CPUs)
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   210
+        self.__speed = _read_cpu_speed()
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   211
+
9174
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
+    def _read_cpuinfo(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   214
+            """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   215
+            @return : content of cpu_info
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   216
+            @rtype  : str
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   217
+            """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   218
+            return os.popen('/usr/sbin/prtconf -v').read()
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   219
+
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   220
+
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   221
+    def cpu_cache(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   222
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   223
+        @return : 2nd level cache of installed processor
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   224
+        @rtype  : int
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
+        return self.__cache_size
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   228
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   229
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   230
+    def cpu_model(self):
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
+        @return : model/type of installed processor
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   233
+        @rtype  : str
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   234
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   235
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   236
+        return self.__model_name
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   237
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   238
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   239
+    def cpu_speed(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   240
+        """
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   241
+        @return : current clock of installed processor
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   242
+        @rtype  : float
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   243
+        """
9331
98b62f2400bf 2007-02-20 Chris Wang <[email protected]>
bewitche
parents: 9320
diff changeset
   244
+        return self.__speed
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   245
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   246
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   247
+    def users(self):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   248
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   249
+        count = 0
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   250
+        data = open('/var/adm/utmpx', 'rb').read()
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
+        for i in range(0, len(data), 384):
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   253
+            ut_type = struct.unpack('h', data[i:i+2])[0]
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   254
+
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   255
+            if (ut_type == 7):
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   256
+                count += 1
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   257
+
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   258
+        return count
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   259
+
11231
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   260
diff -Nrup gDesklets-0.36beta/libdesklets/system/Solaris/__init__.py gDesklets-0.36/libdesklets/system/Solaris/__init__.py
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   261
--- gDesklets-0.36beta/libdesklets/system/Solaris/__init__.py	1970-01-01 08:00:00.000000000 +0800
0079405625d1 Revised gdesklets 01,02,08 patches as we updated to gdesklets 0.36beta tarball
bewitche
parents: 9332
diff changeset
   262
+++ gDesklets-0.36/libdesklets/system/Solaris/__init__.py	2007-10-08 13:14:07.732742000 +0800
9174
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   263
@@ -0,0 +1,3 @@
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   264
+from X86 import X86
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   265
+from Sparc import Sparc
3d241770391c 2007-02-05 Chris Wang <[email protected]>
bewitche
parents:
diff changeset
   266
+from Generic import Generic