logbookgenerator.utilities package

Submodules

logbookgenerator.utilities.file_handling module

file_handling.py: Contains functions for handling files.

logbookgenerator.utilities.file_handling.create_clean_code_files(coursework_path: Path, clean_code: dict[str, str]) None

Create the clean code files.

Parameters:
  • coursework_path (Path) – Path to the coursework directory.

  • clean_code (dict[str, str]) – The clean code files.

logbookgenerator.utilities.file_handling.load_yaml(yaml_path: Path) dict[str, Any]

Load the YAML file.

Parameters:

yaml_path (Path) – Path to the YAML file.

Returns:

The YAML file as a dictionary.

Return type:

dict[str, Any]

logbookgenerator.utilities.file_handling.save_file(file_path: Path, file_content: str) None

Save the file.

Parameters:
  • file_path (Path) – Path to the file.

  • file_content (str) – Content to save in the file.

logbookgenerator.utilities.validation module

validation.py: Contains functions for validating user input.

logbookgenerator.utilities.validation.validate_date(date: str) str

Validate that the date is in the format YYYY-MM-DD.

Parameters:

date (str) – The date to validate.

Returns:

The validated date.

Return type:

str

Raises:

ValueError – If the date is not in the format YYYY-MM-DD.

logbookgenerator.utilities.validation.validate_input_directory(input_directory: Path) None

Validate that the input directory exists and is not empty.

Parameters:

input_directory (Path) – The input directory to validate.

Raises:
  • FileNotFoundError – If the input directory does not exist.

  • ValueError – If the input directory does not have the expected structure.

Notes

Validates an expected structure of: ` input_directory/ ├── week 1/ |   ├── e01-some_text-some_text.cpp |   ├── l01-some_text-some_text.cpp |   ├── l02-some_text-some_text.cpp |   ├── ... |   └── reflection.md ├── week 2/ |   ├── e01-some_text-some_text.cpp |   ├── l01-some_text-some_text.cpp |   ├── l02-some_text-some_text.cpp |   ├── ... |   └── reflection.md ├── ... └── references.yaml ` If the coursework directory is missing, it’ll cause a warning but still continue. This is the same with the references file. There must be at least one week directory, with at least one file in it, though.

logbookgenerator.utilities.validation.validate_student_id(student_id: str) str

Validate that the student ID is an eight-digit number.

Parameters:

student_id (str) – The student ID to validate.

Returns:

The validated student ID.

Return type:

str

Raises:

ValueError – If the student ID is not an eight-digit number.

logbookgenerator.utilities.validation.validate_year(year: str) str

Validate that the year is a four-digit number.

Parameters:

year (str) – The year to validate.

Returns:

The validated year.

Return type:

str

Raises:

ValueError – If the year is not a four-digit number.

Module contents

Utilities package for the project.