diff --git a/extensions/cpsection/power/model.py b/extensions/cpsection/power/model.py
index c76035d..33ec905 100644
a
|
b
|
|
17 | 17 | |
18 | 18 | from gettext import gettext as _ |
19 | 19 | import gconf |
20 | | |
21 | 20 | import dbus |
| 21 | import os |
| 22 | import logging |
22 | 23 | |
23 | 24 | OHM_SERVICE_NAME = 'org.freedesktop.ohm' |
24 | 25 | OHM_SERVICE_PATH = '/org/freedesktop/ohm/Keystore' |
25 | 26 | OHM_SERVICE_IFACE = 'org.freedesktop.ohm.Keystore' |
26 | 27 | |
| 28 | POWERD_FLAG_DIR = '/etc/powerd/flags' |
| 29 | POWERD_INHIBIT_FLAG = '/etc/powerd/flags/inhibit-suspend' |
| 30 | |
| 31 | _logger = logging.getLogger('ControlPanel - Power') |
| 32 | |
| 33 | |
27 | 34 | class ReadError(Exception): |
28 | 35 | def __init__(self, value): |
29 | 36 | self.value = value |
30 | 37 | def __str__(self): |
31 | 38 | return repr(self.value) |
32 | 39 | |
| 40 | def using_powerd(): |
| 41 | # directory exists if powerd running, and it's recent |
| 42 | # enough to be controllable. |
| 43 | return os.access(POWERD_FLAG_DIR, os.W_OK) |
| 44 | |
33 | 45 | def get_automatic_pm(): |
| 46 | if using_powerd(): |
| 47 | return not os.access(POWERD_INHIBIT_FLAG, os.R_OK) |
| 48 | |
| 49 | # ohmd |
34 | 50 | client = gconf.client_get_default() |
35 | 51 | return client.get_bool('/desktop/sugar/power/automatic') |
36 | 52 | |
… |
… |
def print_automatic_pm(): |
40 | 56 | def set_automatic_pm(enabled): |
41 | 57 | """Automatic suspends on/off.""" |
42 | 58 | |
| 59 | if using_powerd(): |
| 60 | # powerd |
| 61 | if enabled == 'off' or enabled == 0: |
| 62 | try: |
| 63 | fd = open(POWERD_INHIBIT_FLAG, 'w') |
| 64 | except IOError: |
| 65 | _logger.debug('File %s is not writeable' % POWERD_INHIBIT_FLAG) |
| 66 | else: |
| 67 | fd.close() |
| 68 | else: |
| 69 | os.unlink(POWERD_INHIBIT_FLAG) |
| 70 | return 0 |
| 71 | |
| 72 | # ohmd |
43 | 73 | bus = dbus.SystemBus() |
44 | 74 | proxy = bus.get_object(OHM_SERVICE_NAME, OHM_SERVICE_PATH) |
45 | 75 | keystore = dbus.Interface(proxy, OHM_SERVICE_IFACE) |