Utilities Classes

All following classes are defined in geekcms.utils.

Data Share

class ShareData
classmethod get(cls, search_key)

search_key is a key for search Share section of theme and project settings.

search_key could be in the pattern of ‘theme_name.key’. In such pattern, GeekCMS would lookup the settings file of theme theme_name for key. If such key do not exist in the settings file of theme theme_name, None would be return. If found, a string bound with key would be return.

Besides, search_key could be presented in the pattern of ‘key’(with no ‘.’ in the search_key). In such case, GeekCMS would lookup all settings files of themes and project, the first match value would be return. If not found, None would be return.

Before executing default and extended procedures, GeekCMS would parse all settings file of project and registered themes, and ShareData would load up all the key-value pairs in Share section of the settings files. Since ShareData.get judges the pattern of search_key by finding a ‘dot’, It’s not a good idea to defines a key along with a ‘dot’.

Path Resolve

class PathResolver
project_path

The path of project.

classmethod set_project_path(cls, path)

Set the project_path with path.

classmethod inputs(cls, *, ensure_exist=False)

Return the path of inputs directory of project. If ensure_exist is True and the directory of inputs do not exist, then an empty directory would be created.

classmethod outputs(cls, *, ensure_exist=False)

Return the path of outputs directory of project. If ensure_exist is True and the directory of outputs do not exist, then an empty directory would be created.

classmethod themes(cls, *, ensure_exist=False)

Return the path of themes directory of project. If ensure_exist is True and the directory of themes do not exist, then an empty directory would be created.

classmethod states(cls, *, ensure_exist=False)

Return the path of states directory of project. If ensure_exist is True and the directory of states do not exist, then an empty directory would be created.

classmethod theme_state(cls, theme_name, *, ensure_exist=False)

Return the path of directory contains state of theme. Such path is generated by joining cls.states() and theme_name. If ensure_exist is True and the directory of theme’s state do not exist, then an empty directory would be created.

classmethod theme_dir(cls, theme_name, *, ensure_exist=False)

Return the path of directory contains code of theme. Such path is generated by joining cls.themes() and theme_name. If ensure_exist is True and the directory of theme’s dir do not exist, then an empty directory would be created.

PathResolver can be helpful for development, with which developer could easily get the path of specific directory, and create specific directory if such directory does not exist.