Utilities

This part of the module provides a collection of generic utilities which are largely for internal use.

The various utilities are typically imported like so:

from mosromgr.utils import s3

Warning

This part of the module should not be considered part of the stable API and is subject to backwards-incompatible changes.

S3

AWS S3 utilities

get_mos_files

mosromgr.utils.s3.get_mos_files(bucket_name: str, prefix: Optional[str] = None, *, suffix: str = '.mos.xml') List[str][source]

Retrieve MOS files from given S3 bucket in location defined by prefix. Returns a list of file keys.

get_file_contents

mosromgr.utils.s3.get_file_contents(bucket_name, file_key)[source]

Open the S3 file and return its contents as a string

XML

XML helper functions

remove_node

mosromgr.utils.xml.remove_node(parent: Element, node: Element)[source]

Remove node from parent.

replace_node

mosromgr.utils.xml.replace_node(parent: Element, old_node: Element, new_node: Element, index: int)[source]

Replace old_node with new_node in parent at index.

insert_node

mosromgr.utils.xml.insert_node(parent: Element, node: Element, index: int)[source]

Insert node in parent at index.

find_child

mosromgr.utils.xml.find_child(parent: Element, child_tag: str, id: Optional[str] = None) Tuple[Optional[Element], Optional[int]][source]

Find an element with child_tag in parent and return (child, index) or (None, None) if not found. If id is provided, it will be searched for, otherwise the first child will be returned.