mast_contributor_tools.filename_check package#
Submodules#
mast_contributor_tools.filename_check.fc_app module#
- mast_contributor_tools.filename_check.fc_app.check_filenames(hlsp_name: str, file_list: list[Path], dbFile: str) None[source]#
Recursively check filenames in a directory tree of HLSP products
- mast_contributor_tools.filename_check.fc_app.check_single_filename(file_name: str, hlsp_name: str = '') None[source]#
HLSP filename module CLI driver.
- Parameters:
file_name (str) – File name of an HLSP product to test: for example ‘hlsp_my-hlsp_readme.txt’. This is a string, and does not need to be a real file.
hlsp_name (str, optional) – Name of example HLSP collection. For example, ‘my-hlsp’. If not supplied, the hlsp_name is inferred using the second field of the filename.
- mast_contributor_tools.filename_check.fc_app.get_file_paths(hlsp_path: str, from_file: str = '', search_pattern: str = '*.*', exclude_pattern: str | None = None, max_n: int | None = None) list[Path][source]#
Build a list of filename Paths relative to the given directory.
- Parameters:
hlsp_path (str) – Head of directory containing HLSP collection files. The base directory defaults to the current working directory.
from_file (str, optional) – Path to a text file containing a list of filenames to check, instead of scanning a directory
search_pattern (str, optional) – Search pattern to limit files to test. For example, ‘.fits’ will only return the fits files. Default value is ‘.*’ for all files
exclude_pattern (str, optional) – Search pattern to exclude files from testing. For example, ‘*.png’ will only skip all of the png files.
max_n (int, optional) – Maximum number of files to check, for testing purposes. For example, max_n=10 will only check the first 10 files found.
- Returns:
A list of filename Paths contained within the given directory
- Return type:
list[Path]
mast_contributor_tools.filename_check.fc_db module#
Create and manage an SQLite database for storing results of file checking.
- class mast_contributor_tools.filename_check.fc_db.Hlsp_SQLiteDb(filename: str)[source]#
Bases:
objectCreate an SQLite DB to store results.
- Parameters:
filename (str) – name of the SQLite DB file to be created
- add_fields(elements: list[dict]) None[source]#
Add metadata for each of a filename’s fields to the fields table
Add results of checking mmultiple filename fields to the fields table. Metadata for each field take the form of key:value pairs.
- add_filename(file_record: dict) None[source]#
Add file metadata to the filename table
Add file metadata to the DB in the form of a list of key:value pairs.
- Parameters:
file_record (dict) – File attributes
mast_contributor_tools.filename_check.hlsp_filename module#
The main logic module to check filename compliance
- class mast_contributor_tools.filename_check.hlsp_filename.ExtensionField(value: str)[source]#
Bases:
FilenameFieldAB
- class mast_contributor_tools.filename_check.hlsp_filename.FieldRule[source]#
Bases:
objectRules for filename validation.
This class embodies rules for validating attributes of field names. The approach to validiting field values varies by field. The expressions that validate the version or target fields can be verified at https://regex101.com
- capitalization() str[source]#
Test the captilizaiton: the entire filename must be lowercase. Returns ‘pass’ or ‘fail’ based on results.
- field_verdict() str[source]#
Determine the final verdict for this field: ‘pass’, ‘needs review’ or ‘fail’, determined as the worst of the input scores.
- length(max_length: int) str[source]#
Test if the character count is non-zero and within the limit for that field. Returns ‘pass’ or ‘fail’ based on results.
- match_choice(choice_list: list[str], score_level='lax') str[source]#
Checks value against a list, typically from oif.yaml. Returns ‘pass’ or ‘needs review’ or ‘fail’ based on results. The optional ‘score_level’ argument determines if ‘fail’ or ‘needs review’ is returned (default lax)
- match_multi_choice(choice_list: list[str], score_level='lax') str[source]#
Checks multiple values against a list, typically from oif.yaml. Returns ‘pass’ or ‘needs review’ or ‘fail’ based on results. The optional ‘score_level’ argument determines if ‘fail’ or ‘needs review’ is returned (default lax)
- class mast_contributor_tools.filename_check.hlsp_filename.FilenameFieldAB(field_name: str, field_value: str)[source]#
Bases:
ABCTemplate for Filename Field classes.
Each field of a filename in an HLSP collection will be evaluated for: length, capitalization, content, and often a match against valid values. Each evaluation results in a score, which is one of: - ‘pass’ for no detected problems - ‘fail’ for a detected problem that must be fixed - ‘needs review’ for a possible but non-fatal problem that requires review by MAST Staff
The final verdict of the set of evaluations is determined as the worst of the input scores.
- Parameters:
- class mast_contributor_tools.filename_check.hlsp_filename.FilterField(value: str)[source]#
Bases:
FilenameFieldABA container for attributes of the filename Filtername field.
- class mast_contributor_tools.filename_check.hlsp_filename.GenericField(value: str, id: int)[source]#
Bases:
FilenameFieldABGeneric field concrete class.
Since some filename fields are optional, this class handles the case of fields that are not identifiable with the standard set. In this case the field will be validated for length and capitalization, but not for value.
- class mast_contributor_tools.filename_check.hlsp_filename.HlspField(value: str)[source]#
Bases:
FilenameFieldABA container for attributes of the literal ‘hlsp’ prefix field.
- class mast_contributor_tools.filename_check.hlsp_filename.HlspFileName(filepath: Path, hlsp_name: str)[source]#
Bases:
objectHLSP filename validation
Filenames are composed of fields separated by underscores, except that the last field is really composed of two fields separated by a period. The last part of the last field may also contain a period. Certain fields are further composed of elements, separated by hyphens.
Filenames must have at least 4 and as many as 9 fields to be valid. For valid filenames:
The first two and the last two fields are required
the third from last (N-2) is always required except when the value of N-1 is ‘readme’
Unless all 9 fields are present, or only 4 are present, it is not possible to determine robustly what the other fields (if present) contain.
- Parameters:
- Raises:
ValueError – If the number of fields falls outside the limits.
- evaluate_fields()[source]#
Evaluate attributes of each field
Returns:#
List of result dictionaries for each field
- class mast_contributor_tools.filename_check.hlsp_filename.HlspNameField(value: str, ref_name: str)[source]#
Bases:
FilenameFieldABA container for attributes of the HLSP name field.
- class mast_contributor_tools.filename_check.hlsp_filename.InstrumentField(value: str)[source]#
Bases:
FilenameFieldABA container for attributes of the filename Instrument field.
- class mast_contributor_tools.filename_check.hlsp_filename.MissionField(value: str)[source]#
Bases:
FilenameFieldABA container for attributes of the filename Mission (or observatory) field.
- class mast_contributor_tools.filename_check.hlsp_filename.ProductField(value: str)[source]#
Bases:
FilenameFieldABA container for attributes of the filename ProductType field.
- class mast_contributor_tools.filename_check.hlsp_filename.TargetField(value: str)[source]#
Bases:
FilenameFieldABA container for attributes of the filename TargetName field.