eww.command

This is our custom command module. It is a subclass of cmd.Cmd. The most significant change is using classes rather than functions for the commands.

Due to this change, we don’t use CamelCase for command class names here. Strictly that’s ok via PEP8 since we are kinda treating these like callables. Just a heads up.

class eww.command.Command(completekey='tab', stdin=None, stdout=None)[source]

Bases: cmd.Cmd

Our cmd subclass where we implement all console functionality.

class BaseCmd[source]

Bases: object

The base class for all commands.

__weakref__

list of weak references to the object (if defined)

run(line)[source]

Performs the requested command. You should definitely override this.

Parameters:line (str) – A command line argument to be parsed.
Returns:True to exit, None otherwise.
Return type:bool
class Command.EOF_command[source]

Bases: eww.command.BaseCmd

Implements support for EOF being interpreted as an exit request.

run(line)[source]

Returns True to trigger an exit.

Parameters:line (str) – A command line argument to be parsed.
Returns:True
Return type:bool
Command.default(line)[source]

The first responder when a command is unrecognized.

class Command.exit_command[source]

Bases: eww.command.BaseCmd

Implements support for the ‘exit’ command to leave the console.

run(line)[source]

Returns True to trigger an exit.

Parameters:line (str) – A command line argument to be parsed.
Returns:True
Return type:bool
class Command.help_command[source]

Bases: eww.command.BaseCmd

When called with no arguments, this presents a friendly help page. When called with an argument, it presents command specific help.

__init__()[source]

Init.

display_command_detail(command_name)[source]

Displays detailed command help.

Parameters:command_name (str) – A command name to print detailed help for.
Returns:None
display_commands()[source]

Displays all included commands.

Returns:None
get_commands()[source]

Returns a list of command classes.

Returns:A list of command classes (not instantiated).
Return type:list
run(line)[source]

Provides help documentation.

Parameters:line (str) – A command line argument to be parsed.
Returns:None
Command.onecmd(line)[source]

We override cmd.Cmd.onecmd in order to support our class-based commands. Changes are noted via comments.

Parameters:line (str) – A command (with arguments) to be executed.
Returns:True if a command is designed to exit, otherwise None.
Return type:bool
class Command.quit_command[source]

Bases: eww.command.BaseCmd

Implements support for the ‘quit’ command to leave the console.

run(line)[source]

Returns True to trigger an exit.

Parameters:line (str) – A command line argument to be parsed.
Returns:True
Return type:bool
class Command.repl_command[source]

Bases: eww.command.BaseCmd

Drops the user into a python REPL.

register_quit()[source]

Registers our custom quit function to prevent stdin from being closed.

Returns:None
run(line)[source]

Implements the repl.

Parameters:line (str) – A command line argument to be parsed.
Returns:None
unregister_quit()[source]

Unregisters our custom quit function.

Returns:None
class Command.stats_command[source]

Bases: eww.command.BaseCmd

A command for inspecting stats and generating graphs.

__init__()[source]

Init.

display_single_stat(stat_name)[source]

Prints a specific stat.

Parameters:stat_name (str) – The stat name to display details of.
Returns:None
display_stat_summary()[source]

Prints a summary of collected stats.

Returns:None
generate_graph(options, stat_name)[source]

Generate a graph of stat_name.

Parameters:
  • options (dict) – A dictionary of option values generated from our parser.
  • stat_name (str) – A graph name to create a graph from.
Returns:

None

reduce_data(data)[source]

Shrinks len(data) to self.max_points.

Parameters:data (iterable) – An iterable greater than self.max_points.
Returns:A list with a fair sampling of objects from data, and a length of self.max_points.
Return type:list
run(line)[source]

Outputs recorded stats and generates graphs.

Parameters:line (str) – A command line argument to be parsed.
Returns:None