thenamelisttool.util¶
Utility methods widely used in the various TNT utilities.
Functions¶
- thenamelisttool.util.colorise_diff(lines)[source]¶
Colorise the lines of any kind of difflib outputs.
- thenamelisttool.util.compose_namelist(recipe_filename, sourcenam_directory=None, suffix='.nam', sorting=0, squeeze=False, fhoutput=None)[source]¶
Compose a namelist from a recipe_filename. For the syntax of recipe, see template recipe.
- Parameters:
recipe_filename – The name of the recipe/directive YAML file
sourcenam_directory – path to directory in which to look for source namelists
suffix – suffix to add to generated namelist: output name is ./recipe_basename[suffix]
sorting – Sorting option (from bronx.datagrip.namelist): NO_SORTING; FIRST_ORDER_SORTING => sort all keys within blocks; SECOND_ORDER_SORTING => sort only within indexes or attributes of the same key, within blocks.
squeeze – squeeze the namelist: remove empty blocks.
fhoutput – a file object where the result is written (if None, a new file named basename(recipe_filename) is created).
- thenamelisttool.util.namelist_read_and_sort(namfile)[source]¶
Read a namelist and return it as a sorted string.
- thenamelisttool.util.process_namelist(filename, directives, sorting=0, blocks_ref=None, in_place=False, outfilename=None, doctor=False, keep_index=False, squeeze=False)[source]¶
For the syntax of keys & blocks arguments, please refer to the according functions.
The order of processing is that of the arguments. As movings are done first, check consistency.
If macros is not None, it can contain the macros a.k.a. values to be replaced, e.g.: {‘NPROC’:8, ‘substrA’:None} will replace all NPROC values by 8 and will let substrA untouched.
Other options:
- Parameters:
in_place – if True, the namelist is written back in the same file; else (default), the target namelist is suffixed with ‘.tnt’ if not given as outfilename.
outfilename – target file for out namelist
sorting – Sorting option (from bronx.datagrip.namelist): NO_SORTING; FIRST_ORDER_SORTING => sort all keys within blocks; SECOND_ORDER_SORTING => sort only within indexes or attributes of the same key, within blocks.
blocks_ref – if not None, defines the path for a reference namelist to which the set of blocks is asserted to be equal.
doctor – if True, try to convert value to DOCTOR norm according type for moved keys
keep_index – if True, moved keys in identical block keep the original index of key in block (except a sorting is requested later on.
squeeze – squeeze the namelist: remove empty blocks.
- thenamelisttool.util.process_tnt_stack(directive, sorting=2)[source]¶
Apply directive to the current working directory.
- Parameters:
directive (TntStackDirective) – The tntstack directive to apply
sorting – Sorting option (from bronx.datagrip.namelist): NO_SORTING; FIRST_ORDER_SORTING => sort all keys within blocks; SECOND_ORDER_SORTING => sort only within indexes or attributes of the same key, within blocks.