~ubuntu-branches/debian/sid/sugar-toolkit-gtk3/sid

« back to all changes in this revision

Viewing changes to src/sugar3/power.py

  • Committer: Package Import Robot
  • Author(s): Jonas Smedegaard, upstream
  • Date: 2015-07-06 19:53:05 UTC
  • mfrom: (1.2.1) (4.1.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150706195305-q9ety8udfkxw4kxr
Tags: 0.106.0-1
[ upstream ]
New release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
    def __init__(self):
40
40
        self._suspend_inhibit_counter = 0
 
41
        if os.path.exists(_POWERD_INHIBIT_DIR):
 
42
            self._path = os.path.join(_POWERD_INHIBIT_DIR, str(os.getpid()))
 
43
        else:
 
44
            self._path = None
41
45
 
42
46
    def __del__(self):
43
47
        self._remove_flag_file()
46
50
        return True
47
51
 
48
52
    def inhibit_suspend(self):
49
 
        if not os.path.exists(_POWERD_INHIBIT_DIR):
50
 
            return
51
 
 
52
 
        if self._suspend_inhibit_counter == 0:
53
 
            path = os.path.join(_POWERD_INHIBIT_DIR, str(os.getpid()))
 
53
        if self._path and self._suspend_inhibit_counter == 0:
54
54
            try:
55
 
                with open(path, 'w') as flag_file:
 
55
                with open(self._path, 'w') as flag_file:
56
56
                    flag_file.write('')
57
57
            except IOError:
58
58
                logging.error("Inhibit Suspend: Could not create file %s",
59
 
                              path)
 
59
                              self._path)
60
60
 
61
61
        self._suspend_inhibit_counter += 1
62
62
 
77
77
        self._remove_flag_file()
78
78
 
79
79
    def _remove_flag_file(self):
80
 
        path = os.path.join(_POWERD_INHIBIT_DIR, str(os.getpid()))
81
 
        try:
82
 
            os.unlink(path)
83
 
        except OSError:
84
 
            logging.error("Inhibit Suspend: Could not delete file %s", path)
 
80
        if self._path:
 
81
            try:
 
82
                os.unlink(self._path)
 
83
            except OSError:
 
84
                pass
85
85
        self._suspend_inhibit_counter = 0