Closed bozhodimitrov closed 4 years ago
The problem with CouchPotato is that it's GPL so can't use code directly from it as the deluge-client is MIT.
It's a big problem and I've written lots of code because a library author decided to go with GPL.
Encapsulating it is a good choice so it's easy to avoid magic.
I modified most of the back-ported code and we are not using the whole library, but just one method. I think that the original author is @alshain (Christian Dale). Maybe we can ask him for permission?
The only thing that really needs to be written from scratch if we ditch the currently sourced code is the auth file discovery.
It is probably easier just to write that from scratch.
Linux config file discovery code: https://github.com/JohnDoee/autotorrent/blob/develop/autotorrent/clients/deluge.py#L62-L78
Parsing code: https://github.com/JohnDoee/autotorrent/blob/develop/autotorrent/clients/deluge.py#L80-L99
Since that's my code it can just be copied with no new attributions.
Appdata for windows: https://stackoverflow.com/questions/13184414/how-can-i-get-the-path-to-the-appdata-directory-in-python - the config file can be found in %APPDATA%\deluge\
Yea, I think that I am using this code already. The problem now is that for some reason the Linux Deluge instance returns Username does not exist
and I think that it is encoding issue.
PS: Doh... this error has to do with the fact that the local deluge instance runs under different user...
Ok, I think that this is it. I am using your code with some slight modifications. Btw, I skipped parsing the daemon port on purpose, because it can be passed to the constructor anyways. Less parsing sounds better to me in this case :)
Let me know if anything else is needed for this PR.
Your parsing code ended up really concise.
One thing I'm a bit unsure about is how to use it correctly in a flow. Lets say I made some script that tries to use LocalDelugeRPCClient
, two things can happen:
How would I use that correctly in a script? It's not immediately obvious to me but I feel like it should be.
If you mean the error handling - It is the same as DelugeRPCClient. It will raise the same errors. I am not adding anything special.
If the _get_local_auth
doesn't find any localclient creds, it will return empty username and password.
And it will call DelugeRPCClient with that empty username and password - at this point, the error handling is in the hands of DelugeRPCClient.
I didn't add any additional error handling, because I wanted to preserve the default behavior of DelugeRPCClient. So if the local Deluge instance is not discovered - it will either raise ConnectionRefusedError (if it can't connect, because of wrong ip/port/firewall restriction) or it will raise exception with msg "Wrong username or password"/"Username does not exist"/etc.
Also keep in mind that this is only for default Deluge installations:
localclient
should exist - this username is the one that the Deluge GTK UI thin client uses itself to connect to its local deluged backend and is generated by default.We can raise an error if the local username and password are not found, but I don't think that it will be a big enhancement. Let me know if you have any idea around that.
Should be good enough, thanks for making it.
Anything else before I create a release ?
Nope, thanks for adding this to the code base - I know that it is a small "feature" and it is not very important, but it really makes it very convenient for home automation purposes and local deployments.
And if you want something else around it, just let me know! Have a nice day and once again, thanks for making this project. 🍻
Encapsulates the logic for automatic login to local Deluge instance into separate LocalDelugeRPCClient class. This will allow easy maintenance/refactoring or removal in the future. Code was back-ported from CouchPotato/CouchPotatoServer/tree/master/libs/synchronousdeluge Made some changes: better error handling and support for Python 3.
What do you think? It is not messing up with the existing code base and can be axed at any point in the future. I can also add documentation in the README and additional test case if you want?