DelugeRPC Help

Suggestions and discussion of future versions
Post Reply
jreid42
New User
New User
Posts: 3
Joined: Tue Sep 29, 2009 1:44 pm

DelugeRPC Help

Post by jreid42 »

I have taken a look on the development page, at twisted defereds, inlineCallbacks etc and I am still utterly lost.

If someone could give me a chunk of code showing me how to do something like this I would be super appreciative:

Code: Select all

class SynchronousDelugeRPC(object):
    def connect(self,host,port,username,password):
       # Connect through client.connect(host,port,username,password) or something like that.

    def start(self,hash);
       # make a synchronous call... or even to a call back 
       # something to I suppose client.core.stop(hash) or something like that.
       # but how am I supposed to get a response.. or a return value from this... even with a callback... im just going to end up returning a deffered arent i?

    def start_callback(self,result)... if you so wished... id prefer to do this without callbacks but I suppose thats unavoidable?
       return result

    def stop(self):
       # make a syncronous call..

    # I think you get the point

Essentially what I want to do is without having the web server running (only deluged) I want to be able to fire somewhat synchronous (or asynchronous requests) at the daemon... I just need to know how to do it correctly in this class like manner.

Any assistance would be super awesome... I have tried for hours to get this working but I am at a loss.

I basically need to be able to do deluge.stop(hash)... deluge.start(hash)... deluge.<other_api_call_here)... and get a response whenever its ready. Just showing me for a basic one is all I need.

Thanks.
jreid42
New User
New User
Posts: 3
Joined: Tue Sep 29, 2009 1:44 pm

Re: DelugeRPC Help

Post by jreid42 »

This seems to be the shortest way possible to do what I was hoping for... if anyone knows an easier way...please let me know.

Code: Select all

def get_config():
	d = _get_config()
	reactor.run()
	return d.result

@defer.inlineCallbacks
def _get_config():
	try:
		connection = yield client.connect()
		configuration = yield client.core.get_config()
		defer.returnValue(configuration)
	except Exception, e:
		print str(e)
	finally:
		reactor.stop()

print get_config()
A synchronous API would rock BTW :D
Post Reply