Input/Output

import kloch
import kloch.filesyntax
kloch.get_all_profile_file_paths(locations: List[Path] | None = None) List[Path]

Get all the environment-profile file paths as registred by the user.

Parameters:

locations – list of filesystem path to directory that might exist

kloch.get_profile_file_path(profile_id: str, profile_locations: List[Path] | None = None) List[Path]

Get the filesystem location to the profile(s) with the given name.

Parameters:
  • profile_id – identifier that must match returned profiles.

  • profile_locations – list of filesystem path to potential existing directories containing profiles.

Returns:

list of filesystem path to existing files . Might be empty.

kloch.serialize_profile(profile: EnvironmentProfile, profile_locations: List[Path] | None = None) str

Convert the instance to a serialized dictionnary intended to be written on disk.

kloch.write_profile_to_file(profile: EnvironmentProfile, file_path: Path, profile_locations: List[Path] | None = None, check_valid_id: bool = True) Path

Convert the instance to a serialized file on disk.

Parameters:
  • profile – profile instance to write to disk

  • file_path – filesystem path to a file that might exist. parent location is expected to exist.

  • check_valid_id – if True, ensure the identifier of the profile is unique among all profile_locations

  • profile_locations – list of filesystem path to potential existing directories containing profiles.

kloch.read_profile_from_file(file_path: Path, profile_locations: List[Path] | None = None) EnvironmentProfile

Generate an instance from a serialized file on disk.

Raises error if the file is not built properly.

Parameters:
  • file_path – filesystem path to an existing valid profile file.

  • profile_locations – list of filesystem path to potential existing directories containing profiles.

kloch.read_profile_from_id(profile_id: str, profile_locations: List[Path] | None = None) EnvironmentProfile

Generate a profile instance from a serialized file on disk retrieved using the given identifier.

Raises error if the profile file is not built properly.

This a convenient function wrapping read_profile_from_file() and get_profile_file_path() and assuming that no profile with the same identifier exist in the locations.

Parameters:
  • profile_id – identifier that must match the profile.

  • profile_locations – list of filesystem path to potential existing directories containing profiles.

Returns:

a profile instance

kloch.filesyntax.is_file_environment_profile(file_path: Path) bool

Return True if the given file is an Environment Profile.

Parameters:

file_path – filesystem path to an existing file