Merge lp:~lottanzb/lottanzb/inhibit-suspending-plugin into lp:lottanzb/0.5

Proposed by Severin H
Status: Merged
Merged at revision: 937
Proposed branch: lp:~lottanzb/lottanzb/inhibit-suspending-plugin
Merge into: lp:lottanzb/0.5
Diff against target: 322 lines (+283/-1)
4 files modified
NEWS (+8/-0)
README (+4/-0)
lottanzb/plugins/__init__.py (+1/-1)
lottanzb/plugins/inhibit_suspending/__init__.py (+270/-0)
To merge this branch: bzr merge lp:~lottanzb/lottanzb/inhibit-suspending-plugin
Reviewer Review Type Date Requested Status
Severin H Approve
Marcel de Vries (community) Approve
Review via email: mp+17793@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Severin H (severinh) wrote :

While all D-Bus operations seem to be properly done, I haven't actually tested the plug-in yet (by not doing any input for a few minutes while downloading). Also, the plug-in will need to be tested on Ubuntu 9.04 (or similar) as a different (older) power management API is used there.

So this merge proposal is mainly meant to be a call to testers. ;-)

891. By Severin H

Update NEWS.

Revision history for this message
Severin H (severinh) wrote :

I seem to have found a bug in gnome-session, preventing the plug-in from working properly on Ubuntu 9.10 and 10.04: https://bugs.edge.launchpad.net/ubuntu/+source/gnome-session/+bug/510907

There is a work-around, but I'd rather wait until things have been cleared up.

Revision history for this message
Severin H (severinh) wrote :

Looks like this merge is currently blocked. The bug mentioned above has been confirmed and triaged. It looks like it's currently not possible to inhibit suspending on Karmic and Lucid machines. Too bad!

review: Disapprove
892. By Severin H

Prevent the plug-in from being enabled on systems with gnome-power-manager < 2.29.2.

Revision history for this message
Severin H (severinh) wrote :

The bug mentioned above has been fixed upstream. Do you (Sander and Marcel) still think that this plug-in would still be a valuable addition to LottaNZB even though it won't work on Ubuntu 9.10? It works fine on Ubuntu 9.04 and 10.04.

Revision history for this message
Severin H (severinh) :
review: Abstain
893. By Severin H

Add note to NEWS that not all systems are supported by the plug-in.

Revision history for this message
Marcel de Vries (carresmd-deactivatedaccount) wrote :

As you block gnome-power-manager versions below 2.29.2, I couldn't test this as Fedora 12 still uses 2.28.2. However looking at the code, it's fine by me. Once I have set up a Fedora rawhide VM I'll give my definitive review. I'll approve for now, as I'm in a good mood ^^.

review: Approve
Revision history for this message
Severin H (severinh) wrote :

Well, it will most probably not work in the Fedora rawhide VM either, simply because gnome-power-manager 2.29.2 hasn't been released yet. ^^ The fix should be part of the GNOME 2.30 Beta to be released in two days.

What do you think about putting this off to LottaNZB 0.5.4 (if it will be released at all)? I just don't feel comfortable releasing a plug-in that won't work for >75% of our users.

Revision history for this message
Marcel de Vries (carresmd-deactivatedaccount) wrote :

It's probably best to put it off to 0.5.4. If I think about it, I see the bug reports floating in like 'Hey, this plugin isn't working...'.

894. By Severin H

Sync with 0.5.

895. By Severin H

Note about gnome-power-manager version in README.

896. By Severin H

Explicitly mention gnome-power-manager bug ID.

Revision history for this message
Severin H (severinh) wrote :

Now that Ubuntu 10.04 has been released, releasing LottaNZB 0.5.4 with this plug-in seems to be more reasonable. Besides this plug-in, some other minor bugs have been fixed and lots of translations were added and updated.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2010-05-11 14:47:56 +0000
+++ NEWS 2010-05-12 20:51:29 +0000
@@ -1,6 +1,14 @@
1LottaNZB 0.5.4 - Development1LottaNZB 0.5.4 - Development
2============================2============================
33
4- New "Inhibit suspending" plug-in. When enabled, it prevents the computer from
5 being suspended if there hasn't been any input for a certain amount of time,
6 but there are still active LottaNZB downloads. This allows you to keep the
7 computer powered on when you go to bed and let it suspend itself when all
8 downloads are complete.
9 Please note that this plug-in doesn't work on all systems. Most importantly,
10 Ubuntu 9.10 isn't supported, while Ubuntu 9.04 and 10.04 are. The reason for
11 this is bug #510907 in gnome-power-manager 2.28.
4- Fix crash of LottaNZB at startup occuring when HellaNZB uses unrar-free to12- Fix crash of LottaNZB at startup occuring when HellaNZB uses unrar-free to
5 extract downloaded archives. (LP: #577105, thanks to Jim in Chicago for13 extract downloaded archives. (LP: #577105, thanks to Jim in Chicago for
6 reporting this)14 reporting this)
715
=== modified file 'README'
--- README 2010-02-15 21:32:25 +0000
+++ README 2010-05-12 20:51:29 +0000
@@ -48,6 +48,10 @@
4848
49- python-gnome2 (the gnomevfs module)49- python-gnome2 (the gnomevfs module)
5050
51For the 'Inhibit suspending' plug-in:
52
53- gnome-power-manager >= 2.29.2 or gnome-power-manager <= 2.24.4
54
51The package names may vary depending on your distribution.55The package names may vary depending on your distribution.
5256
53Build LottaNZB57Build LottaNZB
5458
=== modified file 'lottanzb/plugins/__init__.py'
--- lottanzb/plugins/__init__.py 2010-01-20 22:46:40 +0000
+++ lottanzb/plugins/__init__.py 2010-05-12 20:51:29 +0000
@@ -150,7 +150,7 @@
150 plug-in cannot be enabled.150 plug-in cannot be enabled.
151 """151 """
152 152
153 if key == "enabled" and value and not self.enabled:153 if key == "enabled" and value:
154 try:154 try:
155 if self.locked:155 if self.locked:
156 # The plug-in is locked and can therefore not be enabled156 # The plug-in is locked and can therefore not be enabled
157157
=== added directory 'lottanzb/plugins/inhibit_suspending'
=== added file 'lottanzb/plugins/inhibit_suspending/__init__.py'
--- lottanzb/plugins/inhibit_suspending/__init__.py 1970-01-01 00:00:00 +0000
+++ lottanzb/plugins/inhibit_suspending/__init__.py 2010-05-12 20:51:29 +0000
@@ -0,0 +1,270 @@
1# Copyright (C) 2008-2010 LottaNZB Development Team
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; version 3.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10# GNU General Public License for more details.
11#
12# You should have received a copy of the GNU General Public License
13# along with this program; if not, write to the Free Software
14# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
15
16import re
17
18import logging
19log = logging.getLogger(__name__)
20
21try:
22 import dbus
23except ImportError:
24 dbus = None
25
26from subprocess import Popen, PIPE
27from distutils.version import StrictVersion
28
29from lottanzb.plugins import PluginBase, PluginEnablingError
30from lottanzb.util import _
31from lottanzb.modes import standalone
32
33class Plugin(PluginBase):
34 title = _("Inhibit suspending")
35 description = _("Prevents the computer from being suspended while "
36 "downloading.")
37 author = _("LottaNZB Development Team")
38 requires_modes = [standalone.Mode]
39
40 def __init__(self, app, config):
41 # Holds an `InhibitionProvider` if it's possible to instantiate one.
42 self._provider = None
43
44 PluginBase.__init__(self, app, config)
45
46 self.connect_when_enabled(self.app.backend, "updated",
47 self.on_backend_updated)
48
49 def import_dependencies(self):
50 """
51 Make sure that the D-Bus module is available on the user's machine.
52
53 Try to set up an `InhibitionProvider` that provides the methods to
54 inhibit or uninhibit suspending.
55 """
56
57 global dbus
58
59 if not dbus:
60 import dbus
61
62 # A provider should only be set up once, but this method may be called
63 # several times.
64 if self._provider is None:
65 self._setup_provider()
66
67 def _setup_provider(self):
68 inhibition_providers_classes = (
69 GnomeSessionInhibitionProvider,
70 HALInhibitionProvider
71 )
72
73 for inhibition_providers_class in inhibition_providers_classes:
74 try:
75 provider = inhibition_providers_class("lottanzb")
76 except InhibitionProviderError, error:
77 # Try the next provider class.
78 pass
79 else:
80 self._provider = provider
81
82 if self._provider is None:
83 # Bad luck.
84 raise PluginEnablingError(self, _("Your desktop environment "
85 "isn't supported by the plug-in."))
86
87 def refresh(self):
88 """
89 Inhibit suspending if the plug-in is enabled and there are active
90 downloads or an active post-processing operation. Allows suspending
91 otherwise.
92 """
93
94 if self._provider is not None:
95 if self.enabled:
96 downloads = self.app.backend.downloads
97 inhibit = bool(downloads.get_processing() \
98 or (downloads.get_active_download() \
99 and not self.app.backend.paused))
100
101 if inhibit:
102 self.inhibit()
103 else:
104 self.uninhibit()
105 else:
106 self.uninhibit()
107
108 def on_backend_updated(self, backend):
109 """
110 Check if suspending needs to be inhibited/uninhibited whenever the
111 download list is updated.
112 """
113
114 self.refresh()
115
116 def inhibit(self):
117 """Try to prevent the computer from being suspended."""
118
119 if not self._provider.is_inhibited():
120 reason = _("Download activity")
121
122 try:
123 self._provider.inhibit(reason)
124 except InhibitionProviderError, error:
125 log.warning(_("Could not disallow suspending: %s") % str(error))
126 else:
127 log.info(_("Disallowing suspending."))
128
129 def uninhibit(self):
130 """Allow the computer to be suspended."""
131
132 if self._provider.is_inhibited():
133 try:
134 self._provider.uninhibit()
135 except InhibitionProviderError, error:
136 log.warning(_("Could not reallow suspending: %s") % \
137 str(error))
138 else:
139 log.info(_("Allowing suspending."))
140
141
142class InhibitionProvider:
143 def __init__(self, application):
144 self.application = application
145
146 def inhibit(self, reason=""):
147 raise NotImplementedError
148
149 def uninhibit(self):
150 raise NotImplementedError
151
152 def is_inhibited(self):
153 raise NotImplementedError
154
155 def tear_down(self):
156 pass
157
158
159class HALInhibitionProvider(InhibitionProvider):
160 def __init__(self, application):
161 InhibitionProvider.__init__(self, application)
162
163 try:
164 session_bus = dbus.SessionBus()
165 interface_name = "org.freedesktop.PowerManagement.Inhibit"
166 proxy = session_bus.get_object(
167 "org.freedesktop.PowerManagement",
168 "/org/freedesktop/PowerManagement/Inhibit"
169 )
170
171 self._interface = dbus.Interface(proxy, interface_name)
172 self._cookie = None
173 except dbus.exceptions.DBusException, error:
174 raise InhibitionProviderError()
175
176 def inhibit(self, reason=""):
177 """Try to prevent the computer from being suspended."""
178
179 try:
180 self._cookie = self._interface.Inhibit(self.application, reason)
181 except dbus.exceptions.DBusException, error:
182 raise InhibitionProviderError(error.message)
183
184 def uninhibit(self):
185 """Allow the computer to be suspended."""
186
187 try:
188 self._interface.UnInhibit(self._cookie)
189 except dbus.exceptions.DBusException, error:
190 raise InhibitionProviderError(error.message)
191 finally:
192 self._cookie = None
193
194 def is_inhibited(self):
195 return bool(self._cookie is not None)
196
197
198class GnomeSessionInhibitionProvider(InhibitionProvider):
199 VERSION_PATTERN = re.compile("\d[\d\.]*")
200
201 # The GNOME Power Manager didn't actually use the SessionManager D-Bus API
202 # to check if there are any suspending inhibitors until version 2.29.2.
203 # Thus, this `InhibitionProvider` will not work on systems like Ubuntu 9.10
204 # that use the GNOME 2.28 or older.
205 # See https://bugzilla.gnome.org/show_bug.cgi?id=607748
206 MIN_GPM_VERSION = StrictVersion("2.29.2")
207
208 def __init__(self, application):
209 InhibitionProvider.__init__(self, application)
210
211 try:
212 process = Popen(["gnome-power-manager", "--version"], stdout=PIPE)
213 process.wait()
214 except OSError, error:
215 raise InhibitionProviderError(str(error))
216 else:
217 match = self.VERSION_PATTERN.search(process.stdout.read())
218
219 # Don't raise an `InhibitionProviderError` if the version output
220 # doesn't have the expected format, so that potential future changes
221 # to the GNOME Power Manager don't erroneously fail the check.
222 if match and StrictVersion(match.group()) < self.MIN_GPM_VERSION:
223 raise InhibitionProviderError()
224
225 try:
226 session_bus = dbus.SessionBus()
227 interface_name = "org.gnome.SessionManager"
228 proxy = session_bus.get_object(
229 "org.gnome.SessionManager",
230 "/org/gnome/SessionManager"
231 )
232
233 self._interface = dbus.Interface(proxy, interface_name)
234 self._client_id = self._interface.RegisterClient(self.application,
235 self.application)
236 self._cookie = None
237 except dbus.exceptions.DBusException, error:
238 raise InhibitionProviderError(error.message)
239
240 def inhibit(self, reason=""):
241 """Try to prevent the computer from being suspended."""
242
243 try:
244 self._cookie = self._interface.Inhibit(self.application, 0, reason,
245 0x4)
246 except dbus.exceptions.DBusException, error:
247 raise InhibitionProviderError(error.message)
248
249 def uninhibit(self):
250 """Allow the computer to be suspended."""
251
252 try:
253 self._interface.Uninhibit(self._cookie)
254 except dbus.exceptions.DBusException, error:
255 raise InhibitionProviderError(error.message)
256 finally:
257 self._cookie = None
258
259 def tear_down(self):
260 try:
261 self._interface.UnregisterClient(self._client_id)
262 except dbus.exceptions.DBusException, error:
263 raise InhibitionProviderError(error.message)
264
265 def is_inhibited(self):
266 return bool(self._cookie is not None)
267
268
269class InhibitionProviderError(Exception):
270 pass

Subscribers

People subscribed via source and target branches

to all changes: