4. pypsi.shell - Pypsi Shell

class pypsi.shell.Shell(shell_name='pypsi', width=79, exit_rc=-1024, ctx=None, features=None)[source]

Bases: object

The command line interface that the user interacts with. All shell’s need to inherit this base class.

Subclasses need to call the Shell constructor to properly initialize it.

Parameters:
  • shell_name (str) – the name of the shell; used in error messages
  • exit_rc (int) – the exit return code that is returned from a command when the shell needs to end execution
  • ctx (pypsi.namespace.Namespace) – the base context
cmdloop()[source]

Begin the input processing loop where the user will be prompted for input.

create_pipe_threads(pipe)[source]

Given a pipe (list of CommandInvocation objects) create a thread to execute for each invocation.

Returns tuple:a tuple containing the list of threads (CommandThread) and the last invocation’s stdout stream.
execute(raw)[source]

Parse and execute a statement.

Parameters:
  • raw (str) – the raw command line to parse.
  • input (function) – a function that returns a string, overrides default input function (stdin).
Returns int:

the return code of the statement.

include(file)[source]

Read commands from a file and execute them line by line

Parameters:file (file) – File object to read commands from
Return int:0 if error free; 1 if an error occurred
on_cmdloop_begin()[source]

Hook that is called once the cmdloop() function is called.

on_cmdloop_end()[source]

Hook that is called once the cmdloop() has ended.

on_shell_ready()[source]

Hook that is called after the shell has been created.

register(obj)[source]

Register a Command or a Plugin.

register_base_plugins()[source]

Register all base plugins that are defined.