Now I'm certainly in new territory in the Python space - most of my programming experience has been with Java.
That being said, I can't seem to find a clear definition of what is required for creating a Deluge 2 plugin. I found the instructions that discuss how to convert a version 1 plugin to a version 2, which seemed only to address the UI requirements but nothing else.
I don't want to make a plugin that uses the UI ...
When I installed Deluge 2 on an Ubuntu VM, I followed the instructions https://dev.deluge-torrent.org/wiki/Dev ... 1.3/Plugin and the instructions work in version 2 ... where you use the script to create the folder structure and files for you - then you edit core.py then run the script that compiles the plugin into an egg ... pretty straight forward, except two things:
1) The structure of the plugins is identical to version 1 - which seems suspicious
2) The resulting plugin will not work on Deluge 2. When I install the egg file, the Settings in the UI acts like I gave it nothing and nothing shows up in the .config folder either.
So I searched for documentation that might be specific for Deluge 2 in terms of what exactly is required but I have found nothing and as you can even see in the link I provided above, it has 1.3 in the URL ... where's the 2.x version of that same page?
I am compiling the egg file with Python version 3.6.15 and I tried 3.8.18
If someone just wanted to know the base requirement for making a plugin for Deluge 2 - where they had no prior knowledge about making plugins for Deluge at all ... what resource should they be looking at to understand how to do it?
Thank you,
Mike
Writing plugins for Deluge 2
Re: Writing plugins for Deluge 2
You can open any of the plugins as a zip file (rename to zip or open with something like 7zip or winrar) and see all the python files that make that up.
Would be easiest to just see examples of plugins similar to what you require.
Would be easiest to just see examples of plugins similar to what you require.
Re: Writing plugins for Deluge 2
I'm not at my computer now, but yeah the structure between v1 and v2 is alike. Yes easiest is run create_plugin.py or however called to create files and boiler-plate. That guide to v2 plugins are great but in beginning I had a hard time updating v1 plugins still, because so many changes needing be done, only a few normally for python2 to python3 but more for deluge2 internals and all the gtk2 to gtk3 stuff and glade to gtk builder and whatnot. Transferring the ui glade files to ui gtkbuilder is usually not that hard with the command line tool listed in the Cas link, just need figure out what package it is in on your distro etc, and sometimes it hickups on a line which need to be looked at yourself. Easiest after reading that Cas link was to look at a github project in there commit for a release updated for v2, and compare all the stuff done, I think I often looked at bdutro's updated labelplus for example. Last, it normally doesn't matter what python3 you build with, but just in case rename the py-x.x part away from filename if using deluge under 2.0.4, well do regardless as an issue with a certain python call breaking the workaround introduced for this which I cannot remember on top of head. Anyway, copy plugin into plugins sub-dir of profile manually and enable it in deluge and check terminal or log for errors. If remember right, the default boilerplate adds a pane in gtkui, with a empty setting, and nothing in webui as a bug with that, but honestly in doubt if remember that right.
Please ask a specific question regarding something and I'll, or others, will gladly help you![Smile :)](./images/smilies/icon_e_smile.gif)
Edit: Apologies I reread your post which only skimmed originally, and see you're not about updating plugin, only making original, so much of info is superfluous, sorry about that.
Please ask a specific question regarding something and I'll, or others, will gladly help you
![Smile :)](./images/smilies/icon_e_smile.gif)
Edit: Apologies I reread your post which only skimmed originally, and see you're not about updating plugin, only making original, so much of info is superfluous, sorry about that.
-
- New User
- Posts: 8
- Joined: Sat Feb 10, 2024 5:52 am
Re: Writing plugins for Deluge 2
No worries on that, I understood some of what you said ... lol ...
What I really liked about the document that I linked in my first post here is that it was probably 80% clear as to the details of what to do to make a plugin. And the scripts that you use - creates the folder structure and the CODE that works properly in the various files etc. And you are correct, there is no working webui code in the template plugin structure.
So to cut this short and get to the point ... I only need to make this core.py work in Deluge 2...
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
import os
import re
DEFAULT_CONFIG = {
"createfolder": True
}
class Core(CorePluginBase):
def enable(self):
self.config = deluge.configmanager.ConfigManager('solofolder.conf', DEFAULT_CONFIG)
core = component.get("Core")
self.torrent_manager = component.get("TorrentManager")
self.torrents = core.torrentmanager.torrents
self.event_manager = component.get("EventManager");
self.event_manager.register_event_handler("TorrentAddedEvent", self.torrent_added)
def disable(self):
self.event_manager.deregister_event_handler("TorrentAddedEvent", self.torrent_added)
def torrent_added(self, torrent_id):
if not (self.config['createfolder']):
log.debug('createfolder is false, not creating new folder')
return
torrent = self.torrents[torrent_id]
torrent.pause()
status_keys = ["files", "save_path", "name"]
status = torrent.get_status(status_keys)
if self.config['createfolder'] and not re.match('.*/.*', status["files"][0]["path"]):
newFolderPath = os.path.splitext(status["name"])[0] + "/" + status["files"][0]["path"]
torrent.rename_files([[0, newFolderPath]])
torrent.force_recheck()
log.info('created new folder: ' + newFolderPath)
torrent.resume()
def update(self):
pass
@export
def set_config(self, config):
"""Sets the config dictionary"""
for key in config:
self.config[key] = config[key]
self.config.save()
@export
def get_config(self):
"""Returns the config dictionary"""
return self.config.config
-
- New User
- Posts: 8
- Joined: Sat Feb 10, 2024 5:52 am
Re: Writing plugins for Deluge 2
Yeah, I figured out that egg files are renamed zip files on accident by accidentally double-clicking on one and it opened up in my default compression program ... so I did look at other working plugins and tried all kinds of different things to get Deluge 2 to accept the plugin but ... no luck. There's hardly any difference between a 1 plugin and a 2 plugin for MY specific needs. My plugin is simple because it doesn't use the UI at all.
-
- New User
- Posts: 8
- Joined: Sat Feb 10, 2024 5:52 am
Re: Writing plugins for Deluge 2
Well, I got it working by doing what you said ... just copy the egg file into the plugin folder and restart deluged and the web UI ... then I enabled it and its working fine (though its not the same code I posted above, I changed some things for compatibility with Python 2 nd 3)
Thanks for the tip
Re: Writing plugins for Deluge 2
Good job and much welcome ![Smile :)](./images/smilies/icon_e_smile.gif)
Yeah if using the create_plugin.py from deluge v2.x code-base, then indeed just need edit core.py and rebuild for getting a core plugin(actually a core plugin have only few diffs between v1 and v2 in hindsight, deluge API wise), well probably better to remove the gtkui preferences pane with a "test" useless setting added by default, but no biggie. I always add debug-prints for debugging to look at in terminal, or to logging if preferred, to not work in blind so to speak, and delete afterwards.
The create_plugin.py script also enables the plugin directly for you I forgot say before, for easier development, so to not confuse matters when testing before releasing, then delete the link file added to plugins sub-dir in deluge config, which points to your source files in original place.
There's an issue with installing plugins from webui, where plugin installed with faulty name as object_list or alike, in plugins subdir, but believe not an issue in gtkui, but just in case I always suggest "install" plugin manually because of that to people. I have reported the issue though, with a suggested code-fix to use, or get inspiration from atleast.
I will check later, or one of these days, if that is the issue, and if not, what else is, if can, and post back to you if something needing fixing. Also, let me know if want me to help you with adding gtk and webui support for your config-setting. Personally I feel waste of time adding such abstractions(when config-file support already there, but alot people like such(plus a GUI program nonetheless, for majority users), so hence just throwing out there.
Anyway, thanks for contribution again buddy.
Edit: Sorry, didn't thought through that a single config-file option makes zero sense to add support for, anywhere imho, as can just disable/enable plugin as you stated initially yourself i.e why would anyone enable a plugin and disable its main functionality(instead of just disabling plugin again), so just correcting my little stupid suggestion there![Smile :)](./images/smilies/icon_e_smile.gif)
![Smile :)](./images/smilies/icon_e_smile.gif)
Yeah if using the create_plugin.py from deluge v2.x code-base, then indeed just need edit core.py and rebuild for getting a core plugin(actually a core plugin have only few diffs between v1 and v2 in hindsight, deluge API wise), well probably better to remove the gtkui preferences pane with a "test" useless setting added by default, but no biggie. I always add debug-prints for debugging to look at in terminal, or to logging if preferred, to not work in blind so to speak, and delete afterwards.
The create_plugin.py script also enables the plugin directly for you I forgot say before, for easier development, so to not confuse matters when testing before releasing, then delete the link file added to plugins sub-dir in deluge config, which points to your source files in original place.
There's an issue with installing plugins from webui, where plugin installed with faulty name as object_list or alike, in plugins subdir, but believe not an issue in gtkui, but just in case I always suggest "install" plugin manually because of that to people. I have reported the issue though, with a suggested code-fix to use, or get inspiration from atleast.
I will check later, or one of these days, if that is the issue, and if not, what else is, if can, and post back to you if something needing fixing. Also, let me know if want me to help you with adding gtk and webui support for your config-setting. Personally I feel waste of time adding such abstractions(when config-file support already there, but alot people like such(plus a GUI program nonetheless, for majority users), so hence just throwing out there.
Anyway, thanks for contribution again buddy.
Edit: Sorry, didn't thought through that a single config-file option makes zero sense to add support for, anywhere imho, as can just disable/enable plugin as you stated initially yourself i.e why would anyone enable a plugin and disable its main functionality(instead of just disabling plugin again), so just correcting my little stupid suggestion there
![Smile :)](./images/smilies/icon_e_smile.gif)
-
- New User
- Posts: 8
- Joined: Sat Feb 10, 2024 5:52 am
Re: Writing plugins for Deluge 2
Interestingly, I could not get debugging to show me anything with this plugin. When I ran deluged with debugging enabled, it first and foremost gave a bunch of noise in the terminal, but then when the log statements would hit in the plugin where I was logging to debug errorlevel, those never showed up anywhere ... and I don't know what that was all about but the plugin is simple enough to where it either works or it doesn't because it only does one thing, so in this case, seeing debug statements doesn't really do much for me.
I found that you can basically make the folder structure whatever you want as long as they are declared accurately in SOURCES.txt then it will compile just fine.mhertz wrote: ↑Mon Feb 12, 2024 12:21 pm The create_plugin.py script also enables the plugin directly for you I forgot say before, for easier development, so to not confuse matters when testing before releasing, then delete the link file added to plugins sub-dir in deluge config, which points to your source files in original place.
YES, this is what I saw too ... it would show up as [object_list] in brackets even within the plugin folder. Sounds like a bug to me... someone should write a pull request for thatmhertz wrote: ↑Mon Feb 12, 2024 12:21 pm There's an issue with installing plugins from webui, where plugin installed with faulty name as object_list or alike, in plugins subdir, but believe not an issue in gtkui, but just in case I always suggest "install" plugin manually because of that to people. I have reported the issue though, with a suggested code-fix to use, or get inspiration from at least.
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
Yes, a GUI setting page makes no sense for my plugin since literally enabling it or disabling toggles the binary state of the plugin ... it either makes sub-folders for single file torrents ... or it doesn't ... no need to for that extra code for a settings page which would only mimic the behavior of disabling or enabling it.mhertz wrote: ↑Mon Feb 12, 2024 12:21 pm Edit: Sorry, didn't thought through that a single config-file option makes zero sense to add support for, anywhere imho, as can just disable/enable plugin as you stated initially yourself i.e why would anyone enable a plugin and disable its main functionality(instead of just disabling plugin again), so just correcting my little stupid suggestion there![]()
In terms of making the effort to write such code when a config file is sufficient ... we all know that end users don't consider much about the efforts and time invested in these things ... they wanna see it look pretty and they wanna touch it with their mouse because its less work for them ... and so it will go on for ages as such ...
Thanks again!
Mike
![Laughing :lol:](./images/smilies/icon_lol.gif)
![Razz :P](./images/smilies/icon_razz.gif)
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)