Skip to content

hertzforge.io.data_folder

data_folder

The data folder control runs are kept in, and deleting a run from it.

The control service writes each run's folder under its data folder (docs/run-folder.md): the folder HERTZFORGE_DATA_ROOT names, else Hertzforge_Data in the home folder. data_root resolves it by the same rule, so the analysis service, started beside the control service with the same environment, names the same folder.

delete_run is the one place a run is deleted. It removes a run folder, and with it the project file the folder was converted to (<run name>.hforge inside it, run_convert.default_output), and only ever a folder that is a run folder inside the data folder, reached without a link, whose run has ended and whose project file is not open. plan_delete makes every check and deletes nothing, so a confirmation can name what would go.

Classes:

Name Description
RunDeleteRefused

A run that is not deleted, and why: code names the refusal, the

RunDelete

What deleting a run removes: the run folder, and the project file

Functions:

Name Description
data_root

The data folder, as the control service resolves it: the folder

data_root_source

Where the data folder comes from: environment when

plan_delete

What deleting the run in folder would remove, after every check

delete_run

Delete the run in folder: its folder, and the project file it was

Classes

RunDeleteRefused

RunDeleteRefused(code: str, message: str)

Bases: Exception

A run that is not deleted, and why: code names the refusal, the message says it in words a person can act on. Nothing was deleted.

RunDelete dataclass

RunDelete(folder: str, project_file: str, project_file_exists: bool, complete: bool = True)

What deleting a run removes: the run folder, and the project file it was converted to, which lies inside it.

Functions:

data_root

data_root() -> str

The data folder, as the control service resolves it: the folder HERTZFORGE_DATA_ROOT names, used as it is (an empty value is unset), else Hertzforge_Data in the home folder, else in the working folder when there is no home folder.

Returns:

Type Description
str

The folder's absolute path. It need not exist yet.

data_root_source

data_root_source() -> str

Where the data folder comes from: environment when HERTZFORGE_DATA_ROOT names it, default otherwise.

plan_delete

plan_delete(folder: str | PathLike, root: str | PathLike | None = None, open_files: Iterable[str | PathLike] = (), not_live: bool = False) -> RunDelete

What deleting the run in folder would remove, after every check delete_run makes; nothing is deleted.

Parameters:

Name Type Description Default
folder str or PathLike

The run folder, or its run.json.

required
root str or PathLike

The data folder; data_root() when omitted.

None
open_files iterable of path-like

Files open now (the open project's file, the files its arrays are mapped from): a run holding one is not deleted.

()
not_live bool

True when the caller has established, from the control service, that no live run is recording into folder: only then is a run whose run.json does not say it is complete (one that did not end cleanly) deleted. False, the default, refuses it, as a run that may still be going.

False

Returns:

Type Description
RunDelete

The folder and its project file.

Raises:

Type Description
RunDeleteRefused

not_found when there is no such folder; outside_data_folder when it is not inside the data folder (the data folder itself included); link when the folder, or a folder on the way to it from the data folder, is a link or a junction; not_a_run_folder when it holds no run.json of the run folder schema; link_inside when anything inside it is a link or a junction; incomplete when its run.json does not say the run is complete (the run is still going, or did not end cleanly) and not_live is not true; open when a file inside it is open.

delete_run

delete_run(folder: str | PathLike, root: str | PathLike | None = None, open_files: Iterable[str | PathLike] = (), not_live: bool = False) -> RunDelete

Delete the run in folder: its folder, and the project file it was converted to inside it, after the checks of plan_delete.

Parameters:

Name Type Description Default
folder str | PathLike

As plan_delete takes them.

required
root str | PathLike

As plan_delete takes them.

required
open_files str | PathLike

As plan_delete takes them.

required
not_live str | PathLike

As plan_delete takes them.

required

Returns:

Type Description
RunDelete

What was deleted.

Raises:

Type Description
RunDeleteRefused

As plan_delete refuses; nothing is deleted then.

OSError

When the operating system refuses part of the delete; what it could not delete is left.