model_organization.utils module

Functions

dir_contains(dirname, path[, exists])

Check if a file of directory is contained in another.

get_module_path(mod)

Convenience method to get the directory of a given python module

get_next_name(old[, fmt])

Return the next name that numerically follows old

get_toplevel_module(mod)

go_through_dict(key, d[, setdefault])

Split up the key by .

isstring(s)

safe_list(l)

Function to create a list

dir_contains(dirname, path, exists=True)[source]

Check if a file of directory is contained in another.

Parameters
  • dirname (str) – The base directory that should contain path

  • path (str) – The name of a directory or file that should be in dirname

  • exists (bool) – If True, the path and dirname must exist

Notes

path and dirname must be either both absolute or both relative paths

get_module_path(mod)[source]

Convenience method to get the directory of a given python module

get_next_name(old, fmt='%i')[source]

Return the next name that numerically follows old

get_toplevel_module(mod)[source]
go_through_dict(key, d, setdefault=None)[source]

Split up the key by . and get the value from the base dictionary d

Parameters
  • key (str) – The key in the config configuration. If the key goes some levels deeper, keys may be separated by a '.' (e.g. 'namelists.weathergen'). Hence, to insert a ',', it must be escaped by a preceeding ''.

  • d (dict) – The configuration dictionary containing the key

  • setdefault (callable) – If not None and an item is not existent in d, it is created by calling the given function

Returns

  • str – The last level of the key

  • dict – The dictionary in d that contains the last level of the key

isstring(s)[source]
safe_list(l)[source]

Function to create a list

Parameters

l (iterable or anything else) –

Parameter that shall be converted to a list.

  • If string or any non-iterable, it will be put into a list

  • if iterable, it will be converted to a list

Returns

l put (or converted) into a list

Return type

list