Plugins and deluge.ui.client API.

Suggestions and discussion of future versions
Post Reply
mhertz
Moderator
Moderator
Posts: 2195
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Plugins and deluge.ui.client API.

Post by mhertz »

I would appreciate if someone in the know could please kindly help me little with this, thanks alot in advance.

In the docs it's stated that plugins can use deluge.ui.client API through coreclient wrapper, however that wrapper(coreclient.py) has been removed so cannot be utilized anymore.

When making a python client script, instead of plugin, then I can comunicate with daemon through deluge.ui.client fine, but I cannot from plugin, obviously, as docs state, but was wondering why removed wrapper and what's the alternative.

My main thing is that I want to utilize client.daemon.shutdown(), to close daemon, which I can only do in client script and not plugin, as errors out with no call atribute from nonetype object. Other simple api-calls I tested from that, like client.daemon.get_version() through a twisted addCallback, also doesn't work from plugin, only in my script, as previous issue(tested since was thinking maybe only daemon.shutdown() being problematic and the ui.client limitation possibly lifted since wrapper removed, hence the further tests).

Is there something else I can do? Sorry in advance for beeing a complete noob in this :) I have messed with this on and off for months actually, trying alternative variations of component.get.xxxx etc calls(mainly 'component.get("Core").shutdown()' where docs states also stops daemon, erronyously, as not even works from client script neither), but cannot see how can call daemon's shutdown() command there, and also tried importing deluge.core.daemon and calling it's shutdown() still without luck(Then realized it's from a Daemon() class therein, so then tried importing the Daemon class from it, instatiate it and call it's shutdown() funtion, or _shutdown() one, or it's content direct instead i.e. component.stop or reactor.stop etc etc, no luck with anything though), so thought I finally would ask for help here. Thanks alot again in advance.

I searched the git commit log for the commit that removed the coreclient.py wrapper, for an explenation maybe, or alternative, but the commit only deletes the file and adds example plugin and various seemingly irrelevant other stuff. This is the commit message, and the removal part, strangely replaced with entirely unrelated file, but probaby just the way git/diff works i'm sure:

Code: Select all

martin@arch ~/Downloads/deluge
 % git log --full-history -1 -- deluge/plugins/coreclient.py
commit 703e9def05584bef55f822e00ad471a586a530e8
Author: Andrew Resch <andrewresch@gmail.com>
Date:   Mon Feb 23 23:54:06 2009 +0000

    Change some plugin stuff and add an example plugin

Code: Select all

martin@arch ~/Downloads/deluge
 % git show 703e9
[...]
diff --git a/deluge/plugins/coreclient.py b/deluge/plugins/example/example/webui.py
similarity index 61%
rename from deluge/plugins/coreclient.py
rename to deluge/plugins/example/example/webui.py
index d39778098..c75ce8858 100644
--- a/deluge/plugins/coreclient.py
+++ b/deluge/plugins/example/example/webui.py
@@ -1,7 +1,7 @@
 #
-# coreclient.py
+# webui.py
 #
-# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
+# Copyright (C) 2009 Martijn Voncken <mvoncken@gmail.com>
 #
 # Deluge is free software.
 #
@@ -23,19 +23,13 @@
 #
 
 
+from deluge.log import LOG as log
+from deluge.ui.client import client
+from deluge import component
 
-import deluge.component as component
-
-class CoreClient(object):
-    """
-    provides the uiclient interface to core plugins
-    see http://dev.deluge-torrent.org/wiki/Development/UiClient
-    """
-    def __init__(self):
-        self.core = component.get("Core")
-
-    def __getattr__(self, func_name):
-        return self.core.funcs[func_name]
-
-client = CoreClient()
+class WebUI(WebPluginBase):
+    def enable(self):
+        log.debug("Example Web plugin enabled!")
 
+    def disable(self):
+        log.debug("Example Web plugin disabled!")
[...]
I even added the coreclient.py wrapper back in-place manually, and called it as referenced in docs, but then error out about no attribute funcs in core object, though not surpricingly since so freakin old codebase it was from.

(Autoshutdown plugin from Cas don't feature close daemon functionality, which I else of-course would have used for inspiration, and an unmerged pull-request submitted, was using the GTKUI api for it, well 'MainWindow', whereas I wanna have it working from thinclient without UIs running.)
mhertz
Moderator
Moderator
Posts: 2195
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: Plugins and deluge.ui.client API.

Post by mhertz »

If others interested in how shutdown daemon from plugin, where deluge.ui.client API not available(client.daemon.shutdown()), then I finally had luck with doing what the unavailable client.daemon.shutdown() internally was doing in deluge.core.Daemon().shutdown() and deluge.core.Daemon._shutdown() i.e.:

Code: Select all

component.shutdown()
reactor.stop()
I run above in a reactor.callLater() with slight break, but haven't tested yet if needed or not, but just in case. No '*args,**kwargs' needed from calling function for this, which some stuff specifically needs I previously found, but not this. Actually it works without the first command, and only second that is the needed one, but as both is run(first is from a twisted event trigger), then might as well I thought, and possibly also needed for gracefully saving session/state or something i'm thinking.

Btw, I before that, managed to import deluge.core.Daemon() class but could not use any functions of it, because stated daemon already running, and adding new port would obviously not help as just would start new instance which wasen't my intention - so Daemon() class seemingly is only meant for starting a new daemon instance and operating on it, and not as interface for already running one. I did warn being noob afterall ;) Actually I believe first time utilizing classes where actually worked lol :) Not for intended purposse though however, but still, a win for me regardless :)

Anyway, still would love feedback of why the deluge.ui.client core API wrapper was revoked, and if there's any alternative for issuing RPC calls to daemon easilly from plugins, like is done with client scripts. Else would love example of manual RPC call sending, as have little hard with understanding the RPC api, e.g. is it sendData() or maybe dispatch() ??? and what extra initialization needed, as i'm completely lost regarding "methods", "objects", "request-ids" and whatnot else - I actually tried import 3'rd party 'deluge-client' module from github/pypi instead, which supports sending RPC calls for you to daemon, and I can utilize that from deluge client script fine, but don't work from plugins neither, though also a longshot admittedly(because of project-name referencing 'client', and includes calls I see to deluge.ui.client itself), and I don't see what need for it in client scripts when we already have deluge.ui.client() working perfectly fine and easilly already.

Last, unrelated, but was wondering is it even possible to connect to internal deluge daemon from a client script when deluge running in classic/standalone mode and not thinclient mode, or is that not even possible - couldn't see how from API, but evidently that doesn't mean much afterall lol :) I was thinking if running e.g. a client script from execute plugin upon torrent completion for varius post-processing, which works fine currently through initial client.connect(), but when deluge not in thinclient mode, then what then? Besides using plugin instead of-course. I always use thinclient myself, but still curious though.

Thanks a bunch in advance.
mhertz
Moderator
Moderator
Posts: 2195
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: Plugins and deluge.ui.client API.

Post by mhertz »

... Just for anybody possibly finding this from a google search, then just wanted to add that yes you can use the client UI api from core plugins now(as in the UI-less part of plugins i.e. core.py), hence the removed coreclient.py wrapper of old times, and I was just to noobish to make it work previously(still is, just very slightly less ;) ), e.g. just use propper twisted callbacks and some stuff specifically needs '*args, **kwargs' to make said callback happen cleanly in backend.

Edit: Sorry correction, apparently it only works in non-thinclient mode(standalone/classic), which probably was why I couldn't make it work previously where tested it in thinclient mode, damn thought I had become an elite haxor all of a sudden lmfao :lol: - I also knew about the callbacks and *args, **kwargs thing back then from what I remembered(and from rereading the thread), so couldn't really understand it, but just thought did a mistake then, but apparently not. Anyway, If I can find out how overcome it, then i'll update here.

Edit2: Ok you can use deluge.ui.client from core plugin also in thinclient mode, using same way as if using a client script, so just need connecting to daemon from inside core plugin i.e. calling client.connect() in twisted callback in core.py and then e.g. could run client.daemon.shutdown() etc. but anyway, little stupid to connect to already connected daemon so preferably run the code directly like here reactor.stop() and component.stop() etc.
Post Reply