1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """Provides an interface to the local machine.
20
21 """
22
23 import re;
24
25 from system import *;
26
60
62 """Represents a local system.
63
64 """
66 """Creates an empty local system.
67
68 This constructor does not initialize the local system - that
69 is done with the get_local() method.
70 """
71 System.__init__(self,name)
72
73
75 """Represents the local uptime.
76 """
80
83
85 with open("/proc/uptime") as uptime:
86 for line in uptime:
87 self._uptime=float(re.split(" ",line)[0])
88 self.callback().call("uptime.updated",self)
89
91 """Represents a local processor
92 """
94 """Creates a local processor.
95
96 Ordinarily, the name will be the same as cpu<id>.
97 """
98 Processor.__init__(self)
99 self._name=name
100 self._id=id
101 self._dict=dict()
102
103
104 self._totalusage=0
105 self._totalidle=0
106
109
112
114 ignoring=True
115
116 with open("/proc/cpuinfo") as cpuinfo:
117 for line in cpuinfo:
118 match=re.match("processor[ \t]*:[ \t]*([0-9]+)",line)
119 if match:
120
121 if match.group(1)==str(self._id):
122 ignoring=False
123 else:
124 ignoring=True
125 if not ignoring:
126 match=re.search("([^:\t]+)[ \t]*:[ \t]*(.+)$",line)
127 if match:
128 key=match.group(1)
129 val=match.group(2)
130 self._dict[key]=val
131
132
133 with open("/proc/stat") as stat:
134 for line in stat:
135 match=re.match("%s[ \\t]+([0-9]+)[ \\t]+([0-9]+)[ \\t]+([0-9]+)[ \\t]+([0-9]+)[ \\t]+"
136 % self._name,line)
137 if match:
138 usage=int(match.group(1))+int(match.group(2))+int(match.group(3))
139 idle=int(match.group(4))
140
141 newusage=usage-self._totalusage
142 newidle=idle-self._totalidle
143 if (newusage+newidle)>0:
144 pu=newusage/float(newusage+newidle)
145 else:
146 pu=0
147
148 self.dict()['usage']=pu*self.max_freq()
149 self._totalusage=usage
150 self._totalidle=idle
151 self.callback().call("processor.%s.updated" % self.name(),self)
152
153
155 """Represents a local memory (RAM) bank
156 """
157 - def __init__(self,filename="/proc/meminfo"):
158 """Creates a memory bank from the file.
159
160 By default, the file /proc/meminfo is used.
161 """
162 Memory.__init__(self)
163 self.filename=filename
164 self._dict=dict()
165
167 with open(self.filename) as meminfo:
168 for line in meminfo:
169 match=re.search("([^:]+)[ \t]*:[ \t]*(.+)$",line)
170 if match:
171 key=match.group(1)
172 val=match.group(2)
173 match=re.search("([0-9]+)[ \t]*kB",val)
174 if match:
175 val=int(match.group(1))*1024
176 match=re.search("([0-9]+)[ \t]*MB",str(val))
177 if match:
178 val=int(match.group(1))*1024*1024
179 self._dict[key]=val
180 self.callback().call("memory.updated",self)
181
184
185
187 """Represents a local filesystem.
188 """
193
196
197
199 """Represents a local drive.
200 """
202 """Creates the drive from the major and minor
203 identifiers.
204 """
205 Drive.__init__(self)
206
209
210
212 """Represents a local list of processes.
213
214 Since this class always draws its information from the /proc
215 directory, all instances created on the same system will be
216 identical.
217 """
220
223
224
226 """Represents a single local process.
227 """
228 pass
229