How to get from_state?

Suggestions and discussion of future versions
Post Reply
ult.nrg
Member
Member
Posts: 10
Joined: Thu Sep 01, 2016 6:41 am

How to get from_state?

Post by ult.nrg »

I'm trying to check from_state when a torrent is added using the same method as the label plugin. That is, creating a listener:

Code: Select all

component.get("EventManager").register_event_handler("TorrentAddedEvent", self.post_torrent_add)
And then a function with from_state as a param:

Code: Select all

def post_torrent_add(self, torrent_id, from_state):
However, I'm constantly getting the following error message:
eventmanager:59 Event handler TorrentAddedEvent failed in <bound method Core.post_torrent_add of <deluge.plugins.label.core.Core object at 0x04B7D5F0>> with exception post_torrent_add() takes exactly 3 arguments (2 given)
I've actually downloaded the latest label plugin off git, built an .egg [without touching the contents of the files] and replaced the label .egg in the plugins folder, and that breaks it too.

I also tried another method of getting the from_state variable, using the same method as the execute plugin, but I get the same behavior; the from_state variable is never passed.

Is there any foolproof way to get from_state?
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: How to get from_state?

Post by Cas »

Is post_torrent_add a class method or just a function? If the latter then remove self.
ult.nrg
Member
Member
Posts: 10
Joined: Thu Sep 01, 2016 6:41 am

Re: How to get from_state?

Post by ult.nrg »

Thanks for the reply, Cas. My guess is that it's a function, so should probably remove the self. However, as mentioned, I've just copied the code from the Label plugin (which does contain the self).

Essentially what I am working on is extending the execute plugin to have a few more features (ability to call a URL rather than a script, add an optional delay, work with the "Copied" event and make calls based on labels).

I've got it mostly working, except this bit:

Code: Select all

    def execute_commands(self, torrent_id, event, *arg):
        if event == "added" and arg[0]:
            # No futher action as from_state (arg[0]) is True
return
For whatever reason, from_state just isn't passing through to this function call. I inspected arg and it's empty. The torrentID comes through fine.

It has to be something I'm doing because even if I download the execture plugin straight off git and build an .egg, from_state doesn't come through. arg is completely empty, and of course it spits an index out of range error when trying to call arg[0], as arg is empty.

I tried to use the event callback method as per first post, but again, torrentID comes through but from_state doesn't.
Post Reply