ogt.utils.*¶
-
ogt.utils.
clean_str
(source_str, replace='?')[source]¶ Ensure ASCII characters, and replace any non ascii
Parameters: Returns: a tuple containing
- The ascii string
- True if a non ascii character was encounteres, otherwise False
-
ogt.utils.
delete_dir_contents
(dir_path)[source]¶ Deletes all the contents of a directory, not the directory itself
Parameters: dir_path (str) -- The relative or absolute path to the dir
-
ogt.utils.
file_size
(file_path, human=True)[source]¶ Returns a file's size
Parameters: Returns: str or int with the size
-
ogt.utils.
file_size_format
(num, suffix='B')[source]¶ Formats a file size into human readable
Parameters: - num -- size (bytes)
- suffix --
- B is default and return bytes
- or one of Ki, Mi, Gi, Ti, Pi', Ei, Zi
Returns: `str` with file size
-
ogt.utils.
read_json_file
(file_path)[source]¶ Read and decodes a JSON encoded file
Parameters: file_path (str) -- The relative or absolute path of file to read. Return type: tuple Returns: - A decoded python dict or list
- An Error message if file or decoding error, otherwise None
-
ogt.utils.
to_json
(data, minify=False)[source]¶ Serializes python data to a JSON string
Parameters: - data (dict or list) -- the python data to be encoded
- minify (bool) --
- When `False` the json string is minimized with no spaces, new lines etc.
- When `True` the json string is human readable indented with four spaces, and sorted by key.
Note
Important
- By default this project uses `minify=False`.
- For versioning (eg git), it is recommended to use `minify=False` as the string will always be the same, ie sorted keys, and indentation
Returns: a tuple containing
- str with the encoded json
- An Error message if encoding error, otherwise None
-
ogt.utils.
to_yaml
(data)[source]¶ Serializes python data to a YAML string
Parameters: data (dict or list) -- the python data to be encoded Returns: a tuple containing - str with the encoded json
- An Error message if encoding error, otherwise None
-
ogt.utils.
update
()[source]¶ Downloads data dict file from online
Returns: An error if one occured, else None