FriendlyShell Documentation

Similar documents
Review of Fundamentals

Today. Review. Unix as an OS case study Intro to Shell Scripting. What is an Operating System? What are its goals? How do we evaluate it?

Introduction to Python Documentation

OstrichLib Documentation

Parsing CSCI-400. Principles of Programming Languages.

argcomplete Documentation

Cross-platform daemonization tools.

Contents: 1 Basic socket interfaces 3. 2 Servers 7. 3 Launching and Controlling Processes 9. 4 Daemonizing Command Line Programs 11

maya-cmds-help Documentation

Using Scala for building DSL s

TH IRD EDITION. Python Cookbook. David Beazley and Brian K. Jones. O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Tokyo

argcomplete Documentation Andrey Kislyuk

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

django-embed-video Documentation

f5-icontrol-rest Documentation

my $full_path = can_run('wget') or warn 'wget is not installed!';

CST Algonquin College 2

delegator Documentation

PyDREAM Documentation

Kaiso Documentation. Release 0.1-dev. onefinestay

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

prompt Documentation Release Stefan Fischer

redis-lua Documentation

Recommonmark Documentation

Getting Started Values, Expressions, and Statements CS GMU

IP address. Subnetting. Ping command in detail. Threads in Python. Sub process in Python

SQLAlchemy-ORM-tree Documentation

django-embed-video Documentation

htmlmin Documentation

Project 1: Implementing a Shell

django-embed-video Documentation

petfinder-api Documentation

ffmpy3 Documentation Release Eric Ahn

bzz Documentation Release Rafael Floriano and Bernardo Heynemann

Packtools Documentation

PrettyPandas Documentation

bottle-rest Release 0.5.0

Python Decorators. Chris Calloway

streamio Documentation

In the case of the dynamic array, the space must be deallocated when the program is finished with it. free(x);

PySpec Documentation. Release Zac Stewart

Creating Workflows. What is Prime Network Workflow? CHAPTER

requests-cache Documentation

helper Documentation Release Gavin M. Roy

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?

Tagalog Documentation

pylatexenc Documentation

Lab 2: Implementing a Shell COMPSCI 310: Introduction to Operating Systems

PyZabbixObj Documentation

Archan. Release 2.0.1

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

StratumGS Documentation

lina Documentation Release Author

Python Utils Documentation

YouTube API Wrapper Documentation

dql Release gadaccee-dirty

pyprika Documentation

Fasteners Documentation

sanction Documentation

Nginx Config Builder. Release

NAME SYNOPSIS DESCRIPTION. Behavior of other Perl features in forked pseudo-processes. Perl version documentation - perlfork

Title. Syntax. stata.com. tokengetall(t) tokenget(t) tokenpeek(t) tokenrest(t) tokenoffset(t) tokenoffset(t, real scalar offset)

Python Utils Documentation

Lecture 4. Defining Functions

Shell and Utility Commands

mayatools Documentation

Commodity Documentation

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Kernel Gateway Documentation

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Not-So-Mini-Lecture 6. Modules & Scripts

cursesmenu Documentation

Release Ralph Offinger

Python STL. Release dev

Flask restful swagger Documentation

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

CSE 390a Lecture 2. Exploring Shell Commands, Streams, and Redirection

FIQL Parser. Release 0.15

Should you know scanf and printf?

Python Finite State Machine. Release 0.1.5

CS 1110, LAB 2: ASSIGNMENTS AND STRINGS

Shell and Utility Commands

lala Documentation Release 0.5.dev103+gfd01df0 Wieland Hoffmann

B.V. Patel Institute of BMC & IT, UTU 2014

django-redis-cache Documentation

PYTHON TRAINING COURSE CONTENT

Lecture 8: Structs & File I/O

String Computation Program

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

10. I/O System Library

Although this code is under construction the interfaces are unlikely to change, if only because we use it in production.

The Most Dangerous Software Errors

COP4342 UNIX Tools Assignment #3: A Simple Unix Shell. Instructor: Dr. Robert Van Engelen Teaching Assistant: Imran Chowdhury Spring 2018

discord.py Documentation

lime Documentation Release 0.1 Marco Tulio Ribeiro

Redwood.log( Hello World! );

Dogeon Documentation. Release Lin Ju

dh-virtualenv Documentation

$Id: asg4-shell-tree.mm,v :36: $

NAME SYNOPSIS DESCRIPTION. Behavior of other Perl features in forked pseudo-processes. Perl version documentation - perlfork

Transcription:

FriendlyShell Documentation Release 0.0.0.dev0 Kevin S. Phillips Nov 15, 2018

Contents: 1 friendlyshell 3 1.1 friendlyshell package........................................... 3 2 Overview 9 3 Indices and tables 11 Python Module Index 13 i

ii

Contents: 1

2 Contents:

CHAPTER 1 friendlyshell 1.1 friendlyshell package 1.1.1 Submodules friendlyshell.base_shell module Common shell interaction logic shared between different shells class friendlyshell.base_shell.baseshell(*args, **kwargs) Bases: object Common base class for all Friendly Shells Defines basic IO and interactive shell logic common to all Friendly Shells static alias_native_shell() Gets the shorthand character for the native_shell command Return type str static debug(message, *args, **_kwargs) Displays an internal-use-only debug message to verbose log file Default implementation hides all debug output. Use a logging mixin class to customize this behavior. See friendlyshell.basic_logger_mixin.basicloggermixin for examples. Parameters message (str) text to be displayed do_close() Terminates the currently running shell do_exit() Terminates the command interpreter do_native_shell(cmd) Executes a shell command within the Friendly Shell environment 3

static error(message, *args, **_kwargs) Displays a critical error message to the default output stream Default implementation just directs output to stdout. Use a logging mixin class to customize this behavior. See friendlyshell.basic_logger_mixin.basicloggermixin for examples. Parameters message (str) text to be displayed static help_close() Extended help for close method static info(message, *args, **_kwargs) Displays an info message to the default output stream Default implementation just directs output to stdout. Use a logging mixin class to customize this behavior. See friendlyshell.basic_logger_mixin.basicloggermixin for examples. Parameters message (str) text to be displayed return_code error / return code generated by operations run by this shell Return type int run(*_args, **kwargs) Main entry point function that launches our command line interpreter This method will wait for input to be given via the command line, and process each command provided until a request to terminate the shell is given. Parameters input_stream optional Python input stream object where commands should be loaded from. Typically this will be a file-like object containing commands to be run, but any input stream object should work. If not provided, input will be read from stdin using input() parent Optional parent shell which owns this shell. If none provided this shell is assumed to be a parent or first level shell session with no ancestry run_subshell(subshell) Launches a child process for another shell under this one Parameters subshell the new Friendly Shell to be launched static warning(message, *args, **_kwargs) Displays a non-critical warning message to the default output stream Default implementation just directs output to stdout. Use a logging mixin class to customize this behavior. See friendlyshell.basic_logger_mixin.basicloggermixin for examples. param str message text to be displayed friendlyshell.basic_logger_mixin module Mixin for displaying output from a friendly shell class friendlyshell.basic_logger_mixin.basicloggermixin(*args, **kwargs) Bases: object Mixin class, to be combined with a Friendly Shell, to direct log output to a default output stream 4 Chapter 1. friendlyshell

The assumption here is that all Friendly Shell derived classes are going to use the print(), warning() and error() methods on this class to interact with the shell, and those methods in turn will use the Python logging API to delegate output to. By default those methods should direct their output to stdout, however if a user has s need to redriect the output elsewhere - like, when running a shell in a non-interactive or headless environment - then they can easily do so by simply re-configuring the default logger for the library Helpful links relating to logging https://docs.python.org/2/library/logging.html#logrecord-attributes html#logging-levels debug(message, *args, **kwargs) Displays an internal-use-only debug message to verbose log file Parameters message (str) text to be displayed error(message, *args, **kwargs) Displays a critical error message to the default output stream Parameters message (str) text to be displayed info(message, *args, **kwargs) Displays an info message to the default output stream Parameters message (str) text to be displayed warning(message, *args, **kwargs) Displays a non-critical warning message to the default output stream Parameters message (str) text to be displayed https://docs.python.org/2/library/logging. friendlyshell.basic_shell module friendlyshell.command_complete_mixin module Mixin class that adds command completion to a friendly shell class friendlyshell.command_complete_mixin.commandcompletemixin(*args, **kwargs) Bases: object Mixin to be added to any friendly shell to add command completion do_clear_history() Clears the history of previously used commands from this shell friendlyshell.command_complete_mixin.auto_complete_manager(*args, **kwds) Context manager for enabling command line auto-completion This context manager can be used to ensure that command completion for a Friendly Shell runner can have it s own self-defined auto-completion and command history while not affecting the global completion sub-system that may already be configured prior to running the Friendly Shell. Through the use of a context manager, we ensure the state of the command completion subsystem will be restored regardless of how the context manager was terminated. Parameters key (str) descriptor for keyboard key to use for auto completion trigger callback method point for the callback to run when completion key is pressed history_file (str) optional path to the history file to use for storing previous commands run by this shell. If not provided, history will not be saved. 1.1. friendlyshell package 5

friendlyshell.command_parsers module Pre-defined command line parsers supported by Friendly Shell APIs All Friendly Shell command lines are expected to begin with a command name, followed by 0 or more input parameters as shown below: <command_token>[<parameter_tokens>] The command portion of each line must map command names to Python class methods that are prefixed with the characters do_ (ie: do_exit() ). Because of this commands must meet the same naming restrictions as Python class methods. Thus most Friendly Shells line parsers will want to leverage the meth default_command_parser function to parse the first token of their command lines. Also, for convenience all command token parsers are expected to return a named token with the label command associated with it. The optional list of parameter tokens may satisfy whatever restrictions are desired by a particular command. Since they need not be mapped to Python class methods they do not need to be bound by the same naming rules as the command token. Finally, the list of input parameters - when provided - are expected to return a named token with the label params, which will define a list of 1 or more input parameters to be provided to the command. Below you will find some helper functions that provide pre-built grammars for some common command and parameter token styles so users of the library need not always write their own. friendlyshell.command_parsers.default_command_token() token parser that satisfies the requirements of the FShell interpreter Meets the default naming requirements of the Friendly Shell interpreter, ensuring that command names may be safely mapped to Python class methods. The resulting token will be labelled command as required by the Friendly Shell APIs. Return type pyparsing.parser friendlyshell.command_parsers.default_line_parser() Gets the default command line parser used by the Friendly Shell APIs Return type pyparsing.parser friendlyshell.command_parsers.quoted_space_sep_params_token() Gets a token parser that supports This parser expects all commands to take the following form: <command_name>[ <optional_param2>... ]<eol> <optional_param1> The <command_name> maps to a method of this class or a descendent of it with the same name but with a prefix of do_. As a result tokens for commands must adhere to the same restrictions as a typical Python class method. Commands may optionally accept parameters if desired. Parameters are provided on the same line as the command and are separated by spaces. Each parameter may use any printable character since they are translated to Python strings during translation and thus need not be restricted to the same criteria as commands. Also, if a parameter needs to contain embedded spaces then it must be wrapped in quotation marks. Single or double quotes will work. Further, if you need to embed quotation marks within your string simply wrap the inner quotes with outer quotes of the opposite style. The command token can be accessed by named attribute command, and the list of any parameters provided on the line can be acessed by the named attribute params. TODO: Add support for escaping quote characters when embedded in strings delimited with the same quote style, as in hello world Return type pyparsing.parser 6 Chapter 1. friendlyshell

friendlyshell.shell_help_mixin module 1.1.2 Module contents Package initialization... 1.1. friendlyshell package 7

8 Chapter 1. friendlyshell

CHAPTER 2 Overview Framework for writing interactive Python command line interfaces, similar to the cmd built in class. 9

10 Chapter 2. Overview

CHAPTER 3 Indices and tables genindex modindex search 11

12 Chapter 3. Indices and tables

Python Module Index f friendlyshell, 7 friendlyshell.base_shell, 3 friendlyshell.basic_logger_mixin, 4 friendlyshell.command_complete_mixin, 5 friendlyshell.command_parsers, 6 13

14 Python Module Index

Index A alias_native_shell() (friendlyshell.base_shell.baseshell static method), 3 auto_complete_manager() (in module friendlyshell.command_complete_mixin), 5 B BaseShell (class in friendlyshell.base_shell), 3 BasicLoggerMixin (class in friendlyshell.basic_logger_mixin), 4 C CommandCompleteMixin (class in friendlyshell.command_complete_mixin), 5 D debug() (friendlyshell.base_shell.baseshell static method), 3 debug() (friendlyshell.basic_logger_mixin.basicloggermixin method), 5 default_command_token() (in module friendlyshell.command_parsers), 6 default_line_parser() (in module friendlyshell.command_parsers), 6 run_subshell() do_clear_history() (friendlyshell.command_complete_mixin.commandcompletemixin method), 5 do_close() (friendlyshell.base_shell.baseshell method), 3 do_exit() (friendlyshell.base_shell.baseshell method), 3 do_native_shell() (friendlyshell.base_shell.baseshell method), 3 E error() (friendlyshell.base_shell.baseshell static method), 3 error() (friendlyshell.basic_logger_mixin.basicloggermixin method), 5 F friendlyshell (module), 7 friendlyshell.base_shell (module), 3 friendlyshell.basic_logger_mixin (module), 4 friendlyshell.command_complete_mixin (module), 5 friendlyshell.command_parsers (module), 6 H help_close() (friendlyshell.base_shell.baseshell static method), 4 I info() (friendlyshell.base_shell.baseshell static method), 4 info() (friendlyshell.basic_logger_mixin.basicloggermixin method), 5 Q quoted_space_sep_params_token() (in module friendlyshell.command_parsers), 6 R return_code (friendlyshell.base_shell.baseshell attribute), 4 run() (friendlyshell.base_shell.baseshell method), 4 method), 4 (friendlyshell.base_shell.baseshell W warning() (friendlyshell.base_shell.baseshell static method), 4 warning() (friendlyshell.basic_logger_mixin.basicloggermixin method), 5 15