vantage6.common.context.AppContext#
- class AppContext(instance_type, instance_name, system_folders=False, config_file=None, print_log_header=True)#
Bases:
object
Base class from which to create Node and Server context classes.
- __init__(instance_type, instance_name, system_folders=False, config_file=None, print_log_header=True)#
Create a new AppContext instance.
- Parameters:
instance_type (InstanceType) – Type of instance that is initialized
instance_name (str) – Name of the configuration
system_folders (bool) – Use system folders instead of user folders
config_file (str) – Path to a specific config file. If left as None, OS specific folder will be used to find the configuration file specified by instance_name.
print_log_header (bool) – Print a banner to the log file.
Methods
__init__
(instance_type, instance_name[, ...])Create a new AppContext instance.
available_configurations
(instance_type, ...)Returns a list of configuration managers and a list of paths to configuration files that could not be loaded.
config_exists
(instance_type, instance_name)Check if a config file exists for the given instance type and name.
configure_logger
(name, level)Set the logging level of a logger.
find_config_file
(instance_type, ...[, ...])Find a configuration file.
from_external_config_file
(path, instance_type)Create a new AppContext instance from an external config file.
get_data_file
(filename)Return the path to a data file.
initialize
(instance_type, instance_name[, ...])Initialize the AppContext instance.
instance_folders
(instance_type, ...)Return OS and instance specific folders for storing logs, data and config files.
log_file_name
(type_)Return a path to a log file for a given log file type
Print the log file header.
set_folders
(instance_type, instance_name, ...)Set the folders where the configuration, data and log files are stored.
Setup a basic logging mechanism.
type_data_folder
(instance_type, system_folders)Return OS specific data folder.
Attributes
LOGGING_ENABLED
Return the path to the configuration file.
Return the name of the configuration file.
Return the path to the log file.
- INST_CONFIG_MANAGER#
alias of
ConfigurationManager
- classmethod available_configurations(instance_type, system_folders)#
Returns a list of configuration managers and a list of paths to configuration files that could not be loaded.
- Parameters:
instance_type (InstanceType) – Type of instance that is checked
system_folders (bool) – Use system folders rather than user folders
- Returns:
A list of configuration managers and a list of paths to configuration files that could not be loaded.
- Return type:
list[ConfigurationManager], list[Path]
- classmethod config_exists(instance_type, instance_name, system_folders=False)#
Check if a config file exists for the given instance type and name.
- Parameters:
instance_type (InstanceType) – Type of instance that is checked
instance_name (str) – Name of the configuration
system_folders (bool) – Use system folders rather than user folders
- Returns:
True if the config file exists, False otherwise
- Return type:
bool
- property config_file: Path#
Return the path to the configuration file.
- Returns:
Path to the configuration file
- Return type:
Path
- property config_file_name: str#
Return the name of the configuration file.
- Returns:
Name of the configuration file
- Return type:
str
- static configure_logger(name, level)#
Set the logging level of a logger.
- Parameters:
name (str) – Name of the logger to configure. If None, the root logger is configured.
level (str) – Logging level to set. Must be one of ‘debug’, ‘info’, ‘warning’, ‘error’, ‘critical’.
- Returns:
The logger object and the logging level that was set.
- Return type:
Tuple[Logger, int]
- classmethod find_config_file(instance_type, instance_name, system_folders, config_file=None, verbose=True)#
Find a configuration file.
- Parameters:
instance_type (InstanceType) – Type of instance that is checked
instance_name (str) – Name of the configuration
system_folders (bool) – Use system folders rather than user folders
config_file (str | None) – Name of the configuration file. If None, the name of the configuration is used.
verbose (bool) – Print the directories that are searched for the configuration file.
- Returns:
Path to the configuration file
- Return type:
str
- Raises:
Exception – If the configuration file is not found
- classmethod from_external_config_file(path, instance_type, system_folders=False)#
Create a new AppContext instance from an external config file.
- Parameters:
path (str) – Path to the config file
instance_type (InstanceType) – Type of instance for which the config file is used
system_folders (bool) – Use system folders rather than user folders
- Returns:
A new AppContext instance
- Return type:
- get_data_file(filename)#
Return the path to a data file.
- Parameters:
filename (str) – Name of the data file
- Returns:
Path to the data file
- Return type:
str
- initialize(instance_type, instance_name, system_folders=False, config_file=None, print_log_header=True)#
Initialize the AppContext instance.
- Parameters:
instance_type (str) – ‘server’ or ‘node’
instance_name (str) – Name of the configuration
system_folders (bool) – Use system folders rather than user folders
config_file (str) – Path to a specific config file. If left as None, OS specific folder will be used to find the configuration file specified by instance_name.
print_log_header (bool) – Print a banner to the log file.
- Return type:
None
- static instance_folders(instance_type, instance_name, system_folders)#
Return OS and instance specific folders for storing logs, data and config files.
- Parameters:
instance_type (InstanceType) – Type of instance that is checked
instance_name (str) – Name of the configuration
system_folders (bool) – Use system folders rather than user folders
- Returns:
Dictionary with Paths to the folders of the log, data and config files.
- Return type:
dict
- property log_file: Path#
Return the path to the log file.
- Returns:
Path to the log file
- Return type:
Path
- log_file_name(type_)#
Return a path to a log file for a given log file type
- Parameters:
type (str) – The type of log file to return.
- Returns:
The path to the log file.
- Return type:
Path
- Raises:
AssertionError – If the configuration manager is not initialized.
- print_log_header()#
Print the log file header.
- Return type:
None
- set_folders(instance_type, instance_name, system_folders)#
Set the folders where the configuration, data and log files are stored.
- Parameters:
instance_type (InstanceType) – Type of instance that is checked
instance_name (str) – Name of the configuration
system_folders (bool) – Whether to use system folders rather than user folders
- Return type:
None
- setup_logging()#
Setup a basic logging mechanism.
Exits if the log file can’t be created.
- Return type:
None
- static type_data_folder(instance_type, system_folders)#
Return OS specific data folder.
- Parameters:
instance_type (InstanceType) – Type of instance that is checked
system_folders (bool) – Use system folders rather than user folders
- Returns:
Path to the data folder
- Return type:
Path