diff options
author | Sayamindu Dasgupta <sayamindu@gmail.com> | 2010-03-02 19:38:54 (GMT) |
---|---|---|
committer | Sayamindu Dasgupta <sayamindu@gmail.com> | 2010-03-02 19:38:54 (GMT) |
commit | 5bb0bc3b511104c3b40c27819c8900fb9881eca4 (patch) | |
tree | 3286b43fc6d8a905e6f4fa53321aa5dc1fcf357a /extensions | |
parent | 03d85c730d4bf9f1ce66dab900126500c1c81767 (diff) |
Us a try: block instead of checking if the file is writeable or not
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/cpsection/power/model.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/extensions/cpsection/power/model.py b/extensions/cpsection/power/model.py index c02984a..33ec905 100644 --- a/extensions/cpsection/power/model.py +++ b/extensions/cpsection/power/model.py @@ -58,12 +58,13 @@ def set_automatic_pm(enabled): 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() + try: + fd = open(POWERD_INHIBIT_FLAG, 'w') + except IOError: + _logger.debug('File %s is not writeable' % POWERD_INHIBIT_FLAG) + else: + fd.close() else: os.unlink(POWERD_INHIBIT_FLAG) return 0 |