|
Odyssey
|
Functions | |
| def | get_ith_batch (_list, batch_index, batch_size) |
| def | encode_base64 (_data) |
| def | decode_base64 (_encode) |
| def | get_valid_json (_obj, **kwargs) |
| def | sanitize_insert_values (_values) |
| def | sanitize_dict (records_dict) |
| def | sanitize_insert_collection (_collection) |
| def | generate_mdx_hash (_cu, _key) |
| def | generate_hash (_action, _cu, _secret_key) |
| def | format_error_permission (_e, _file__or_script) |
| def | file_exc_decorator (original_file_handler) |
| def | get_strip_value_dict (_k, _dict, **kwargs) |
| def | log_progress (_progress_dict) |
| def | custom_css_parser (_content) |
Variables | |
| LOGGER = logging.getLogger(__name__) | |
This module includes utility functions.
| def ody_migr_utils.custom_css_parser | ( | _content | ) |
Simple css parser to convert css attributes to python dict.
Args:
_content (str): main css content
Returns:
cssdict (dict): parsed python dictionary
Alternative advanced css parsing using tinycss
**implementation starts**
import tinycss
parser = tinycss.make_parser()
stylesheet = parser.parse_stylesheet(_content)
cssdict = {}
for rule in stylesheet.rules:
this_rule = rule.selector.as_css()
cssdict[this_rule] = {}
print (this_rule)
for css_attr in rule.declarations:
# print (css_attr)
cssdict[this_rule][css_attr.name] = css_attr.value.as_css()
print (css_attr.name, css_attr.value.as_css())
print(stylesheet.errors)
return cssdict
**implementation ends**
Definition at line 250 of file ody_migr_utils.py.
| def ody_migr_utils.decode_base64 | ( | _encode | ) |
Decode base64 encoded content to string
Args:
_encode : bytes-like object
Returns:
decoded string
Definition at line 45 of file ody_migr_utils.py.
| def ody_migr_utils.encode_base64 | ( | _data | ) |
Encode content into using base64 encoding
Args:
_data (str): input data to encode
Returns:
base64 encoded bytes
Definition at line 33 of file ody_migr_utils.py.
| def ody_migr_utils.file_exc_decorator | ( | original_file_handler | ) |
| def ody_migr_utils.format_error_permission | ( | _e, | |
| _file__or_script | |||
| ) |
Display error messages for FileNotFound/Permission Denied errors.
Args:
_e: error message object
_file_or_script: script/file that caused error
Returns:
Formatted PermissionError/FileNotFoundError error message
Definition at line 163 of file ody_migr_utils.py.
| def ody_migr_utils.generate_hash | ( | _action, | |
| _cu, | |||
| _secret_key | |||
| ) |
Generate and return authentication hash code
Args:
_action: Data target
_cu: Current CU
Returns:
SHA1 encoded hexdigest code
Definition at line 147 of file ody_migr_utils.py.
| def ody_migr_utils.generate_mdx_hash | ( | _cu, | |
| _key | |||
| ) |
Generate and return MDX new_id hash
Args:
_cu: Current CU
_key: key to append with _cu
Returns:
SHA1 encoded hexdigest code
Definition at line 131 of file ody_migr_utils.py.
| def ody_migr_utils.get_ith_batch | ( | _list, | |
| batch_index, | |||
| batch_size | |||
| ) |
Utility function to obtain a ith batch of data from list
Args:
_list: list to choose batch from
batch_index: batch index
batch_size: size of batch to select
Returns:
batch (sub list of _list) of size batch_size
Definition at line 17 of file ody_migr_utils.py.
| def ody_migr_utils.get_strip_value_dict | ( | _k, | |
| _dict, | |||
| ** | kwargs | ||
| ) |
Get or Pop an element from a dictionary
Args:
_k: key to get or pop
_dict: dictionary to get or pop an element from
**kwargs: Options:
default: default value to return
pop: do we `get` or `pop` from the dict
Returns:
value associated with key in a dictionary
Raises:
ValueError, TypeError if the invalid castto is encountered
Definition at line 207 of file ody_migr_utils.py.
| def ody_migr_utils.get_valid_json | ( | _obj, | |
| ** | kwargs | ||
| ) |
Utility function to print pretty json string
Args:
_obj: python dictionary
**kwargs: optional keywords arguments
possible values:
pretty: for pretty printing
Returns:
prints formatted json string
Definition at line 57 of file ody_migr_utils.py.
| def ody_migr_utils.log_progress | ( | _progress_dict | ) |
Log progress information to be used in progressbar in Monitor
Args:
_progress_dict: dictionary that contains completed and total stat
Definition at line 240 of file ody_migr_utils.py.
| def ody_migr_utils.sanitize_dict | ( | records_dict | ) |
Sanitize dictionary values
Args:
records_dict: dictionary values
Returns:
list of stripped, sanitized dictionary
Definition at line 96 of file ody_migr_utils.py.
| def ody_migr_utils.sanitize_insert_collection | ( | _collection | ) |
Cleanup list values
Args:
_collection: list of dictionary values
Returns:
list of stripped, sanitized list of dictionary values
Definition at line 113 of file ody_migr_utils.py.
| def ody_migr_utils.sanitize_insert_values | ( | _values | ) |
Cleanup list values
Args:
_values: list of values
Returns:
list of normalized list
Definition at line 78 of file ody_migr_utils.py.
1.8.15