config
This is the module to configure your weatherDB package.
- weatherDB.config = <weatherDB.config.ConfigParser.ConfigParser object>
This is the class/object of the configurations for the weatherDB module.
- class weatherDB.config.ConfigParser(*args, **kwargs)[source]
Bases:
ConfigParserThis is the class/object of the configurations for the weatherDB module.
Warning
You shouldn’t initialize this class directly, but use the :py:data:
weatherDB.configobject from the weatherDB module, which is an instance of this class.- add_listener(section, option, callback)[source]
Add a callback function to be called when a configuration option is changed.
- Parameters:
section (str) – The section of the configuration file. If None, the callback will be called for every change.
option (str) – The option of the configuration file. If None, the callback will be called for every change in the given section.
callback (function) – The function to be called when the configuration option is changed.
- remove_listener(section, option, callback='_all_')[source]
Remove a callback function from the list of callbacks.
- Parameters:
section (str or None) – The section of the configuration file. If “_all_”, the callback will be removed for every change.
option (str or None) – The option of the configuration file. If “_all_”, the callback will be removed for every change in the given section.
callback (function or str, optional) – The function to be removed from the list of callbacks. If “_all_”, all callbacks for the given section and option will be removed. The default is “_all_”.
- set(section, option, value)[source]
Set a configuration option for the weatherDB module.
- Parameters:
- Raises:
PermissionError – If you try to change the database password with this method. Use set_db_credentials instead.
- get_list(section, option)[source]
Get a list of values from a configuration option.
This function parses the configuration option seperated by commas and returns a list of values.
- getlist(section, option)[source]
Get a list of values from a configuration option.
This function parses the configuration option seperated by commas and returns a list of values.
Warning
This function will become deprecated in the future. Please use get_list instead.
- get_datetime(section, option, fallback=None)[source]
Get a date from a configuration option.
This function parses the configuration option and returns a datetime object.
- get_date(section, option, fallback=None)[source]
Get a date from a configuration option.
This function parses the configuration option and returns a date object.
- set_db_credentials(db_key=None, user=None, password=None)[source]
Set the database credentials for the weatherDB database.
- Parameters:
db_key (str, optional) – The key/name for the database section in the configuration file. If not given, the function will use the default database connection. The default is None.
user (str, optional) – The username for the database. If not given, the function will take the user from configuration if possible or ask for it. The default is None.
password (str, optional) – The password for the database user. If not given, the function will ask for it. The default is None.
- property has_user_config
Check if a user config file is defined.
- Returns:
True if a user config file is defined, False otherwise.
- Return type:
- property user_config_file
Get the path to the user config file.
- Returns:
The path to the user config file.
- Return type:
str or None
- create_user_config(user_config_file=None, on_exists='ask')[source]
Create a new user config file.
- Parameters:
user_config_file (str or Path, optional) – The path to the new user config file. If not given, the function will use the config.user_config_file if available or ask for it. If set to “ask”, the function will allways open a filedialog to select the file. The default is None.
on_exists (str, optional) – What to do if the user config file already exists. The options are: - “ask”/”A” : Ask the user what to do. - “overwrite”/”O” : Overwrite the existing file. - “define”/”D” : Only define the file as new user config file location. - “error”/”E” : Raise an error and stop the creation. The default is “ask”.
- load_user_config(raise_undefined_error=True, if_not_existing='ask')[source]
(re)load the user config file.
- Parameters:
raise_undefined_error (bool, optional) – Raise an error if no user config file is defined. The default is True.
if_not_existing (str, optional) – What to do if the user config file is not existing at the specified location. The options are: - “ask” : Ask the user what to do. - “ignore” : Ignore the error and continue. - “create” : Create a new user config file. - “define” : Define a new user config file location. - “remove” : Remove the user config file location. The default is the value of the environment variable “WEATHERDB_HANDLE_NON_EXISTING_CONFIG” or if undefined “ask”.
- set_user_config_file(user_config_file=None)[source]
Define the user config file.
- Parameters:
user_config_file (str, Path or None, optional) – The path to the user config file. If None, the function will open a filedialog to select the file. The default is None.
- update_user_config(section, option, value)[source]
Update a specific value in the user config file.
- load_environment_variables()[source]
Load the environment variables into the configuration.
The following environment variables are possible to use: - WEATHERDB_USER_CONFIG_FILE : The path to the user config file. - WEATHERDB_HANDLE_NON_EXISTING_CONFIG : What to do if the user config file is not existing at the specified location. - WEATHERDB_DB_USER : The username for the database. - WEATHERDB_DB_PASSWORD : The password for the database user. - WEATHERDB_DB_HOST : The host for the database. - WEATHERDB_DB_PORT : The port for the database. - WEATHERDB_DB_DATABASE : The database name. - WEATHERDB_DATA_BASE_DIR : The base path for the data directory. - WEATHERDB_LOGGING_HANDLER : The logging handler to use. Possible values are “console” and “file”. - WEATHERDB_LOGGING_LEVEL : The logging level to use. Possible values are “DEBUG”, “INFO”, “WARNING”, “ERROR” and “CRITICAL”. - WEATHERDB_LOGGING_DIRECTORY : The directory to store the log files. - WEATHERDB_LOGGING_FILE : The file name for the log file. - WEATHERDB_HORIZON_RADIUS : The radius in meters for the horizon angle calculation. - WEATHERDB_HORIZON_CRS : The CRS as EPSG code for the distance calculation during the horizon angle calculation.
- BOOLEAN_STATES = {'0': False, '1': True, 'false': False, 'no': False, 'off': False, 'on': True, 'true': True, 'yes': True}
- NONSPACECRE = re.compile('\\S')
- OPTCRE = re.compile('\n (?P<option>.*?) # very permissive!\n \\s*(?P<vi>=|:)\\s* # any number of space/tab,\n # followed by any of t, re.VERBOSE)
- OPTCRE_NV = re.compile('\n (?P<option>.*?) # very permissive!\n \\s*(?: # any number of space/tab,\n (?P<vi>=|:)\\s* # optionally followed , re.VERBOSE)
- SECTCRE = re.compile('\n \\[ # [\n (?P<header>.+) # very permissive!\n \\] # ]\n ', re.VERBOSE)
- add_section(section)[source]
Create a new section in the configuration. Extends RawConfigParser.add_section by validating if the section name is a string.
- clear() None. Remove all items from D.
- property converters
- defaults()
- get(section, option, *, raw=False, vars=None, fallback=<object object>)
Get an option value for a given section.
If vars is provided, it must be a dictionary. The option is looked up in vars (if provided), section, and in DEFAULTSECT in that order. If the key is not found and fallback is provided, it is used as a fallback value. None can be provided as a fallback value.
If interpolation is enabled and the optional argument raw is False, all interpolations are expanded in the return values.
Arguments raw, vars, and fallback are keyword only.
The section DEFAULT is special.
- getboolean(section, option, *, raw=False, vars=None, fallback=<object object>, **kwargs)
- getfloat(section, option, *, raw=False, vars=None, fallback=<object object>, **kwargs)
- getint(section, option, *, raw=False, vars=None, fallback=<object object>, **kwargs)
- has_option(section, option)
Check for the existence of a given option in a given section. If the specified section is None or an empty string, DEFAULT is assumed. If the specified section does not exist, returns False.
- has_section(section)
Indicate whether the named section is present in the configuration.
The DEFAULT section is not acknowledged.
- items(section=<object object>, raw=False, vars=None)
Return a list of (name, value) tuples for each option in a section.
All % interpolations are expanded in the return values, based on the defaults passed into the constructor, unless the optional argument raw is true. Additional substitutions may be provided using the vars argument, which must be a dictionary whose contents overrides any pre-existing defaults.
The section DEFAULT is special.
- keys() a set-like object providing a view on D's keys
- options(section)
Return a list of option names for the given section name.
- optionxform(optionstr)
- pop(k[, d]) v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem()
Remove a section from the parser and return it as a (section_name, section_proxy) tuple. If no section is present, raise KeyError.
The section DEFAULT is never returned because it cannot be removed.
- read(filenames, encoding=None)
Read and parse a filename or an iterable of filenames.
Files that cannot be opened are silently ignored; this is designed so that you can specify an iterable of potential configuration file locations (e.g. current directory, user’s home directory, systemwide directory), and all existing configuration files in the iterable will be read. A single filename may also be given.
Return list of successfully read files.
- read_dict(dictionary, source='<dict>')
Read configuration from a dictionary.
Keys are section names, values are dictionaries with keys and values that should be present in the section. If the used dictionary type preserves order, sections and their keys will be added in order.
All types held in the dictionary are converted to strings during reading, including section names, option names and keys.
Optional second argument is the source specifying the name of the dictionary being read.
- read_file(f, source=None)
Like read() but the argument must be a file-like object.
The f argument must be iterable, returning one line at a time. Optional second argument is the source specifying the name of the file being read. If not given, it is taken from f.name. If f has no name attribute, <???> is used.
- read_string(string, source='<string>')
Read configuration from a given string.
- readfp(fp, filename=None)
Deprecated, use read_file instead.
- remove_option(section, option)
Remove an option.
- remove_section(section)
Remove a file section.
- sections()
Return a list of section names, excluding [DEFAULT]
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D
- update([E, ]**F) None. Update D from mapping/iterable E and F.
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D's values
- write(fp, space_around_delimiters=True)
Write an .ini-format representation of the configuration state.
If space_around_delimiters is True (the default), delimiters between keys and values are surrounded by spaces.
Please note that comments in the original configuration file are not preserved when writing the configuration back.