Utility Functions and the Parser

Groups

class adles.group.Group(name, group, instance=None)[source]

Manages a group of users that has been loaded from a specification

adles.group.get_ad_groups(groups)[source]

Extracts Active Directory-type groups from a dict of groups.

Parameters:groups (dict) – Dict of groups and lists of groups
Returns:List of AD groups extracted
Return type:list(Group)

Parser

adles.parser.check_syntax(specfile_path: str, spec_type: str = 'exercise') → Optional[dict][source]

Checks the syntax of a specification file.

Parameters:
  • specfile_path – Path to the YAML specification file
  • spec_type – Type of specification file

(exercise | package | infra) :return: The specification

adles.parser.parse_yaml(filename: str) → Optional[dict][source]

Parses a YAML file and returns a nested dictionary containing its contents.

Parameters:filename – Name of YAML file to parse
Returns:Parsed file contents
adles.parser.parse_yaml_file(file: _io.TextIOWrapper) → Optional[dict][source]

Parses a YAML file and returns a nested dictionary containing its contents.

Parameters:file – Handle of file to parse
Returns:Parsed file contents
adles.parser.verify_exercise_syntax(spec: dict) → Tuple[int, int][source]

Verifies the syntax of an environment specification.

Parameters:spec – Dictionary of environment specification
Returns:Number of errors, Number of warnings
adles.parser.verify_infra_syntax(infra: dict) → Tuple[int, int][source]

Verifies the syntax of an infrastructure specification.

Parameters:infra – infrastructure
Returns:Number of errors, Number of warnings
adles.parser.verify_package_syntax(package: dict) → Tuple[int, int][source]

Verifies the syntax of an package specification.

Parameters:package – Dictionary representation of the package specification
Returns:Number of errors, Number of warnings

Utils

class adles.utils.TqdmHandler(level=0)[source]
emit(record)[source]

Emit a record.

If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline. If exception information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream has an ‘encoding’ attribute, it is used to determine how to do the output to the stream.

adles.utils.get_vlan() → int[source]

Generates a globally unique VLAN tags.

Returns:VLAN tag
adles.utils.handle_keyboard_interrupt(func: Callable) → Callable[source]

Function decorator to handle keyboard interrupts in a consistent manner.

adles.utils.pad(value: int, length: int = 2) → str[source]

Adds leading and trailing zeros to value (“pads” the value).

>>> pad(5)
05
>>> pad(9, 3)
009
Parameters:
  • value – integer value to pad
  • length – Length to pad to
Returns:

string of padded value

adles.utils.read_json(filename: str) → Optional[dict][source]

Reads input from a JSON file and returns the contents.

Parameters:filename – Path to JSON file to read
Returns:Contents of the JSON file
adles.utils.setup_logging(filename: str, colors: bool = True, console_verbose: bool = False, server: Tuple[str, int] = None, show_progress: bool = True)[source]

Configures the logging interface used by everything for output.

Parameters:
  • filename – Name of file that logs should be saved to
  • colors – Color the terminal output
  • console_verbose – Print DEBUG logs to terminal
  • server – SysLog server to forward logs to
  • show_progress – Show live status as operations progress
adles.utils.sizeof_fmt(num: float) → str[source]

Generates the human-readable version of a file size.

>>> sizeof_fmt(512)
512bytes
>>> sizeof_fmt(2048)
2KB
Parameters:num – Robot-readable file size in bytes
Returns:Human-readable file size
adles.utils.split_path(path: str) → Tuple[List[str], str][source]

Splits a filepath.

>>> split_path('/path/To/A/f1le')
(['path', 'To', 'A'], 'file')
Parameters:path – Path to split
Returns:Path, basename
adles.utils.time_execution(func: Callable) → Callable[source]

Function decorator to time the execution of a function and log to debug.

Parameters:func – The function to time execution of
Returns:The decorated function