Sessions¶
A session represent a connection on a remote or local machine.
BaseSession¶
-
class
rcontrol.core.
BaseSession
(auto_close=True)[source]¶ Represent an abstraction of a session on a remote or local machine.
-
copy_dir
(*args, **kwargs)¶ Asynchronous version of
s_copy_dir()
.This method returns an instance of a
ThreadableTask
.Note that you can use the on_done keyword argument to define a callback that will be called at the end of the execution (see the
Task
constructor).
-
copy_file
(*args, **kwargs)¶ Asynchronous version of
s_copy_file()
.This method returns an instance of a
ThreadableTask
.Note that you can use the on_done keyword argument to define a callback that will be called at the end of the execution (see the
Task
constructor).
-
execute
(command, **kwargs)[source]¶ Execute a command in an asynchronous way.
Return an instance of a subclass of a
CommandTask
.Parameters: - command – the command to execute (a string)
- kwargs – named arguments passed to the constructor of the class:CommandTask subclass.
-
open
(filename, mode='r', bufsize=-1)[source]¶ Return an opened file object.
Parameters: - filename – the file path to open
- mode – the mode used to open the file
- bufsize – buffer size
-
s_copy_dir
(src, dest_session, dest, chunk_size=16384)[source]¶ Recursively copy a directory from a session to another one.
dest must not exist, it will be created automatically.
Parameters: - src – path of the dir to copy in this session
- dest_session – session to copy to
- dest – path of the dir to copy in the dest session (must not exists)
-
s_copy_file
(src, dest_os, dest, chunk_size=16384)[source]¶ Copy a file from this session to another session.
Parameters: - src – full path of the file to copy in this session
- dest_os – session to copy to
- dest – full path of the file to copy in the dest session
-
wait_for_tasks
(raise_if_error=True)[source]¶ Wait for the running tasks launched from this session.
If any errors are encountered, they are raised or returned depending on raise_if_error. Note that this contains errors reported from silently finished tasks (tasks ran and finished in backround without explicit wait call on them).
Tasks started from another task callback (like on_finished) are also waited here.
This is not required to call this method explictly if you use the
BaseSession
or theSessionManager
with the with keyword.Parameters: raise_if_error – If True, errors are raised using TaskErrors
. Else the errors are returned as a list.
-
SshSession¶
LocalSession¶
SessionManager¶
-
class
rcontrol.core.
SessionManager
(*args, **kwds)[source]¶ A specialized OrderedDict that keep sessions instances.
It can be used like a namespace:
sess_manager.local = LocalSession() # equivalent to: # sess_manager['local'] = LocalSession()
It should be used inside a with block, to wait for pending tasks and close sessions if needed automatically.
-
wait_for_tasks
(raise_if_error=True)[source]¶ Wait for the running tasks lauched from the sessions.
Note that it also wait for tasks that are started from other tasks callbacks, like on_finished.
Parameters: raise_if_error – if True, raise all possible encountered errors using TaskErrors
. Else the errors are returned as a list.
-