Skip to content

gufo.err.cli

err utility.

Cli

Bases: object

err utility class.

__check_dir(path) staticmethod

Check if directory exists and accessible.

Parameters:

Name Type Description Default
path str

Directory path

required

Returns:

Type Description
ExitCode
  • OK - on success
ExitCode
  • NOT_EXISTS - if the directory is not exists
ExitCode
  • EACCESS - if the directory is not accessible

col(t, width) staticmethod

Format text to column.

Enlarge with spaces, when necessary. Cut if too long.

Parameters:

Name Type Description Default
t str

Text

required
width int

Column width

required

Returns:

Type Description
str

Aligned text.

Examples:

col("abcdef", 5)
returns
"ab..."

get_handler(name)

Get handler for command.

Return the handler for furher command processing.

Parameters:

Name Type Description Default
name str

Command name

required

Returns:

Type Description
Callable[[Namespace], ExitCode]

Callable, accepting argparse.Namespace

Callable[[Namespace], ExitCode]

and returning ExitCode.

get_index(prefix) staticmethod

Get fingerprint index.

Parameters:

Name Type Description Default
prefix str

Error Info directory prefix

required

Returns:

Type Description
Dict[str, str]

Dict of fingerprint -> file name

handle_clear(ns)

Clear selected errors.

Parameters:

Name Type Description Default
ns Namespace

argsparse.Namespace with fields:

  • prefix - directory of errorinfo files.
  • fingerprints - List of fingerprint expressions.
required

Returns:

Type Description
ExitCode

Exit code.

handle_list(ns)

Show the list of the registered errors.

Parameters:

Name Type Description Default
ns Namespace

argsparse.Namespace with fields:

  • prefix - directory of errorinfo files.
  • fingerprints - list of fingerprint expressions.
required

Returns:

Type Description
ExitCode

Exit code.

handle_version(_ns)

Print Gufo Err version.

Parameters:

Name Type Description Default
_ns Namespace

Options namespace, ignored.

required

Returns:

Type Description
ExitCode

Exit code.

handle_view(ns)

Show the details of the selected errors.

Parameters:

Name Type Description Default
ns Namespace

argsparse.Namespace with fields:

  • prefix - directory of errorinfo files.
  • format - output format:

    • terse
    • extend
  • fingerprints - List of fingerprint expressions.

required

Returns:

Type Description
ExitCode

Exit code.

iter_fingerprints(items, prefix) staticmethod

Resolve fingerprint expressions and iterate result.

Fingerprint expressions is a list user-defined expressions passed via command line. Each item may be:

  • <UUID> - single fingerprint
  • all or * - all errors

Parameters:

Name Type Description Default
items List[str]

List of expressions.

required
prefix str

Error info directory

required

Returns:

Type Description
Iterable[str]

Yields all resolved fingerprints.

rcol(t, width) staticmethod

Format text to column aligned to the range.

Enlarge with spaces, when necessary. Cut if too long.

Parameters:

Name Type Description Default
t str

Text

required
width int

Column width

required

Returns:

Type Description
str

Aligned text.

Examples:

col("abcdef", 5)
returns
"...ef"

read_info(path) staticmethod

Read error info file.

Parameters:

Name Type Description Default
path str

JSON file path

required

Returns:

Type Description
Optional[ErrorInfo]
  • ErrorInfo instance, if file has been read correctly.
Optional[ErrorInfo]
  • None otherwise.

run(args)

Main dispatcher function.

Parameters:

Name Type Description Default
args List[str]

List of command-line arguments.

required

ExitCode

Bases: IntEnum

Cli exit codes.

Attributes:

Name Type Description
OK

Successful exit

NOT_EXISTS

Error Info directory is not found

EACCESS

Error Info directory is not readable

CANNOT_READ

Cannot read Error Info file

INVALID_ARGS

Invalid arguments

SYNTAX

Invalid expression

ListItem dataclass

Bases: object

Data structure for err list.

Attributes:

Name Type Description
fingerprint str

Stringified fingerprint.

exception str

Exception string.

name str

Application name.

ts datetime

Error timestamp.

place str

Error location.

main()

Run err utility with command-line arguments.