robottelo.cli.hammer

Helpers to interact with hammer command line utility.

Module Contents

Functions

_csv_reader(output)

An unicode CSV reader which processes unicode strings and return unicode

_normalize(header)

Replace empty spaces with ‘-’ and lower all chars

parse_json(stdout)

Parse JSON output from Hammer CLI and convert it to python dictionary

_normalize_obj(obj)

Normalize all dict’s keys replacing empty spaces with “-” and lowering

parse_csv(output)

Parse CSV output from Hammer CLI and convert it to python dictionary.

parse_help(output)

Parse the help output from a hammer command and return a dictionary

get_line_indentation_spaces(line, tab_spaces=4)

Return the number of spaces chars the line begin with

get_line_indentation_level(line, tab_spaces=4, indentation_spaces=4)

Return the indentation level

parse_info(output)

Parse the info output and returns a dict mapping the values.

robottelo.cli.hammer._csv_reader(output)[source]

An unicode CSV reader which processes unicode strings and return unicode strings data.

This is needed because the builtin module does not support unicode strings, from Python 2 docs:

Note: This version of the csv module doesn't support Unicode input.
Also, there are currently some issues regarding ASCII NUL characters.
Accordingly, all input should be UTF-8 or printable ASCII to be safe;"

On Python 3 this generator is not needed because the default string type is unicode.

Parameters

output – can be any object which supports the iterator protocol and returns a unicode string each time its next() method is called.

Returns

generator that will yield a list of unicode string values.

robottelo.cli.hammer._normalize(header)[source]

Replace empty spaces with ‘-’ and lower all chars

robottelo.cli.hammer.parse_json(stdout)[source]

Parse JSON output from Hammer CLI and convert it to python dictionary while normalizing keys.

robottelo.cli.hammer._normalize_obj(obj)[source]

Normalize all dict’s keys replacing empty spaces with “-” and lowering chars

robottelo.cli.hammer.parse_csv(output)[source]

Parse CSV output from Hammer CLI and convert it to python dictionary.

robottelo.cli.hammer.parse_help(output)[source]

Parse the help output from a hammer command and return a dictionary mapping the subcommands and options accepted by that command.

robottelo.cli.hammer.get_line_indentation_spaces(line, tab_spaces=4)[source]

Return the number of spaces chars the line begin with

Parameters
  • line (str) – the line string to parse

  • tab_spaces (int) – The tab char is represent how many spaces

robottelo.cli.hammer.get_line_indentation_level(line, tab_spaces=4, indentation_spaces=4)[source]

Return the indentation level

Parameters
  • line (str) – the line string to parse

  • tab_spaces (int) – The tab char is represent how many spaces

  • indentation_spaces – how much spaces represent an indentation level

Note:

suppose we have the following lines:
'''
level 0
    level 1
        level 2
'''
assert get_line_indentation_level('level 0') == 0
assert get_line_indentation_level('    level 1') == 1
assert get_line_indentation_level('        level 2') == 2
robottelo.cli.hammer.parse_info(output)[source]

Parse the info output and returns a dict mapping the values.