Merge lp:~injaon/indicator-sysmonitor/new_sensors into lp:indicator-sysmonitor/trunk
- new_sensors
- Merge into trunk
Proposed by
Gabriel Lopez
Status: | Merged |
---|---|
Approved by: | Gabriel Lopez |
Approved revision: | 23 |
Merged at revision: | 22 |
Proposed branch: | lp:~injaon/indicator-sysmonitor/new_sensors |
Merge into: | lp:indicator-sysmonitor/trunk |
Diff against target: |
384 lines (+136/-69) 1 file modified
indicator-sysmonitor (+136/-69) |
To merge this branch: | bzr merge lp:~injaon/indicator-sysmonitor/new_sensors |
Related bugs: | |
Related blueprints: |
Support for several CPU
(Medium)
Add swap Usage
(Medium)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alex Eftimie | Approve | ||
Review via email: mp+129980@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Alex Eftimie (alexeftimie) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'indicator-sysmonitor' | |||
2 | --- indicator-sysmonitor 2012-09-26 17:53:59 +0000 | |||
3 | +++ indicator-sysmonitor 2012-10-16 20:22:18 +0000 | |||
4 | @@ -21,7 +21,6 @@ | |||
5 | 21 | import subprocess | 21 | import subprocess |
6 | 22 | import psutil as ps | 22 | import psutil as ps |
7 | 23 | import re | 23 | import re |
8 | 24 | import gobject | ||
9 | 25 | import gtk | 24 | import gtk |
10 | 26 | gtk.gdk.threads_init() | 25 | gtk.gdk.threads_init() |
11 | 27 | import appindicator | 26 | import appindicator |
12 | @@ -29,7 +28,7 @@ | |||
13 | 29 | logging.basicConfig(file=sys.stderr, level=logging.INFO) | 28 | logging.basicConfig(file=sys.stderr, level=logging.INFO) |
14 | 30 | 29 | ||
15 | 31 | B_UNITS = ['', 'KB', 'MB', 'GB', 'TB'] | 30 | B_UNITS = ['', 'KB', 'MB', 'GB', 'TB'] |
17 | 32 | VERSION = '0.5.0~unreleased' | 31 | VERSION = '0.5.1~unreleased' |
18 | 33 | HELP_MSG = """<span underline="single" size="x-large">{title}</span> | 32 | HELP_MSG = """<span underline="single" size="x-large">{title}</span> |
19 | 34 | 33 | ||
20 | 35 | {introduction} | 34 | {introduction} |
21 | @@ -47,16 +46,36 @@ | |||
22 | 47 | CPU {{cpu}} | MEM {{mem}} | root {{fs///}} | 46 | CPU {{cpu}} | MEM {{mem}} | root {{fs///}} |
23 | 48 | """.format( | 47 | """.format( |
24 | 49 | title=_("Help Page"), | 48 | title=_("Help Page"), |
26 | 50 | introduction=_("The sensors are the names of the devices you want to retrieve information from. They must be placed between brackets."), | 49 | introduction=_("The sensors are the names of the devices you want to \ |
27 | 50 | retrieve information from. They must be placed between brackets."), | ||
28 | 51 | basic=_("The basics are:"), | 51 | basic=_("The basics are:"), |
29 | 52 | cpu_desc=_("It shows the average of CPU usage."), | 52 | cpu_desc=_("It shows the average of CPU usage."), |
30 | 53 | mem_desc=_("It shows the physical memory in use."), | 53 | mem_desc=_("It shows the physical memory in use."), |
31 | 54 | bat_desc=_("It shows the available battery which id is %d."), | 54 | bat_desc=_("It shows the available battery which id is %d."), |
34 | 55 | net_desc=_("It shows the amount of data you are downloading and uploading through your network."), | 55 | net_desc=_("It shows the amount of data you are downloading and uploading \ |
35 | 56 | compose=_("Also there are the following sensors that are composed with two parts divided by two slashes."), | 56 | through your network."), |
36 | 57 | compose=_("Also there are the following sensors that are composed with \ | ||
37 | 58 | two parts divided by two slashes."), | ||
38 | 57 | fs_desc=_("Show available space in the file system."), | 59 | fs_desc=_("Show available space in the file system."), |
39 | 58 | example=_("Example:")) | 60 | example=_("Example:")) |
40 | 59 | 61 | ||
41 | 62 | supported_sensors = re.compile("\A(mem|swap|cpu\d*|net|bat\d*|fs//.+)\Z") | ||
42 | 63 | settings = { | ||
43 | 64 | 'custom_text': 'cpu: {cpu} mem: {mem}', | ||
44 | 65 | 'interval': 2, | ||
45 | 66 | 'on_startup': False, | ||
46 | 67 | 'sensors': { | ||
47 | 68 | # 'name' => (desc, cmd) | ||
48 | 69 | 'cpu\d*': (_('Average CPU usage'), True), | ||
49 | 70 | 'mem': (_('Physical memory in use.'), True), | ||
50 | 71 | 'net': (_('Network activity.'), True), | ||
51 | 72 | 'bat\d*': (_('Network activity.'), True), | ||
52 | 73 | 'fs//.+': (_('Available space in file system.'), True), | ||
53 | 74 | "swap": (_("Average swap usage"), True) | ||
54 | 75 | |||
55 | 76 | } | ||
56 | 77 | } | ||
57 | 78 | |||
58 | 60 | 79 | ||
59 | 61 | class ISMError(Exception): | 80 | class ISMError(Exception): |
60 | 62 | """General exception.""" | 81 | """General exception.""" |
61 | @@ -72,25 +91,12 @@ | |||
62 | 72 | dialog.run() | 91 | dialog.run() |
63 | 73 | dialog.destroy() | 92 | dialog.destroy() |
64 | 74 | 93 | ||
65 | 75 | supported_sensors = re.compile("mem|cpu|net|bat\d+|fs//.+?") | ||
66 | 76 | settings = { | ||
67 | 77 | 'custom_text': 'cpu: {cpu} mem: {mem}', | ||
68 | 78 | 'interval': 2, | ||
69 | 79 | 'on_startup': False, | ||
70 | 80 | 'sensors': { | ||
71 | 81 | # 'name' => (desc, cmd) | ||
72 | 82 | 'cpu': (_('Average CPU usage'), True), | ||
73 | 83 | 'mem': (_('Physical memory in use.'), True), | ||
74 | 84 | 'net': (_('Network activity.'), True), | ||
75 | 85 | 'bat\d+': (_('Network activity.'), True), | ||
76 | 86 | 'fs//.+': (_('Available space in file system.'), True) | ||
77 | 87 | } | ||
78 | 88 | } | ||
79 | 89 | |||
80 | 90 | 94 | ||
81 | 91 | class Sensor(object): | 95 | class Sensor(object): |
82 | 92 | """Singleton""" | 96 | """Singleton""" |
83 | 93 | _instance = None | 97 | _instance = None |
84 | 98 | bat = re.compile("\Abat\d*\Z") | ||
85 | 99 | cpus = re.compile("\Acpu\d+\Z") | ||
86 | 94 | 100 | ||
87 | 95 | def __init__(self): | 101 | def __init__(self): |
88 | 96 | """It must not be called. Use Sensor.get_instace() | 102 | """It must not be called. Use Sensor.get_instace() |
89 | @@ -101,6 +107,16 @@ | |||
90 | 101 | Sensor._instance = self | 107 | Sensor._instance = self |
91 | 102 | self.update_regex() | 108 | self.update_regex() |
92 | 103 | 109 | ||
93 | 110 | @staticmethod | ||
94 | 111 | def update_regex(names=None): | ||
95 | 112 | if names is None: | ||
96 | 113 | names = settings["sensors"].keys() | ||
97 | 114 | |||
98 | 115 | reg = '|'.join(names) | ||
99 | 116 | reg = "\A({})\Z".format(reg) | ||
100 | 117 | global supported_sensors | ||
101 | 118 | supported_sensors = re.compile("{}".format(reg)) | ||
102 | 119 | |||
103 | 104 | @classmethod | 120 | @classmethod |
104 | 105 | def get_instance(cls): | 121 | def get_instance(cls): |
105 | 106 | """Returns the unique instance of Sensor.""" | 122 | """Returns the unique instance of Sensor.""" |
106 | @@ -114,6 +130,23 @@ | |||
107 | 114 | """Checks if the sensor name exists""" | 130 | """Checks if the sensor name exists""" |
108 | 115 | return bool(supported_sensors.match(name)) | 131 | return bool(supported_sensors.match(name)) |
109 | 116 | 132 | ||
110 | 133 | @staticmethod | ||
111 | 134 | def check(sensor): | ||
112 | 135 | if sensor.startswith("fs//"): | ||
113 | 136 | path = sensor.split("//")[1] | ||
114 | 137 | if not os.path.exists(path): | ||
115 | 138 | raise ISMError(_("Path: {} doesn't exists.").format(path)) | ||
116 | 139 | |||
117 | 140 | elif Sensor.cpus.match(sensor): | ||
118 | 141 | nber = int(sensor[3:]) | ||
119 | 142 | if nber >= ps.NUM_CPUS: | ||
120 | 143 | raise ISMError(_("Invalid number of CPU.")) | ||
121 | 144 | |||
122 | 145 | elif Sensor.bat.match(sensor): | ||
123 | 146 | bat_id = int(sensor[3:]) if len(sensor) > 3 else 0 | ||
124 | 147 | if bat_id >= len(os.listdir("/proc/acpi/battery/")): | ||
125 | 148 | raise ISMError(_("Invalid number of Batterry.")) | ||
126 | 149 | |||
127 | 117 | def add(self, name, desc, cmd): | 150 | def add(self, name, desc, cmd): |
128 | 118 | """Adds a custom sensors.""" | 151 | """Adds a custom sensors.""" |
129 | 119 | if Sensor.exists(name): | 152 | if Sensor.exists(name): |
130 | @@ -122,15 +155,6 @@ | |||
131 | 122 | settings["sensors"][name] = (desc, cmd) | 155 | settings["sensors"][name] = (desc, cmd) |
132 | 123 | self.update_regex() | 156 | self.update_regex() |
133 | 124 | 157 | ||
134 | 125 | @staticmethod | ||
135 | 126 | def update_regex(names=None): | ||
136 | 127 | if names is None: | ||
137 | 128 | names = settings["sensors"].keys() | ||
138 | 129 | |||
139 | 130 | reg = '|'.join(names) | ||
140 | 131 | global supported_sensors | ||
141 | 132 | supported_sensors = re.compile("{}".format(reg)) | ||
142 | 133 | |||
143 | 134 | def delete(self, name): | 158 | def delete(self, name): |
144 | 135 | """Deletes a custom sensors.""" | 159 | """Deletes a custom sensors.""" |
145 | 136 | sensors = settings['sensors'] | 160 | sensors = settings['sensors'] |
146 | @@ -176,7 +200,10 @@ | |||
147 | 176 | self._parent = parent | 200 | self._parent = parent |
148 | 177 | self.last = ps.cpu_times() | 201 | self.last = ps.cpu_times() |
149 | 178 | 202 | ||
151 | 179 | def _fetch_cpu(self): | 203 | def _fetch_cpu(self, percpu=False): |
152 | 204 | if percpu: | ||
153 | 205 | return ps.cpu_percent(interval=0, percpu=True) | ||
154 | 206 | |||
155 | 180 | last = self.last | 207 | last = self.last |
156 | 181 | current = ps.cpu_times() | 208 | current = ps.cpu_times() |
157 | 182 | 209 | ||
158 | @@ -198,30 +225,61 @@ | |||
159 | 198 | else: | 225 | else: |
160 | 199 | return 0 | 226 | return 0 |
161 | 200 | 227 | ||
162 | 228 | def _fetch_swap(self): | ||
163 | 229 | """Return the swap usage in percent""" | ||
164 | 230 | usage = 0 | ||
165 | 231 | total = 0 | ||
166 | 232 | try: | ||
167 | 233 | with open("/proc/swaps") as swaps: | ||
168 | 234 | swaps.readline() | ||
169 | 235 | for line in swaps.readlines(): | ||
170 | 236 | dummy, dummy, total_, usage_, dummy = line.split() | ||
171 | 237 | total += int(total_) | ||
172 | 238 | usage += int(usage_) | ||
173 | 239 | |||
174 | 240 | return usage * 100 / total | ||
175 | 241 | |||
176 | 242 | except IOError: | ||
177 | 243 | return "N/A" | ||
178 | 244 | |||
179 | 201 | def _fetch_mem(self): | 245 | def _fetch_mem(self): |
181 | 202 | """It gets the total memory info and return the used in percentaje.""" | 246 | """It gets the total memory info and return the used in percent.""" |
182 | 203 | with open('/proc/meminfo') as meminfo: | 247 | with open('/proc/meminfo') as meminfo: |
183 | 204 | total = StatusFetcher.digit_regex.findall(meminfo.readline()).pop() | 248 | total = StatusFetcher.digit_regex.findall(meminfo.readline()).pop() |
184 | 205 | free = StatusFetcher.digit_regex.findall(meminfo.readline()).pop() | 249 | free = StatusFetcher.digit_regex.findall(meminfo.readline()).pop() |
185 | 206 | meminfo.readline() | 250 | meminfo.readline() |
187 | 207 | cached = StatusFetcher.digit_regex.findall(meminfo.readline()).pop() | 251 | cached = StatusFetcher.digit_regex.findall( |
188 | 252 | meminfo.readline()).pop() | ||
189 | 208 | free = int(free) + int(cached) | 253 | free = int(free) + int(cached) |
190 | 209 | return 100 - 100 * free / float(total) | 254 | return 100 - 100 * free / float(total) |
191 | 210 | 255 | ||
201 | 211 | def _fetch_bat(self, bat_id): | 256 | def _fetch_bat(self, batid): |
202 | 212 | current_bat = subprocess.Popen( | 257 | """Fetch the the amount of remaining battery""" |
203 | 213 | "grep 'remaining capacity:' /proc/acpi/battery/BAT%s/state |awk '{print $3}' |grep [0-9] || echo 10" % bat_id, | 258 | try: |
204 | 214 | stdout=subprocess.PIPE, shell=True).communicate()[0].strip() | 259 | with open("/proc/acpi/battery/BAT{}/state".format(batid)) as state: |
205 | 215 | #total_bat = subprocess.Popen("cat /proc/acpi/battery/BAT0/info |grep -i 'design capacity:' |awk '{print $3}'", | 260 | while True: |
206 | 216 | total_bat = subprocess.Popen( | 261 | line = state.readline() |
207 | 217 | "grep 'last full capacity:' /proc/acpi/battery/BAT%s/info | awk '{print $4}' |grep [0-9] || echo 65130" % bat_id, | 262 | if "remaining capacity:" in line: |
208 | 218 | stdout=subprocess.PIPE, shell=True).communicate()[0].strip() | 263 | remaining = int(line.split()[2]) |
209 | 219 | return 100 * float(current_bat) / float(total_bat) | 264 | break |
210 | 265 | |||
211 | 266 | with open("/proc/acpi/battery/BAT{}/info".format(batid)) as info: | ||
212 | 267 | while True: | ||
213 | 268 | line = info.readline() | ||
214 | 269 | if "last full capacity" in line: | ||
215 | 270 | capacity = int(line.split()[3]) | ||
216 | 271 | break | ||
217 | 272 | |||
218 | 273 | except IOError: | ||
219 | 274 | return "N/A" | ||
220 | 275 | |||
221 | 276 | return remaining * 100.0 / capacity | ||
222 | 220 | 277 | ||
223 | 221 | def _fetch_net(self): | 278 | def _fetch_net(self): |
224 | 222 | """It use the command "ifstat" to know the total net usage""" | 279 | """It use the command "ifstat" to know the total net usage""" |
225 | 223 | total_net = subprocess.Popen( | 280 | total_net = subprocess.Popen( |
227 | 224 | "ifstat -a -n -q -S -T 0.5 1 | tail -1 | awk '{ printf(\"↓%dkB/s ↑%dkB/s\", $6, $7) }'", | 281 | "ifstat -a -n -q -S -T 0.5 1 | tail -1 | awk \ |
228 | 282 | '{ printf(\"↓%dkB/s ↑%dkB/s\", $6, $7) }'", | ||
229 | 225 | stdout=subprocess.PIPE, shell=True).communicate()[0].strip() | 283 | stdout=subprocess.PIPE, shell=True).communicate()[0].strip() |
230 | 226 | return total_net | 284 | return total_net |
231 | 227 | 285 | ||
232 | @@ -229,29 +287,33 @@ | |||
233 | 229 | """Return a dict whose element are the sensors | 287 | """Return a dict whose element are the sensors |
234 | 230 | and their values""" | 288 | and their values""" |
235 | 231 | res = {} | 289 | res = {} |
237 | 232 | for sensor in Preferences.sensors_regex.findall(settings["custom_text"]): | 290 | cpus = None |
238 | 291 | for sensor in Preferences.sensors_regex.findall( | ||
239 | 292 | settings["custom_text"]): | ||
240 | 233 | sensor = sensor[1:-1] | 293 | sensor = sensor[1:-1] |
241 | 234 | if not Sensor.exists(sensor): | ||
242 | 235 | continue | ||
243 | 236 | if sensor == 'cpu': | 294 | if sensor == 'cpu': |
244 | 237 | res['cpu'] = "{:02.0f}%".format(self._fetch_cpu()) | 295 | res['cpu'] = "{:02.0f}%".format(self._fetch_cpu()) |
245 | 296 | elif Sensor.cpus.match(sensor): | ||
246 | 297 | if cpus is None: | ||
247 | 298 | cpus = self._fetch_cpu(percpu=True) | ||
248 | 299 | res[sensor] = "{:02.0f}%".format(cpus[int(sensor[3:])]) | ||
249 | 300 | |||
250 | 238 | elif sensor == 'mem': | 301 | elif sensor == 'mem': |
251 | 239 | res['mem'] = '{:02.0f}%'.format(self._fetch_mem()) | 302 | res['mem'] = '{:02.0f}%'.format(self._fetch_mem()) |
252 | 240 | elif sensor == 'net': | 303 | elif sensor == 'net': |
253 | 241 | res['net'] = self._fetch_net() | 304 | res['net'] = self._fetch_net() |
254 | 242 | 305 | ||
261 | 243 | elif sensor.startswith('bat'): | 306 | elif Sensor.bat.match(sensor): |
262 | 244 | bat_id = sensor[4:] | 307 | bat_id = int(sensor[3:]) if len(sensor) > 3 else 0 |
257 | 245 | try: | ||
258 | 246 | bat_id = int(bat_id) | ||
259 | 247 | except: | ||
260 | 248 | bat_id = 0 | ||
263 | 249 | res[sensor] = '{:02.0f}%'.format(self._fetch_bat(bat_id)) | 308 | res[sensor] = '{:02.0f}%'.format(self._fetch_bat(bat_id)) |
264 | 250 | 309 | ||
265 | 251 | elif sensor.startswith('fs//'): | 310 | elif sensor.startswith('fs//'): |
266 | 252 | parts = sensor.split('//') | 311 | parts = sensor.split('//') |
267 | 253 | res[sensor] = self._fetch_fs(parts[1]) | 312 | res[sensor] = self._fetch_fs(parts[1]) |
268 | 254 | 313 | ||
269 | 314 | elif sensor == "swap": | ||
270 | 315 | res[sensor] = '{:02.0f}%'.format(self._fetch_swap()) | ||
271 | 316 | |||
272 | 255 | else: # custom sensor | 317 | else: # custom sensor |
273 | 256 | res[sensor] = self._exec(settings["sensors"][sensor][1]) | 318 | res[sensor] = self._exec(settings["sensors"][sensor][1]) |
274 | 257 | 319 | ||
275 | @@ -468,8 +530,8 @@ | |||
276 | 468 | 530 | ||
277 | 469 | class Preferences(gtk.Dialog): | 531 | class Preferences(gtk.Dialog): |
278 | 470 | """It define the the Preferences Dialog and its operations.""" | 532 | """It define the the Preferences Dialog and its operations.""" |
281 | 471 | AUTOSTART_PATH = '{}/.config/autostart/indicator-sysmonitor.desktop'.format( | 533 | AUTOSTART_PATH = '{}/.config/autostart/indicator-sysmonitor.desktop'\ |
282 | 472 | os.getenv("HOME")) | 534 | .format(os.getenv("HOME")) |
283 | 473 | DESKTOP_PATH = '/usr/share/applications/indicator-sysmonitor.desktop' | 535 | DESKTOP_PATH = '/usr/share/applications/indicator-sysmonitor.desktop' |
284 | 474 | sensors_regex = re.compile("{.+?}") | 536 | sensors_regex = re.compile("{.+?}") |
285 | 475 | 537 | ||
286 | @@ -477,16 +539,18 @@ | |||
287 | 477 | """It creates the widget of the dialogs""" | 539 | """It creates the widget of the dialogs""" |
288 | 478 | gtk.Dialog.__init__(self) | 540 | gtk.Dialog.__init__(self) |
289 | 479 | self.ind_parent = parent | 541 | self.ind_parent = parent |
294 | 480 | self.connect('delete-event', self.on_cancel) | 542 | self.custom_entry = None |
295 | 481 | self.set_title(_('Preferences')) | 543 | self.interval_entry = None |
292 | 482 | self.resize(400, 350) | ||
293 | 483 | self.set_position(gtk.WIN_POS_CENTER_ALWAYS) | ||
296 | 484 | self._create_content() | 544 | self._create_content() |
297 | 485 | self.set_data() | 545 | self.set_data() |
298 | 486 | self.show_all() | 546 | self.show_all() |
299 | 487 | 547 | ||
300 | 488 | def _create_content(self): | 548 | def _create_content(self): |
301 | 489 | """It creates the content for this dialog.""" | 549 | """It creates the content for this dialog.""" |
302 | 550 | self.connect('delete-event', self.on_cancel) | ||
303 | 551 | self.set_title(_('Preferences')) | ||
304 | 552 | self.resize(400, 350) | ||
305 | 553 | self.set_position(gtk.WIN_POS_CENTER_ALWAYS) | ||
306 | 490 | notebook = gtk.Notebook() | 554 | notebook = gtk.Notebook() |
307 | 491 | notebook.set_border_width(4) | 555 | notebook.set_border_width(4) |
308 | 492 | 556 | ||
309 | @@ -504,10 +568,10 @@ | |||
310 | 504 | vbox.pack_start(hbox, expand=False, fill=False) | 568 | vbox.pack_start(hbox, expand=False, fill=False) |
311 | 505 | 569 | ||
312 | 506 | hbox = gtk.HBox() | 570 | hbox = gtk.HBox() |
314 | 507 | l = gtk.Label( | 571 | label = gtk.Label( |
315 | 508 | _('This is indicator-sysmonitor version: {}').format(VERSION)) | 572 | _('This is indicator-sysmonitor version: {}').format(VERSION)) |
318 | 509 | l.set_alignment(0.5, 0.5) | 573 | label.set_alignment(0.5, 0.5) |
319 | 510 | hbox.pack_start(l) | 574 | hbox.pack_start(label) |
320 | 511 | vbox.pack_end(hbox) | 575 | vbox.pack_end(hbox) |
321 | 512 | notebook.append_page(vbox, gtk.Label(_('General'))) | 576 | notebook.append_page(vbox, gtk.Label(_('General'))) |
322 | 513 | # }}} | 577 | # }}} |
323 | @@ -587,14 +651,17 @@ | |||
324 | 587 | for sensor in sensors: | 651 | for sensor in sensors: |
325 | 588 | sensor = sensor[1:-1] | 652 | sensor = sensor[1:-1] |
326 | 589 | if not Sensor.exists(sensor): | 653 | if not Sensor.exists(sensor): |
328 | 590 | raise ISMError(_("{} sensor not supported.").format(sensor)) | 654 | raise ISMError(_("{{{}}} sensor not supported."). |
329 | 655 | format(sensor)) | ||
330 | 656 | # Check if the sensor is well-formed | ||
331 | 657 | Sensor.check(sensor) | ||
332 | 591 | 658 | ||
333 | 592 | try: | 659 | try: |
334 | 593 | interval = float(self.interval_entry.get_text()) | 660 | interval = float(self.interval_entry.get_text()) |
335 | 594 | if interval <= 0: | 661 | if interval <= 0: |
336 | 595 | raise ISMError(_("Interval value is not valid.")) | 662 | raise ISMError(_("Interval value is not valid.")) |
337 | 596 | 663 | ||
339 | 597 | except ValueError, ex: | 664 | except ValueError: |
340 | 598 | raise ISMError(_("Interval value is not valid.")) | 665 | raise ISMError(_("Interval value is not valid.")) |
341 | 599 | 666 | ||
342 | 600 | settings["custom_text"] = custom_text | 667 | settings["custom_text"] = custom_text |
343 | @@ -618,8 +685,8 @@ | |||
344 | 618 | try: | 685 | try: |
345 | 619 | shutil.copy(Preferences.DESKTOP_PATH, | 686 | shutil.copy(Preferences.DESKTOP_PATH, |
346 | 620 | Preferences.AUTOSTART_PATH) | 687 | Preferences.AUTOSTART_PATH) |
349 | 621 | except Exception as e: | 688 | except Exception, ex: |
350 | 622 | logging.exception(e) | 689 | logging.exception(ex) |
351 | 623 | 690 | ||
352 | 624 | def get_autostart(self): | 691 | def get_autostart(self): |
353 | 625 | return os.path.exists(Preferences.AUTOSTART_PATH) | 692 | return os.path.exists(Preferences.AUTOSTART_PATH) |
354 | @@ -725,8 +792,8 @@ | |||
355 | 725 | Sensor.update_regex() | 792 | Sensor.update_regex() |
356 | 726 | self.update_indicator_guide() | 793 | self.update_indicator_guide() |
357 | 727 | 794 | ||
360 | 728 | except Exception as e: | 795 | except Exception as ex: |
361 | 729 | logging.exception(e) | 796 | logging.exception(ex) |
362 | 730 | logging.error('Reading settings failed') | 797 | logging.error('Reading settings failed') |
363 | 731 | 798 | ||
364 | 732 | @staticmethod | 799 | @staticmethod |
365 | @@ -737,8 +804,8 @@ | |||
366 | 737 | with open(IndicatorSysmonitor.SETTINGS_FILE, 'w') as f: | 804 | with open(IndicatorSysmonitor.SETTINGS_FILE, 'w') as f: |
367 | 738 | f.write(json.dumps(settings)) | 805 | f.write(json.dumps(settings)) |
368 | 739 | 806 | ||
371 | 740 | except Exception as e: | 807 | except Exception as ex: |
372 | 741 | logging.exception(e) | 808 | logging.exception(ex) |
373 | 742 | logging.error('Writting settings failed') | 809 | logging.error('Writting settings failed') |
374 | 743 | 810 | ||
375 | 744 | # actions raised from menu | 811 | # actions raised from menu |
376 | @@ -789,7 +856,7 @@ | |||
377 | 789 | self._help_dialog = None | 856 | self._help_dialog = None |
378 | 790 | 857 | ||
379 | 791 | 858 | ||
381 | 792 | from optparse import OptionParser | 859 | from optparse import OptionParser # TODO: optparse is deprecated |
382 | 793 | 860 | ||
383 | 794 | if __name__ == "__main__": | 861 | if __name__ == "__main__": |
384 | 795 | parser = OptionParser("usage: %prog [options]", version="%prog " + VERSION) | 862 | parser = OptionParser("usage: %prog [options]", version="%prog " + VERSION) |