Developer Interface

Application and Commands

class chuda.app.App[source]

Base class for create an application in chuda

app_name = ''

Name of the application, show in the help and version strings

arguments = []

List of Argument objects. Replace with the argparse.Namespace at runtime

arguments_declaration = []

arguments will be copied here of before it be replaced with namespace

config = {}

The configuration file will be loaded here

config_parser = 'ini'

The parser used to parse the configuration file. Possible values are: ini, json, yaml

config_path = []

Acceptable paths to find the configuration file. Stop searching on the first one exists

description = ''

Description of the command. Print in help

logger = None

Instance of Logger

override_default_arguments = False

Should arguments override default provided arguments ?

merge_arguments_in_subcommands = True

Should arguments be merged in subcommands instead of being accesibble globally ?

parser = None

Instance of ArgumentParser

plugins = []

List of Plugins

shell = <chuda.shell.Runner object>

Instance of Runner

subcommands = []

List of Command

version = '0.0.1'

version of your application. Display withe –version flag

call_plugins(step)[source]

For each plugins, check if a “step” method exist on it, and call it

Parameters:step (str) – The method to search and call on each plugin
run()[source]

Run the application

main()[source]

Main method of the application when the program is started without any subcommand selected. If this is not overrided, it will print the help

class chuda.commands.Command[source]

A subcommand for multicommands cli tool

command_name = None

Name of the command, use on the command-line (like “add”, in “git add”)

use_subconfig = False

Should use config_parser and config_path to generate a config for this command

config = {}

The configuration file will be loaded here

config_parser = 'ini'

The parser used to parse the configuration file. Possible values are: ini, json, yaml

config_path = []

Acceptable paths to find the configuration file. Stop searching on the first one exists

app = None

Contains a reference to the App instance who contains this Command

merge_parent_arguments = True

Should parent arguments be merge with local arguments ? True by default.

arguments = []

List of Argument objects. Replace with the argparse.Namespace at runtime

arguments_declaration = None
arguments will be copied here of before it be replaced with namespace
Warning: This will contains only local arguments declarations
logger = None

Instance of Logger

shell = <chuda.shell.Runner object>

Instance of Runner

run()[source]

Run the command

setup(app)[source]

Setup properties from parent app on the command

Arguments

class chuda.arguments.Argument(name=None, action='store', nargs=None, const=None, default=None, type=None, choices=None, required=None, help=None, metavar=None, dest=None)[source]

Abstract parent class for Option and Parameter.

For attributes who are not documented here, please see add_argument() documentation

convert_to_argument()[source]

Convert the Argument object to a tuple use in add_argument() calls on the parser

class chuda.arguments.Option(name=None, action='store', nargs=None, const=None, default=None, type=None, choices=None, required=None, help=None, metavar=None, dest=None)[source]

Represent an option on the command-line (mycommand --whatever)

name

Options can have multiple names, so name must be a list or a tuple

Type:list
get_default_name()[source]

Return the default generated name to store value on the parser for this option.

eg. An option [‘-s’, ‘–use-ssl’] will generate the use_ssl name

Returns:the default name of the option
Return type:str
convert_to_argument()[source]

Convert the Argument object to a tuple use in add_argument() calls on the parser

class chuda.arguments.Parameter(name=None, action='store', nargs=None, const=None, default=None, type=None, choices=None, required=None, help=None, metavar=None, dest=None)[source]

Represent a parameter on the command-line (mycommand whatever)

name

Parameter can have only one name, so it must be a string

Type:str
convert_to_argument()[source]

Convert the Argument object to a tuple use in add_argument() calls on the parser

Plugins

class chuda.plugins.Plugin[source]

Class represent a Plugin for a Chuda application A plugin can register hooks for steps in the application lifecycle or enrich the app with new properties

setup(app)[source]

Setup the app on the plugin

enrich_app(name, value)[source]

Add a new property to the app (with setattr)

Parameters:
  • name (str) – the name of the new property
  • value (any) – the value of the new property
on_create()[source]

Called at the app creation

on_arguments_parsed()[source]

Called after arguments have been parsed

on_config_read()[source]

Called after configurations files have been read

on_signals_handled()[source]

Called after signals handlers have been setuped

on_logger_created()[source]

Called after logger have been created

on_run()[source]

Called just before run the app

on_end()[source]

Called after all steps and code have been executed

Decorators

chuda.decorators.autorun()[source]

Call the run method of the decorated class if the current file is the main file

chuda.decorators.signal_handler(sig)[source]

Flag a method to be used as a signal handler

Parameters:sig (signal) – The signal, from the signal module

Shell

class chuda.shell.Runner(logger=None, cwd=None)[source]

Factory for ShellCommand

cwd

the current working directory

Type:str
logger

Instance of Logger

Type:Logger
run(command, block=True, cwd=None, stdin=-1, stdout=-1, stderr=-1)[source]

Create an instance of ShellCommand and run it

Parameters:
class chuda.shell.ShellCommand(command, logger, cwd=None, block=True, stdin=-1, stdout=-1, stderr=-1)[source]

DEPRECATED: Please use sh.py instead

Abstraction layer for shell subprocess

You can disable stdout, stdin, stderr

block

if false, the command will be run asynchronously

Type:bool
command

the shell command to run

Type:str
cwd

the current working directory

Type:str
error

everything the command will write on stderr will be here

Type:str|list
logger

Instance of Logger

Type:Logger
output

everything the command will write on stdout will be here

Type:str|list
process

the Popen instance use to run the command

Type:Popen
return_code

the return code of the shell command

Type:int
thread

the Thread instance use if the command is run in non blocking mode

Type:Thread
writer

Instance of TextIOWrapper plugged on stdin

Type:TextIOWrapper
run()[source]

Run the shell command

Returns:return this ShellCommand instance for chaining
Return type:ShellCommand
send(value)[source]

Send text to stdin. Can only be used on non blocking commands

Parameters:value (str) – the text to write on stdin
Raises:TypeError – If command is blocking
Returns:return this ShellCommand instance for chaining
Return type:ShellCommand
poll_output()[source]

Append lines from stdout to self.output.

Returns:The lines added since last call
Return type:list
poll_error()[source]

Append lines from stderr to self.errors.

Returns:The lines added since last call
Return type:list
kill()[source]

Kill the current non blocking command

Raises:TypeError – If command is blocking
wait_for(pattern, timeout=None)[source]

Block until a pattern have been found in stdout and stderr

Parameters:
  • pattern (Pattern) – The pattern to search
  • timeout (int) – Maximum number of second to wait. If None, wait infinitely
Raises:

TimeoutError – When timeout is reach

is_running()[source]

Check if the command is currently running

Returns:True if running, else False
Return type:bool
wait()[source]

Block until the end of the process

print_live_output()[source]

Block and print the output of the command

Raises:TypeError – If command is blocking