ogt.utils.*

ogt.utils.ags4dd_file()[source]
Returns:str with path to the ags4.min.json data dict file
ogt.utils.clean_str(source_str, replace='?')[source]

Ensure ASCII characters, and replace any non ascii

Parameters:
  • source_str (str) -- The source str to clean
  • replace (str) -- The character(s) to replace non ascii characters with
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:
  • file_path (str) -- relative or absolute path to file
  • human (bool) --
    • If False, return an int of the file size in bytes
    • If True returns a str with bytes in Kb, MB
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.get_example_dirs()[source]
ogt.utils.initialise()[source]

Check env is sane and loads the ags data dict file

ogt.utils.list_examples(sub_dir)[source]
ogt.utils.ogt_dir()[source]

Path to open-getechnical cache directory

ogt.utils.read_file(file_path)[source]
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_int(obj)[source]
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
ogt.utils.user_dir()[source]

Path to users home dir

ogt.utils.write_file(file_path, contents)[source]
ogt.utils.write_json_file(file_path, data, minify=False)[source]

Saves python data in a JSON encoded file

Parameters:
  • file_path (str) -- The relative or absolute path of file to save.
  • data (dict or list) -- The python data to save
  • minify (bool) -- see to_json()
Returns:

Error message if write error, otherwise None

ogt.utils.write_yaml_file(file_path, data)[source]

Saves python data in a JSON encoded file

Parameters:
  • file_path (str) -- The relative or absolute path of file to save.
  • data (dict or list) -- The python data to save
Returns:

Error message if write error, otherwise None