Add sphinx API documentation

This commit is contained in:
Kristóf Tóth
2018-06-01 16:20:20 +02:00
parent c0fb28c46c
commit e80cce00f3
16 changed files with 381 additions and 36 deletions

View File

@ -74,10 +74,10 @@ class BashMonitor(HistoryMonitor):
HistoryMonitor for monitoring bash CLI sessions.
This requires the following to be set in bash
(note that this is done automatically by TFW):
PROMPT_COMMAND="history -a"
shopt -s cmdhist
shopt -s histappend
unset HISTCONTROL
PROMPT_COMMAND="history -a"
shopt -s cmdhist
shopt -s histappend
unset HISTCONTROL
"""
@property
def command_pattern(self):

View File

@ -101,9 +101,10 @@ class IdeEventHandler(EventHandlerBase, MonitorManagerMixin):
When any file in the selected directory changes they are automatically refreshed
on the frontend (this is done by listening to inotify events).
This EventHandler accepts messages that have a data["command"] key specifying
This EventHandler accepts messages that have a data['command'] key specifying
a command to be executed.
The API of each command is documented in their respective handlers.
The API of each command is documented in their respective handler.
"""
def __init__(self, key, directory, allowed_directories, selected_file=None, exclude=None,
additional_watched_directories=None):
@ -112,7 +113,7 @@ class IdeEventHandler(EventHandlerBase, MonitorManagerMixin):
:param directory: working directory which the EventHandler should serve files from
:param allowed_directories: list of directories that can be switched to using the selectdir command
:param selected_file: file that is selected by default
:param exclude: list of filenames that should not appear between files (for *.o, *.pyc, etc.)
:param exclude: list of filenames that should not appear between files (for .o, .pyc, etc.)
:param additional_watched_directories: refresh the selected file when files change in these directories
(the working directory is watched by default, this is useful for
symlinks and such)
@ -139,7 +140,7 @@ class IdeEventHandler(EventHandlerBase, MonitorManagerMixin):
"""
Read the currently selected file.
:return: message with the contents of the file in data['content']
:return dict: message with the contents of the file in data['content']
"""
try:
data['content'] = self.filemanager.file_contents
@ -155,8 +156,9 @@ class IdeEventHandler(EventHandlerBase, MonitorManagerMixin):
"""
Overwrites a file with the desired string.
:param data: TFW message data containing keys:
|-string: containing the desired file contents
:param data: TFW message data containing key 'content'
(new file content)
"""
self.monitor.ignore = self.monitor.ignore + 1
try:
@ -170,8 +172,8 @@ class IdeEventHandler(EventHandlerBase, MonitorManagerMixin):
"""
Selects a file from the current directory.
:param data: TFW message data containing keys:
|-filename: name of file to select relative to the current directory
:param data: TFW message data containing 'filename'
(name of file to select relative to the current directory)
"""
try:
self.filemanager.filename = data['filename']
@ -183,10 +185,10 @@ class IdeEventHandler(EventHandlerBase, MonitorManagerMixin):
"""
Select a new working directory to display files from.
:param data: TFW message data containing keys:
|-directory: absolute path of diretory to select.
must be a path whitelisted in
self.allowed_directories
:param data: TFW message data containing 'directory'
(absolute path of diretory to select.
must be a path whitelisted in
self.allowed_directories)
"""
try:
self.filemanager.workdir = data['directory']
@ -204,8 +206,9 @@ class IdeEventHandler(EventHandlerBase, MonitorManagerMixin):
"""
Overwrite list of excluded files
:param data: TFW message data containing keys:
|-exclude: list of filename patterns to be excluded, e.g.: ["*.pyc", "*.o"]
:param data: TFW message data containing 'exclude'
(list of unix-style filename patterns to be excluded,
e.g.: ["\*.pyc", "\*.o")
"""
try:
self.filemanager.exclude = list(data['exclude'])

View File

@ -14,7 +14,10 @@ class LogMonitoringEventHandler(EventHandlerBase, MonitorManagerMixin):
Monitors the output of a supervisor process (stdout, stderr) and
sends the results to the frontend.
Exposes API to change monitoring parameters.
Accepts messages that have a data['command'] key specifying
a command to be executed.
The API of each command is documented in their respective handler.
"""
def __init__(self, key, process_name, log_tail=0):
super().__init__(key)
@ -39,8 +42,8 @@ class LogMonitoringEventHandler(EventHandlerBase, MonitorManagerMixin):
"""
Changes the monitored process.
:param data: TFW message data containing keys:
|-value: name of the process to monitor
:param data: TFW message data containing 'value'
(name of the process to monitor)
"""
self.set_monitor_args(data['value'], self.log_tail)
@ -50,8 +53,8 @@ class LogMonitoringEventHandler(EventHandlerBase, MonitorManagerMixin):
to the frontend (the monitor will send back the last
'value' characters of the log).
:param data: TFW message data containing keys:
|-value: new tail length
:param data: TFW message data containing 'value'
(new tail length)
"""
self.set_monitor_args(self.process_name, data['value'])

View File

@ -25,9 +25,9 @@ class ProcessManagingEventHandler(EventHandlerBase):
"""
Event handler that can manage processes managed by supervisor.
This EventHandler accepts messages that have a data["command"] key specifying
This EventHandler accepts messages that have a data['command'] key specifying
a command to be executed.
Every message must contain a data["process_name"] field with the name of the
Every message must contain a data['process_name'] field with the name of the
process to manage. This is the name specified in supervisor config files like so:
[program:someprogram]

View File

@ -19,13 +19,13 @@ class TerminalCommands(ABC):
To receive events you need to subscribe TerminalCommand.callback to a HistoryMonitor
instance.
Inherit from this class and define methods which start with "command_". When the user
Inherit from this class and define methods which start with "command\_". When the user
executes the command specified after the underscore, your method will be invoked. All
such commands must expect the parameter *args which will contain the arguments of the
such commands must expect the parameter \*args which will contain the arguments of the
command.
For example to define a method that runs when someone starts vim in the terminal
you have to define a method like: "def command_vim(self, *args)"
you have to define a method like: "def command_vim(self, \*args)"
You can also use this class to create new commands similarly.
"""

View File

@ -16,9 +16,9 @@ class TerminalEventHandler(EventHandlerBase):
sessions to connect to. You need to instanciate this in order for frontend
terminals to work.
This EventHandler accepts messages that have a data["command"] key specifying
This EventHandler accepts messages that have a data['command'] key specifying
a command to be executed.
The API of each command is documented in their respective handlers.
The API of each command is documented in their respective handler.
"""
def __init__(self, key, monitor):
"""
@ -54,8 +54,8 @@ class TerminalEventHandler(EventHandlerBase):
Writes a string to the terminal session (on the pty level).
Useful for pre-typing and executing commands for the user.
:param data: TFW message data containing keys:
|-value: command to be written to the pty
:param data: TFW message data containing 'value'
(command to be written to the pty)
"""
self.terminado_server.pty.write(data['value'])
@ -63,9 +63,9 @@ class TerminalEventHandler(EventHandlerBase):
"""
Reads the history of commands executed.
:param data: TFW message data containing keys:
|-count: the number of history elements to return
:return: message with list of commands in data['history']
:param data: TFW message data containing 'count'
(the number of history elements to return)
:return dict: message with list of commands in data['history']
"""
data['count'] = int(data.get('count', 1))
if self.historymonitor: