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: taucmdr.cli.command.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
class taucmdr.cli.cli_view.CopyCommand(*args, **kwargs)[source]

Bases: taucmdr.cli.cli_view.CreateCommand

Base class for the copy subcommand of command line views.

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: taucmdr.cli.cli_view.AbstractCliView

Base class for the create command of command line views.

_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: taucmdr.cli.cli_view.AbstractCliView

Base class for the delete subcommand of command line views.

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: taucmdr.cli.cli_view.AbstractCliView

Base class for the edit subcommand of command line views.

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: taucmdr.cli.cli_view.AbstractCliView

Base class for the list subcommand of command line views.

_count_records(ctrl)[source]

Print a record count to stdout.

Parameters:controller (Controller) – Controller for the data model.
_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 self.key_attr.
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 self.key_attr.
  • 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 self.key_attr.
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: taucmdr.cli.cli_view.AbstractCliView

A command with subcommands for actions.

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.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. This may break when texttable is upgraded as it is marked for internal use only. Adapted from texttable v1.6.3: