From 03d85c730d4bf9f1ce66dab900126500c1c81767 Mon Sep 17 00:00:00 2001 From: Paul Fox Date: Tue, 02 Mar 2010 19:17:12 +0000 Subject: Let power control panel auto-adapt to whether powerd or ohmd is in use. --- diff --git a/extensions/cpsection/power/model.py b/extensions/cpsection/power/model.py index c76035d..c02984a 100644 --- a/extensions/cpsection/power/model.py +++ b/extensions/cpsection/power/model.py @@ -17,20 +17,36 @@ from gettext import gettext as _ import gconf - import dbus +import os +import logging OHM_SERVICE_NAME = 'org.freedesktop.ohm' OHM_SERVICE_PATH = '/org/freedesktop/ohm/Keystore' OHM_SERVICE_IFACE = 'org.freedesktop.ohm.Keystore' +POWERD_FLAG_DIR = '/etc/powerd/flags' +POWERD_INHIBIT_FLAG = '/etc/powerd/flags/inhibit-suspend' + +_logger = logging.getLogger('ControlPanel - Power') + + class ReadError(Exception): def __init__(self, value): self.value = value def __str__(self): return repr(self.value) +def using_powerd(): + # directory exists if powerd running, and it's recent + # enough to be controllable. + return os.access(POWERD_FLAG_DIR, os.W_OK) + def get_automatic_pm(): + if using_powerd(): + return not os.access(POWERD_INHIBIT_FLAG, os.R_OK) + + # ohmd client = gconf.client_get_default() return client.get_bool('/desktop/sugar/power/automatic') @@ -40,6 +56,19 @@ def print_automatic_pm(): def set_automatic_pm(enabled): """Automatic suspends on/off.""" + if using_powerd(): + # powerd + if not os.access(POWERD_INHIBIT_FLAG, os.W_OK): + _logger.debug('File %s is not writeable' % POWERD_INHIBIT_FLAG) + return 0 + if enabled == 'off' or enabled == 0: + fd = open(POWERD_INHIBIT_FLAG, 'w') + fd.close() + else: + os.unlink(POWERD_INHIBIT_FLAG) + return 0 + + # ohmd bus = dbus.SystemBus() proxy = bus.get_object(OHM_SERVICE_NAME, OHM_SERVICE_PATH) keystore = dbus.Interface(proxy, OHM_SERVICE_IFACE) -- cgit v0.9.1