devctrl.task.preset.TaskPresetManager#
- class TaskPresetManager(task_preset_dir: str)[source]#
Bases:
objectManages a preset directory, which contains task preset files.
Each file contains one
TaskPreset(saved using.TaskPreset.save_yaml). The file name may be anything, but should ideally be the task preset name as sanitized filename.Files are always immediately synchronized, if a preset is changed using add_preset (with
override=True), the file is updated as well. Presets obtained using get_presets must not be modified, as these changes will be lost.Initialize the manager, read all preset files.
If the preset directory does not exist, it is created.
- Parameters:
task_preset_dir – The preset directory path.
- Raises:
RuntimeError – If the directory can not be created or can not be written to.
Methods
Add a new preset and write the associated file.
Delete a preset and its associated file.
Return list of all presets, optionally filtered for a specific task type.
Read and return the preset in the file.
Read and return all presets in the preset directory.
- __annotations__ = {'_presets': 'dict[str, TaskPreset]'}#
- __dict__ = mappingproxy({'__module__': 'devctrl.task.preset', '__firstlineno__': 33, '__doc__': 'Manages a preset directory, which contains task preset files.\n\nEach file contains one :py:class:`.TaskPreset` (saved using `.TaskPreset.save_yaml`).\nThe file name may be anything, but should ideally be the task preset name as sanitized filename.\n\nFiles are always immediately synchronized, if a preset is changed using add_preset (with ``override=True``), the file is updated as well.\nPresets obtained using get_presets must not be modified, as these changes will be lost.\n', '__init__': <function TaskPresetManager.__init__>, 'get_presets': <function TaskPresetManager.get_presets>, 'add_preset': <function TaskPresetManager.add_preset>, 'delete_preset': <function TaskPresetManager.delete_preset>, 'read_presets': <staticmethod(<function TaskPresetManager.read_presets>)>, 'read_preset': <staticmethod(<function TaskPresetManager.read_preset>)>, '__static_attributes__': ('_preset_dir', '_presets'), '__dict__': <attribute '__dict__' of 'TaskPresetManager' objects>, '__weakref__': <attribute '__weakref__' of 'TaskPresetManager' objects>, '__annotations__': {'_presets': 'dict[str, TaskPreset]'}})#
- __firstlineno__ = 33#
- __init__(task_preset_dir: str)[source]#
Initialize the manager, read all preset files.
If the preset directory does not exist, it is created.
- Parameters:
task_preset_dir – The preset directory path.
- Raises:
RuntimeError – If the directory can not be created or can not be written to.
- __module__ = 'devctrl.task.preset'#
- __static_attributes__ = ('_preset_dir', '_presets')#
- __weakref__#
list of weak references to the object
- _presets: dict[str, TaskPreset]#
- add_preset(task: Task, name: str, key: str | None = None, filename: str | None = None, override: bool = False) None[source]#
Add a new preset and write the associated file.
- Parameters:
task – The task to save as preset
name – The name of the preset
key – The key of the task, must be unique. Defaults to “<task type name>.<preset name>”.
filename – The filename to use, must be unique. Defaults to sanitized <key> with spaces replaced by underscores.
override – Whether to override existing keys.
- Raises:
KeyError – If the key already exists and
override==False.
- delete_preset(key: str)[source]#
Delete a preset and its associated file.
- Parameters:
key – The preset to delete.
- Raises:
KeyError – If the key does not exist.
- get_presets(filter_task_class: type[Task] | None = None) list[TaskPreset][source]#
Return list of all presets, optionally filtered for a specific task type.
- Parameters:
filter_task_class – If given, only return presets for the given task type.
- static read_preset(preset_file: str, loader=<class 'yaml.loader.Loader'>) TaskPreset[source]#
Read and return the preset in the file.
- Parameters:
preset_file – Preset file to load.
loader – Yaml loader to use.
- Returns:
Task preset
- Raises:
FileNotFoundError – If the file is not found.
ValueError – If the contents of the file are invalid.
- static read_presets(preset_dir: str, loader=<class 'yaml.loader.Loader'>) dict[str, TaskPreset][source]#
Read and return all presets in the preset directory.
All yaml files are loaded, the
- Parameters:
preset_dir – Preset directory
loader – Yaml loader to use.
- Returns:
Dictionary of presets with
key: TaskPreset