From: Alfredo Deza Date: Fri, 4 Oct 2013 17:01:22 +0000 (-0400) Subject: update the docs X-Git-Tag: 0.0.4~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bc23c0dc8af955cb3fbe40b90fb14a2690ea91b4;p=remoto.git update the docs --- diff --git a/README.rst b/README.rst index d51f969..2bba175 100644 --- a/README.rst +++ b/README.rst @@ -76,3 +76,44 @@ characters removed. This is useful if you need to process the information back locally, as opposed to just firing and forgetting (while logging, like ``process.run``). + + +Remote Functions +================ + +To execute remote functions (ideally) you would need to define them in a module +and add the following to the end of that module:: + + if __name__ == '__channelexec__': + for item in channel: + channel.send(eval(item)) + + +If you had a function in a module named ``foo`` that looks like this:: + + import os + + def listdir(path): + return os.listdir(path) + +To be able to execute that ``listdir`` function remotely you would need to pass +the module to the connection object and then call that function:: + + >>> import foo + >>> conn = Connection('hostname') + >>> remote_foo = conn.import_module(foo) + >>> remote_foo.listdir('.') + ['.bash_logout', + '.profile', + '.veewee_version', + '.lesshst', + 'python', + '.vbox_version', + 'ceph', + '.cache', + '.ssh'] + +Note that functions to be executed remotely **cannot** accept objects as +arguments, just normal Python data structures, like tuples, lists and +dictionaries. Also safe to use are ints and strings. +