Utilities¶
This part of the documentation covers all the utilities of GMUtils.
Config Object¶
-
class
gmutils.utils.config.
Config
¶ -
ENV
¶
The ENV attribute allows you to dictate which enviroment your current code is runing in
-
THREADS
¶
This is a list of current running threads
-
classmethod
export
(path=None, export_object=None, depth=1)¶ This function allows for simple exporting funionality.
Keyword Arguments: - {str} -- path for the output to be saved too (default (path) – {None})
- {object} -- arbatiry object (default (export_object) – {Config})
- {int} -- the depth of the exporting (default (depth) – {1})
Returns: dict – returns a dictonary for exporting if path is not set
-
classmethod
haltThreads
(name=None)¶ This function is used to stop all registered threads added to the Config.THREADS list. This will set the Config.HALT boolean to True which should make stop threads from executing if they are using the helpme_thread wrappers.
Keyword Arguments: - {str} -- name of the group of threads that you want to (name) –
- (default (shutdown) – {None})
-
classmethod
initCLI
()¶ This allows for an application to have an initial CLI flow for standard arguments.
-
classmethod
isTesting
()¶ This function is used to determine if the current enviroment is for testing or production.
Returns: bool – if the current system is in testing or prod
-
classmethod
load
()¶ The load function runs though a predeterminded list of of loading paths, env vars and command argvs.
-
classmethod
loadDict
(config_dct)¶ The loadDict function allows for dict objects to be loaded into the Config() class.
Parameters: {dict} -- the dict to be loaded into Config() (config_dct) – Raises: GMException – If a object that isn’t a dict, this error will be thrown
-
classmethod
loadFile
(path_file)¶ You can load a config from file from this function. This is where addition support for different loads can be placed.
Parameters: {str} -- path to a configuration file (path_file) – Raises: GMException – If the configuration file doesn’t match the critiria, this exception will be thrown.
-
Paths Object¶
-
class
gmutils.utils.paths.
Paths
(**kargvs)¶ -
__export__
()¶ When the object is exported, this is the returned values not the whole object. This is used with the Paths.load() function to load the options back into the class.
Returns: dict – exported dictorary
-
__init__
(**kargvs)¶ The Paths() class supplies Utils with an interface to set, get and other functionality to GMUtils.
Parameters: {dict} -- options being set/loaded into Paths() (**kargvs) –
-
add
(name, path, **kargvs)¶ The add function allows developers to add paths for their project, allowing many options for the developer to use.
Parameters: - {str} -- the name of the resource (name) –
- {str} -- the path or location to a resource (path) –
- {dict} -- the different path options (**kargvs) –
- Options (kargvs):
required {bool} – The required paramater allows the developer to make sure that the file/dir exists before using it. An example of this is to check if a config file exists, if it doesn’t an exception will be thrown.
create {bool} – The create parameter will create the file for the user if the file doesn’t exist already.
directory {bool} – The directory flag is set when a developer wants to create/use the path as a directory.
mime {str} – The mime paramater allows for the developer to quickly check the file type before its used. An example of this is if you are expecting a JSON file, using ‘application/json’ will make sure that the correct files are used without the developer having to write any more code.
Raises: - GMException – if kargvs option key is unknown
- GMException – if kargvs option value is of unknown type
- GMException – if path name already exists
- GMException – if kargvs.required is True but doesn’t exist
-
check
(path, mime=None)¶ The check function allows you to provide a path and perform various checks. This will return if those checks were sucessful.
- Checks:
- Does the path exist?
- Does the provided mime type match?
Parameters: {str} -- path that the checked will be performed against (path) – Keyword Arguments: {str} -- the mime type that the file must be (default (mime) – {None}) Returns: bool – return the value
-
static
checkMime
(path, mime=None)¶ This function allows a user to check if a path provided is the type that is expected using mime file types.
Parameters: {str} -- path that will be checked (path) –
Keyword Arguments: - {str} -- if a mime is provided, the check will be performed. (mime) –
- not mime type is provided, the mimetype is returned. (if) –
- (default – {None})
Raises: GMSecurity – if a mime is provided and the file does not match
Returns: str,bool – string of the mime from the file or True if sucessful
-
clear
()¶ This function will reset/clear the current paths added in the Paths() class.
-
static
create
(path, is_directory=False)¶ Create is a static function that will create files or directories on behalf other the programmer.
Parameters: {str} -- the path you want (path) –
Keyword Arguments: - {bool} -- is it a directory you want to create? (is_directory) –
- (default – {False})
-
defaults
()¶ Set multiple default paths
Paths created: - cwd – Current Working Directory - project – The location where the project is stored - project-lib – local project library directory - project-data – local project data storage area - config-project – local project config file stored
-
get
(name, mime=None)¶ This function allows you to get a path/resource by name that has been registered
Parameters: {str} -- the name that you can to get (name) – Keyword Arguments: {str} -- the mime type that the file must be (default (mime) – {None}) Returns: str – path based off the name provided
-
getFull
(name)¶ This function will get all the details associated to a path.
Parameters: {str} -- the name that you can to get (name) – Returns: dict – return the full details of the path
-
join
(root, *paths)¶ The Paths.join() function is just a wrapper on-top of the standard os.path.join() function except it performs some security checks if Paths.security_checks is set to true.
Parameters: - {str} -- the root directory (root) –
- {str} -- list of paths to join (*paths) –
Raises: GMSecurity – when a security issue occurs
Returns: str – the full string of the concatinated paths
-
load
(**kargvs)¶ The Path.load() function is used for loads all the projects predetermined path variables. Normally these are defined in the projects config.json file.
Parameters: {dict} -- options being loaded into Paths() (**kargvs) –
-
remove
(name)¶ The remove function deletes a path by name.
Parameters: {str} -- Name of the path that you want to delete (name) – Raises: GMException – if the path does not exist
-
Constants Object¶
-
class
gmutils.utils.constants.
Constants
¶ -
__export__
()¶ Allows for Constants to be exported
Returns: dict – returns constants in __CONSTS__ dict
-
add
(key, value)¶ Add a constant with a key and value
Parameters: - {str} -- string of the constant that will be added (key) –
- {object} -- value (value) –
-
clear
()¶ Resets all the current constants
-
get
(query, default=None)¶ Query for keys using a query
Parameters: - {str} -- query string (query) –
- {object} -- arbitrary object (default (default) – {None})
Returns: object – returns the arbitrary value found at the end of the query, or the default varable
-
load
(**kargvs)¶ The load function allows a developer to loads constants
Parameters: {dict} -- dict of constants (kargvs) –
-
Get Query Function¶
-
gmutils.utils.get.
get
(myobject, query, default=None)¶ This function allows you to query a dict object to get the value recursively through dicts and array’s, returning the value found at the end of the query chain.
Parameters: - {object} -- dictionary or array of objects (myobject) –
- {str} -- query string (query) –
Keyword Arguments: {object} -- the default return type (default (default) – {None})
Returns: [type] – return value if query does not return None or returned default object