nudb_use.paths package¶
nudb_use.paths.latest module¶
Location utilities for discovering the latest shared NUDB datasets.
- get_file_short_name(p)¶
Get short name of a file, from a path.
- Parameters:
p (
Path) – Path that potentially includes period/version information.- Returns:
File short name without period and version fragments.
- Return type:
str
Return the newest shared dataset path.
This is a convenience wrapper around latest_shared_paths that returns the most recent dataset entry (by sorted key).
- Parameters:
dataset_name (
str) – Optional dataset identifier to filter available paths before selecting the newest entry.- Returns:
The dataset key and its latest path.
- Return type:
tuple[str, Path]
Find the last shared version and period of each stem in the shared folder.
- Parameters:
dataset_name (
str) – Optional dataset identifier. When provided only the path for that dataset is returned.- Returns:
Mapping of dataset stems to their newest paths, or a single Path when dataset_name is supplied.
- Return type:
dict[str, Path] | Path
nudb_use.paths.path_parse module¶
Helper for parsing information out of NUDB file paths.
- get_periods_from_path(path)¶
Get start- and end- dates from path-string.
This function analyzes the filename portion of the given path, extracting up to two period components that appear after the last ‘_p’ in the stem.
- Parameters:
path (
str|Path) – File path as a string or Path object from which to extract period info.- Returns:
A single period (as string or datetime) or a tuple of two periods, depending on how many fragments are found and whether datetime conversion is requested.
- Return type:
None | datetime.date | tuple[datetime.date, datetime.date]
- Raises:
ValueError – If there is no period parts in the path.
nudb_use.paths.path_utils module¶
Utilities for manipulating NUDB file paths and metadata locations.
- metadatapath_from_path(path)¶
Generate a path for JSON metadata file corresponding to input file.
- Parameters:
path (
str|Path) – Path to input file.- Returns:
Path to the metadata JSON file for the input file.
- Return type:
Path
- next_path_mkdir(path)¶
Generate a bumped version path for a new file version, including creating any missing folders.
- Parameters:
path (
str|Path) – Current path as a string.- Returns:
Path to the newly created directory.
- Return type:
Path
nudb_use.paths.paths_validate module¶
- exception SsbPathValidationError¶
Bases:
ExceptionIf there is something wrong with a file path according to SSB naming standard.
- generate_validation_report_dont_print(validation_results)¶
Generate a standard validation report.
This function takes a list of ValidationResult objects and creates a NamingStandardReport instance.
- Parameters:
validation_results (
list[ValidationResult]) – A list of ValidationResult objects that contain the outcomes of the name standard checks.- Returns:
- An instance of NamingStandardReport containing
the validation results.
- Return type:
NamingStandardReport
- validate_path(path, raise_errors=False)¶
Validate a single path according to the naming standard from SSB.
- Parameters:
path (
str|Path) – A single path to a file.raise_errors (
bool) – If you want the function to raise errors instead of returning a bool.
- Returns:
- If we are not raising errors: the function returns True if no errors where found,
False if we found errors.s
- Return type:
bool
- validate_paths(paths, raise_errors=False)¶
Validate a list of paths, accoring to the naming standard of SSB.
- Parameters:
paths (
list[str|Path]) – a list of paths to files you want to check.raise_errors (
bool) – If you want the function to raise the validation errors it finds as errors.
- Returns:
- If we are not raising errors: the function returns True if no errors where found,
False if we found at least one error, on one of the files.
- Return type:
bool