Пример #1
0
def get_variable_tracking(shell=None):
    """Creates a **read-only** tracking manager for the standard global and
    local configuration files.

    Parameters
    ----------
    shell : .shell.Shell, optional
        The shell which is used in the current environment, used to retrieve
        the local configuration directory.

    Returns
    -------
    .settings.variable_tracking.VariableTracking
        The tracking handler engine.
        The configuration files are opened **read-only**.
    """
    if shell and shell.is_envprobe_capable:
        local_config_file = config_file.ConfigurationFile(
            os.path.join(shell.configuration_directory,
                         variable_tracking.get_tracking_file_name()),
            variable_tracking.VariableTracking.config_schema_local,
            read_only=True)
    else:
        local_config_file = None

    global_config_file = config_file.ConfigurationFile(
        os.path.join(settings.get_configuration_directory(),
                     variable_tracking.get_tracking_file_name()),
        variable_tracking.VariableTracking.config_schema_local,
        read_only=True)

    return variable_tracking.VariableTracking(global_config_file,
                                              local_config_file)
Пример #2
0
def get_variable_information_manager(variable_name, read_only=True):
    """Creates the extended information attribute manager for environment
    variables based on the requested variable's name, using the locally
    installed community descriptions data as source.

    Parameters
    ----------
    varable_name : str
        The name of the variable to configure.
    read_only : bool
        If ``True``, the associated file will be opened read-only and not saved
        at exit.

    Returns
    -------
    envprobe.settings.variable_information.VariableInformation
        The configuration handler engine.
        Access to the underlying file is handled automatically through this
        instance.
    """
    basedir = os.path.join(_local_data_root(),
                           variable_information.get_variable_directory_name())

    return variable_information.VariableInformation(
        config_file.ConfigurationFile(
            os.path.join(basedir,
                         variable_information.get_information_file_name(
                             variable_name)),
            variable_information.VariableInformation.config_schema,
            read_only=read_only)
    )
Пример #3
0
def generate_variable_information_managers():
    """Generates the manager objects for all datafiles that are present in the
    data directory for variable information storage.

    These managers are **read-only**.
    """
    basedir = os.path.join(_local_data_root(),
                           variable_information.get_variable_directory_name())

    try:
        if not os.path.isdir(basedir):
            return None
    except OSError:
        return None

    for file in os.listdir(basedir):
        if not file.endswith(".json"):
            continue

        yield variable_information.VariableInformation(
            config_file.ConfigurationFile(
                os.path.join(basedir, file),
                variable_information.VariableInformation.config_schema,
                read_only=True)
        )
Пример #4
0
def get_snapshot(snapshot_name, read_only=True):
    """Creates the snapshot instance for the snapshot of the given name.

    Parameters
    ----------
    snapshot_name : str
        The name of the snapshot to load or create.
    read_only : bool
        If ``True``, the file will be opened read-only and not saved at exit.

    Returns
    -------
    .settings.snapshot.Snapshot
        The snapshot manager object.
        Access to the underlying file is handled automatically through this
        instance.
    """
    basedir = os.path.join(settings.get_configuration_directory(),
                           snapshot.get_snapshot_directory_name())
    return snapshot.Snapshot(
        config_file.ConfigurationFile(
            os.path.join(basedir,
                         snapshot.get_snapshot_file_name(snapshot_name)),
            snapshot.Snapshot.config_schema,
            read_only=read_only)
    )
Пример #5
0
def get_storage_configuration(read_only=True):
    """Returns the configuration manager for the metainformation about the
    local storage.
    """
    return MetaConfiguration(
        config_file.ConfigurationFile(
            os.path.join(_local_data_root(),
                         get_description_config_file_name()),
            MetaConfiguration.config_schema,
            read_only=read_only)
    )