~gdesklets-desklet-team/gdesklets/0.36

« back to all changes in this revision

Viewing changes to libdesklets/system/NetBSD/Generic.py

  • Committer: Robert Pastierovic
  • Date: 2007-10-07 10:08:42 UTC
  • Revision ID: pastierovic@gmail.com-20071007100842-fdvp2vzmqgh1j87k
merged 0.3x branch and basic documentation and some other changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from libdesklets.system.Arch import Arch
 
2
 
 
3
import re
 
4
import struct
 
5
 
 
6
 
 
7
class Generic(Arch):
 
8
 
 
9
    def __init__(self):
 
10
 
 
11
        Arch.__init__(self)
 
12
 
 
13
        self.__net_devices = re.compile('^\s*(\w+):.*mtu', re.M
 
14
                                        ).findall( os.popen('/sbin/ifconfig -a').read() )
 
15
 
 
16
        # cpu0 at mainbus0: MIPS R3000A CPU (0x230) Rev. 3.0 with MIPS R3010 FPC Rev. 3.0
 
17
        # cpu0: 64KB/4B direct-mapped Instruction cache, 64 TLB entries
 
18
        # cpu0: 64KB/4B direct-mapped write-through Data cache
 
19
 
 
20
        m = re.compile('^cpu0 at mainbus0: (.*?) CPU', re.M
 
21
                       ).search(open("/var/run/dmesg.log").read() )
 
22
 
 
23
        self.__model = m.group(1)
 
24
 
 
25
 
 
26
 
 
27
    def net_devices(self):
 
28
        """
 
29
        @return : all available network devices
 
30
        @rtype  : list
 
31
        """
 
32
 
 
33
        return (self.__net_devices)
 
34
 
 
35
 
 
36
 
 
37
    def cpu_model(self):
 
38
        """
 
39
        @return : model/type of installed processor
 
40
        @rtype  : str
 
41
        """
 
42
 
 
43
        return (self.__model)
 
44
 
 
45
 
 
46
 
 
47
    def users(self):
 
48
        """
 
49
        @return : number of connected users
 
50
        @rtype  : int
 
51
        """
 
52
 
 
53
        # mips3000 : ok
 
54
        count = 0
 
55
        data = open('/var/run/utmp', 'rb').read()
 
56
 
 
57
        for i in range(8, len(data), 36):
 
58
 
 
59
            ut_name = struct.unpack('c', data[i:i+1])[0]
 
60
 
 
61
            if (ut_name != '\0'):
 
62
                count += 1
 
63
 
 
64
        return count