sksurgerycore.configuration.configuration_manager module¶
Class to load application configuration information from a json file.
- Design principles:
All errors as Exceptions
- Fail early in constructor, so the rest of the program neverhas an invalid instance of ConfigurationManager.If its constructed, its valid.
Setter and Getter do a deepcopy, so only suitable for small config files.
- Pass ConfigurationManager to any consumer of the data,its up to the consumer to know where to find the data.
-
class
sksurgerycore.configuration.configuration_manager.
ConfigurationManager
(file_name, write_on_setter=False)[source]¶ Bases:
object
Class to load application configuration from a json file. For example, this might be used at the startup of an application.
Parameters: - file_name – a json file to read.
- write_on_setter – if True, will write back to the same file whenever the setter is called.
Raises: All errors raised as various Exceptions.
-
get_copy
()[source]¶ Returns a copy of the data read from file.
Returns: deep copy of whatever data structure is stored internally.
-
get_dir_name
()[source]¶ Returns the directory name of the file that was used when creating the ConfigurationManager.
Returns: str dir name
-
get_file_name
()[source]¶ Returns the absolute filename that was used when the ConfigurationManager was created.
Returns: str absolute file name
-
set_data
(config_data)[source]¶ Stores the provided data internally.
Note that: you would normally load settings from disk, and then use get_copy() to get a copy, change some settings, and then use set_data() to pass the data structure back in. So, the data provided for this method should still represent the settings you want to save, not just be a completely arbitrary data structure.
Parameters: config_data – data structure representing your settings.