shutdown, hibernate and suspend a linux system

Want something added? Ask for it here.
carresmd
Release Testers
Release Testers
Posts: 10
Joined: September 25th, 2009, 11:14 am

shutdown, hibernate and suspend a linux system

Post by carresmd »

I have written some code that enables the shutdown, hibernate and suspend functions for linux when the download queue has finished. I would like to see this included in 0.5 as we are basing LottaNZB 0.6 on SABnzbd 0.5 :D.

It basically uses DBus and HAL (to support older distributions) and ConsoleKit/DeviceKit-power (to support newer distributions), I think the code is pretty much self explanatory.

Thanks
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: shutdown, hibernate and suspend a linux system

Post by shypike »

Thanks, quite interesting.
My Linux knowledge is quite superficial, hence the question:
This is portable over the different distributions and will not cause problems when not supported by the platform?

I think we can include it in release 0.5.0.
carresmd
Release Testers
Release Testers
Posts: 10
Joined: September 25th, 2009, 11:14 am

Re: shutdown, hibernate and suspend a linux system

Post by carresmd »

shypike wrote: Thanks, quite interesting.
My Linux knowledge is quite superficial, hence the question:
This is portable over the different distributions and will not cause problems when not supported by the platform?

I think we can include it in release 0.5.0.
It will work on probably 99% of the systems running a graphical environment. This code is targeted at desktop system because it would be kind of pointless to shutdown, hibernate or suspend a server via SABnzbd. If the platform doesn't support these things the code will handle it.

For example the shutdown code;
It will try to shutdown using HAL, if that isn't supported it will try ConsoleKit and if that isn't supported it will just shutdown SABnzbd itself.

Code: Select all

try:
    import dbus
except ImportError:
    pass
else:
    try:
        name = 'org.freedesktop.PowerManagement'
        path = '/org/freedesktop/PowerManagement'
        interface = 'org.freedesktop.PowerManagement'
        bus = dbus.SessionBus()
        proxy = bus.get_object(name, path)
    except dbus.exceptions.DBusException:
        try:
            name = 'org.freedesktop.ConsoleKit'
            path = '/org/freedesktop/ConsoleKit/Manager'
            interface = 'org.freedesktop.ConsoleKit.Manager'
            bus = dbus.SystemBus()
            proxy = bus.get_object(name, path)
        except dbus.exceptions.DBusException:
            pass
        else:
            if proxy.CanStop(dbus_interface=interface):
                proxy.Stop(dbus_interface=interface)
    else:
        if proxy.CanShutdown():
            proxy.Shutdown(dbus_interface=interface)
finally:
    os._exit(0)
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: shutdown, hibernate and suspend a linux system

Post by shypike »

Thanks for your explanation.
carresmd
Release Testers
Release Testers
Posts: 10
Joined: September 25th, 2009, 11:14 am

Re: shutdown, hibernate and suspend a linux system

Post by carresmd »

Hi shypike, any news regarding my patch? ::)
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: shutdown, hibernate and suspend a linux system

Post by shypike »

carresmd wrote: Hi shypike, any news regarding my patch? ::)
It will be included, but current the development pace of SABnzbd is quite low.
carresmd
Release Testers
Release Testers
Posts: 10
Joined: September 25th, 2009, 11:14 am

Re: shutdown, hibernate and suspend a linux system

Post by carresmd »

shypike wrote: It will be included, but current the development pace of SABnzbd is quite low.
Great to hear that! Not so much about the development pace though, but that's just how stuff goes.
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: shutdown, hibernate and suspend a linux system

Post by shypike »

It will take some rewriting, because your code isn't compatible with Python 2.4.
(Due to the try/except/else).

I'm skipping it for Alpha6.
carresmd
Release Testers
Release Testers
Posts: 10
Joined: September 25th, 2009, 11:14 am

Re: shutdown, hibernate and suspend a linux system

Post by carresmd »

Oops, didn't think about backwards compatibility at all.
Well I'm just pretty new to this Python stuff (maybe 2 months now) so don't know the features in previous version and what not.
Anyway, if you think you're short on free-time or interest to rewrite this, I'm happy to rewrite it myself.
Let me know :)
Last edited by carresmd on October 2nd, 2009, 1:44 pm, edited 1 time in total.
carresmd
Release Testers
Release Testers
Posts: 10
Joined: September 25th, 2009, 11:14 am

Re: shutdown, hibernate and suspend a linux system

Post by carresmd »

I have modified my patch to be backwards compatible with Python 2.4.
It's a very small edit though. 2 lines removed and 3 lines added.
Last edited by carresmd on October 2nd, 2009, 1:44 pm, edited 1 time in total.
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: shutdown, hibernate and suspend a linux system

Post by shypike »

Great, thank you. But it wasn't just the compatibility.
I just want some time to test a bit more and 0.5.0Alpha6 is going out this weekend.
It will be in 0.5.0 any way.
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: shutdown, hibernate and suspend a linux system

Post by shypike »

It has been implemented for release 0.5.0 under Ticket #329.
Thanks for your assistence!
carresmd
Release Testers
Release Testers
Posts: 10
Joined: September 25th, 2009, 11:14 am

Re: shutdown, hibernate and suspend a linux system

Post by carresmd »

Thank you for implementing it! Looking forward to the 0.5(.0) release! :D

If it is not too much of a hassle, I'd like to be 'credited' with my full name, 'Marcel de Vries', and perhaps my email, 'marceldevries__AT__phannet.cc' (replace '__AT__' with '@'). As I only use my nickname to login and generally use my full name for everything else. Not required though, just a kind request. (I'm doing my best not to sound rude) ::)

Thanks again!
Last edited by carresmd on October 16th, 2009, 5:21 pm, edited 1 time in total.
User avatar
shypike
Administrator
Administrator
Posts: 19773
Joined: January 18th, 2008, 12:49 pm

Re: shutdown, hibernate and suspend a linux system

Post by shypike »

I'll add your credit line to the source code (end of misc.py).
It's not exactly like you wrote it,  I chose to reshuffle it quite a bit.
I can add you to the list of Release Testers, that will give you access to pre-built binaries.
(Although currently we have none with your code in it).
carresmd
Release Testers
Release Testers
Posts: 10
Joined: September 25th, 2009, 11:14 am

Re: shutdown, hibernate and suspend a linux system

Post by carresmd »

Yeah, already saw the code changes you made. Looking good! ;)

You can add me to the Release Testers if you want to. I generally run the trunk code, but I'm happy to test release(s) (candidates)! Especially the 0.5(.0) release, as we depend on it. :D
Post Reply