taucmdr.cli.cli_view module

A command line data view.

See http://en.wikipedia.org/wiki/Model-view-controller

class taucmdr.cli.cli_view.AbstractCliView(model, module_name, summary_fmt=None, help_page_fmt=None, group=None, include_storage_flag=True)[source]

Bases: AbstractCommand

A command that works as a view for a controller.

See http://en.wikipedia.org/wiki/Model-view-controller

controller

The controller class for this view’s data.

Type:

class

model_name

The lower-case name of the model.

Type:

str

_abc_impl = <_abc._abc_data object>
class taucmdr.cli.cli_view.CopyCommand(*args, **kwargs)[source]

Bases: CreateCommand

Base class for the copy subcommand of command line views.

_abc_impl = <_abc._abc_data object>
_construct_parser()[source]

Construct a command line argument parser.

_copy_record(store, updates, key)[source]
main(argv)[source]

Command program entry point.

Parameters:

argv (list) – Command line arguments.

Returns:

Process return code: non-zero if a problem occurred, 0 otherwise

Return type:

int

class taucmdr.cli.cli_view.CreateCommand(*args, **kwargs)[source]

Bases: AbstractCliView

Base class for the create command of command line views.

_abc_impl = <_abc._abc_data object>
_construct_parser()[source]

Construct a command line argument parser.

_create_record(store, data)[source]

Create the model record.

Parameters:
Returns:

EXIT_SUCCESS if successful.

Return type:

int

Raises:

UniqueAttributeError – A record with the same unique attribute already exists.

main(argv)[source]

Command program entry point.

Parameters:

argv (list) – Command line arguments.

Returns:

Process return code: non-zero if a problem occurred, 0 otherwise

Return type:

int

class taucmdr.cli.cli_view.DeleteCommand(*args, **kwargs)[source]

Bases: AbstractCliView

Base class for the delete subcommand of command line views.

_abc_impl = <_abc._abc_data object>
_construct_parser()[source]

Construct a command line argument parser.

_delete_record(store, key)[source]
main(argv)[source]

Command program entry point.

Parameters:

argv (list) – Command line arguments.

Returns:

Process return code: non-zero if a problem occurred, 0 otherwise

Return type:

int

class taucmdr.cli.cli_view.EditCommand(*args, **kwargs)[source]

Bases: AbstractCliView

Base class for the edit subcommand of command line views.

_abc_impl = <_abc._abc_data object>
_construct_parser()[source]

Construct a command line argument parser.

_update_record(store, data, key)[source]
main(argv)[source]

Command program entry point.

Parameters:

argv (list) – Command line arguments.

Returns:

Process return code: non-zero if a problem occurred, 0 otherwise

Return type:

int

class taucmdr.cli.cli_view.ListCommand(*args, **kwargs)[source]

Bases: AbstractCliView

Base class for the list subcommand of command line views.

_abc_impl = <_abc._abc_data object>
_construct_parser()[source]

Construct a command line argument parser.

_count_records(ctrl)[source]

Print a record count to stdout.

Parameters:

controller (Controller) – Controller for the data model.

_format_long_item(key, val)[source]
_format_records(ctrl, style, keys=None, context=True)[source]

Format records in a given style.

Retrieves records for controller ctrl and formats them.

Parameters:
  • ctrl (Controller) – Controller for the data model.

  • style (str) – Style in which to format records.

  • keys (list) – Keys to match to the model’s key attribute.

Returns:

Record data as formatted strings.

Return type:

list

_list_records(storage_levels, keys, style, context=True)[source]

Shows record data via print.

Parameters:
  • storage_levels (list) – Storage levels to query, e.g. [‘user’, ‘project’]

  • keys (list) – Keys to match to the model’s key attribute.

  • style (str) – Style in which to format records.

Returns:

EXIT_SUCCESS if successful.

Return type:

int

_retrieve_records(ctrl, keys, context=True)[source]

Retrieve modeled data from the controller.

Parameters:
  • ctrl (Controller) – Controller for the data model.

  • keys (list) – Keys to match to the model’s key attribute.

Returns:

Model records.

Return type:

list

dashboard_format(records)[source]

Format modeled records in dashboard format.

Parameters:

records – Modeled records to format.

Returns:

Record data in dashboard format.

Return type:

str

long_format(records)[source]

Format records in long format.

Parameters:

records – Controlled records to format.

Returns:

Record data in long format.

Return type:

str

main(argv)[source]

Command program entry point.

Parameters:

argv (list) – Command line arguments.

Returns:

Process return code: non-zero if a problem occurred, 0 otherwise

Return type:

int

short_format(models)[source]

Format modeled records in short format.

Parameters:

models – Modeled records to format.

Returns:

Record data in short format.

Return type:

str

class taucmdr.cli.cli_view.RootCommand(model, module_name, summary_fmt=None, help_page_fmt=None, group=None, include_storage_flag=True)[source]

Bases: AbstractCliView

A command with subcommands for actions.

_abc_impl = <_abc._abc_data object>
_construct_parser()[source]

Construct a command line argument parser.

main(argv)[source]

Command program entry point.

Parameters:

argv (list) – Command line arguments.

Returns:

Process return code: non-zero if a problem occurred, 0 otherwise

Return type:

int

class taucmdr.cli.cli_view.Texttable(max_width=80)[source]

Bases: Texttable

Extend the Texttable class to print header rows in bold.

_draw_line(line, isheader=False)[source]

Override original Texttable’s _draw_line() method to make headers bold.

Draws a line by looping over a single cell length, over all the cells, making any header text bold. A better place to implement this would have been _splitit() but the logic in texttable does not strip ANSI escape sequences and treats them as printable characters. texttable 1.6.3 and 1.7.1 have the same _draw_line. Adapted from texttable v1.6.3: https://github.com/foutaise/texttable/blob/4073cefdfc4e5c50ed587909875b64b005c70df8/texttable.py#L657-L686