[Plugin] Autoshutdown - Shutdown PC once torrents complete

Suggest, post, or discuss plugins for Deluge
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

[Plugin] Autoshutdown - Shutdown PC once torrents complete

Post by Cas »

This is the the Autoshutdown plugin and will either shutdown, hibernate or standby your computer once Deluge has finished downloading all torrents.

Autoshutdown Releases

Based upon original work by Ray Chen
mingle
New User
New User
Posts: 7
Joined: Mon Sep 17, 2012 6:50 am

Re: Autoshutdown

Post by mingle »

Hi again,

I've just installed this plugin, but can't see any options to set and it's also not listed under Preferences>Plugins.

The .egg file is in the correct folder and other installed plugins are fine.

I couldn't find any other info about how to configure the plugin

(apologies for my recent number of bozo-questions!)

Cheers,

Mike.
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: [Plugin] Autoshutdown - Shutdown PC once torrents comple

Post by Cas »

mingle
New User
New User
Posts: 7
Joined: Mon Sep 17, 2012 6:50 am

Re: [Plugin] Autoshutdown - Shutdown PC once torrents comple

Post by mingle »

Thanks for your help - I was confused about my Python version!

I have 2.7.3, so just renamed the egg and all is well.

Cheers,

Mike.
mayB
Member
Member
Posts: 18
Joined: Fri Nov 23, 2012 6:57 am

Re: [Plugin] Autoshutdown - Shutdown PC once torrents comple

Post by mayB »

Hello.

AutoShutdown-0.1-py2.6.egg doesn't work in windows 7, at least I finished the download of the only torrent I had in deluge transferes and system didn't turned off.

Please tell me exactly how to configure deluge to shutdown the system after all the active downloads are finished.

I tried this weird wizmo application with a bat file but deluge doesn't have any connection with it.

Please make it clear.

Thanks.
tekkaman

Autoshutdown doesn't work

Post by tekkaman »

Hello everyone

I tried many times but it never even attempts to shut down. Any ideas?
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: [Plugin] Autoshutdown - Shutdown PC once torrents comple

Post by Cas »

I had been working on adding windows code to the plugin but never got around to testing it. The eggs are below for anyone wishing to help test it for me. If you have any issue enable debug logging and look for AutoShutdown messages.

Edit: I was testing on Linux and found several major issues so fixed them and have attached the new version. It is still untested on Windows so some feedback would be helpful.
Attachments
AutoShutdown-1.1-py2.7.egg
(16.28 KiB) Downloaded 4497 times
AutoShutdown-1.1-py2.6.egg
(16.28 KiB) Downloaded 2207 times
smb_au
New User
New User
Posts: 2
Joined: Sun Jun 02, 2013 7:30 pm

Re: [Plugin] Autoshutdown - Shutdown PC once torrents comple

Post by smb_au »

I'm just starting to play with debian and all it entails to build a home nas.

My plan (from what I currently know), would be to have hdparm set the disks to spin down after 20 minutes of inactivity, and then to have a cron job check to see if both (non OS disks) have spun down, and then poweroff the nas. When I want media served, or to access the disks/deluge, I'll send a magic packet to wake it. I'm going this route as on average I may not touch it from day to day, so want something that will be "off" for as long as possible.

Having looked at a few torrent clients, Deluge seems a perfect fit, now all I need is to manage to shut it down once all downloads have completed, rather than shut the system down as I may be using it for other things.

I've had a go at modifying the plugin itself - with some success (got it to compile, and log) - but don't know python, and so have rather crudely put

Code: Select all

component.get("Core").shutdown
just below

Code: Select all

log.info("[AutoShutDown] Suspending...")
just for testing purposes, but it's not doing anything, nor generating any errrors.

Any help with this - or my general "power management" strategy - would be much appreciated, as all of this is new to me.

Thanks
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: [Plugin] Autoshutdown - Shutdown PC once torrents comple

Post by Cas »

It's a method so requires brackets:

Code: Select all

component.get("Core").shutdown()
smb_au
New User
New User
Posts: 2
Joined: Sun Jun 02, 2013 7:30 pm

Re: [Plugin] Autoshutdown - Shutdown PC once torrents comple

Post by smb_au »

As much as I would have loved that to have been down to my complete stupidity (I thought the compilation would have picked that up), it's still not working, and I'm wondering whether I need to do any housekeeping before calling shutdown?

I've only changed the core.py file - mainly to simplify it so I know what's going on (it hasn't helped):

Code: Select all

from deluge.log import LOG as log
from deluge.plugins.pluginbase import CorePluginBase
import deluge.component as component
import deluge.configmanager
from deluge.core.rpcserver import export
from deluge.common import windows_check, osx_check

DEFAULT_PREFS = {
    "enabled"           : True,
    "system_state"      : None,
    "can_hibernate"     : False,
    "can_suspend"       : False
}

class Core(CorePluginBase):
    def enable(self):
        log.debug("[AutoShutDown] Enabling plugin...")

        self.config = deluge.configmanager.ConfigManager("autoshutdown.conf", DEFAULT_PREFS)
        self.check_suspend_hibernate_flags()

        component.get("EventManager").register_event_handler("TorrentFinishedEvent", self.on_event_torrent_finished)


    def disable(self):
        log.debug("[AutoShutDown] Disabling plugin...")
        component.get("EventManager").deregister_event_handler(self.on_event_torrent_finished)
        self.config.save()

    def on_event_torrent_finished(self, torrent_id):
        log.debug("[AutoShutDown] Torrent finished event for %s", torrent_id)
        # calc how many of torrent right now
        downloading_torrents = component.get("Core").get_torrents_status({"state": "Downloading"}, ["name"])
        # core status might not be updated so ensure finished torrent is removed
        downloading_torrents.pop(torrent_id, None)
        log.info("[AutoShutDown] Total torrents waiting to complete: %s", len(downloading_torrents))
        log.debug("[AutoShutDown] Waiting list: %s", downloading_torrents)
        if not downloading_torrents:
            self.power_action()

    def power_action(self):
        if not self.config["enabled"]:
            log.debug("[AutoShutDown] Disabled, nothing to do")
            return
        if self.config["system_state"] == 'shutdown':
            self.os_shutdown()
        elif self.config["system_state"] == 'hibernate':
            self.os_hibernate()
        elif self.config["system_state"] == 'suspend':
            self.os_suspend()

    def os_suspend(self):
            log.info("[AutoShutDown] Suspending...")
            component.get("Core").shutdown()

    def os_hibernate(self):
            log.info("[AutoShutDown] Hibernating...")
            component.get("Core").shutdown()

    def os_shutdown(self):
            log.info("[AutoShutDown] Shutting down...")
            log.info("[AutoShutDown] Closing Core...")
            component.get("Core").shutdown()

    def check_suspend_hibernate_flags(self):
        self.config["can_hibernate"] = False
        self.config["can_suspend"] = False
        self.config.save()

    def update(self):
        pass

    @export
    def set_config(self, config):
        "sets the config dictionary"
        for key in config.keys():
            self.config[key] = config[key]
        self.config.save()

    @export
    def get_config(self):
        "returns the config dictionary"
        return self.config.config
and the logging gives me no idea as to what's happended, it appears to just ignore it

Code: Select all

[DEBUG   ] 19:56:25 alertmanager:123 torrent_finished_alert: LibreOffice_4.0.3_Win_x86.msi torrent finished downloading
[DEBUG   ] 19:56:25 alertmanager:123 state_changed_alert: LibreOffice_4.0.3_Win_x86.msi: state changed to: finished
[DEBUG   ] 19:56:25 alertmanager:123 state_changed_alert: LibreOffice_4.0.3_Win_x86.msi: state changed to: seeding
[DEBUG   ] 19:56:25 alertmanager:123 tracker_announce_alert: LibreOffice_4.0.3_Win_x86.msi (http://tracker.documentfoundation.org:6969/announce) sending announce (completed)
[DEBUG   ] 19:56:25 torrentmanager:855 on_alert_torrent_finished
[DEBUG   ] 19:56:25 torrentmanager:861 39a2eb68ca81744a82ba5071855d7360c0076853 is finished..
[DEBUG   ] 19:56:25 rpcserver:466 intevents: {1: ['NewVersionAvailableEvent', 'PluginEnabledEvent', 'TorrentResumedEvent', 'TorrentAddedEvent', 'TorrentRemovedEvent', 'PluginDisabledEvent', 'SessionResumedEvent', 'TorrentQueueChangedEvent', 'TorrentFileRenamedEvent', 'TorrentFolderRenamedEvent', 'TorrentStateChangedEvent', 'TorrentFinishedEvent', 'ConfigValueChangedEvent', 'SessionPausedEvent']}
[DEBUG   ] 19:56:25 rpcserver:470 Emit Event: TorrentFinishedEvent ['39a2eb68ca81744a82ba5071855d7360c0076853']
[DEBUG   ] 19:56:25 core:32 [AutoShutDown] Torrent finished event for 39a2eb68ca81744a82ba5071855d7360c0076853
[INFO    ] 19:56:25 core:37 [AutoShutDown] Total torrents waiting to complete: 0
[DEBUG   ] 19:56:25 core:38 [AutoShutDown] Waiting list: {}
[INFO    ] 19:56:25 core:62 [AutoShutDown] Shutting down...
[INFO    ] 19:56:25 core:63 [AutoShutDown] Closing Core...
[DEBUG   ] 19:56:25 torrent:379 set_state_based_on_ltstate: Seeding
[DEBUG   ] 19:56:25 torrent:380 session.is_paused: False
[DEBUG   ] 19:56:25 torrentmanager:999 on_alert_state_changed
[DEBUG   ] 19:56:25 torrent:379 set_state_based_on_ltstate: Seeding
[DEBUG   ] 19:56:25 torrent:380 session.is_paused: False
[DEBUG   ] 19:56:25 torrentmanager:999 on_alert_state_changed
[DEBUG   ] 19:56:25 torrent:379 set_state_based_on_ltstate: Seeding
[DEBUG   ] 19:56:25 torrent:380 session.is_paused: False
[DEBUG   ] 19:56:25 torrentmanager:946 on_alert_tracker_announce
[DEBUG   ] 19:56:25 alertmanager:123 save_resume_data_alert: LibreOffice_4.0.3_Win_x86.msi resume data generated
[DEBUG   ] 19:56:25 torrentmanager:1013 on_alert_save_resume_data
[DEBUG   ] 19:56:25 torrentmanager:718 Opening torrents fastresume file for load.
Apologies if I'm missing something obvious, I'm only dipping my toe in here, but I had hoped I'd be seeing some errors to correct me along the way.

Thanks again
Post Reply