Helpers functions for Commands¶
Detailed description¶
This module gives objects to manage the execution.
LogicalUnit — Files manipulations¶
The LogicalUnitFile helps to open/close files from Fortran, C++ or
Python without conflict.
A convenient context manager ReservedUnitUsed allows to
automatically open/close reserved units in case of writing in a such unit in
a Python command.
Note
It may be interesting to refactor that in C++ to simplify the interface.
- class code_aster.Helpers.LogicalUnit.LogicalUnitFile(unit, filename, action, typ, access, to_register=True)[source]¶
Bases:
objectThis class defines a file associated to a fortran logical unit
- classmethod open(filename, typ=0, access=0)[source]¶
Open a LogicalUnitFile by name to be available in fortran.
- Parameters:
filename (Path|str) – Path of the file.
typ (FileType) – Type of the file.
access (FileAccess) – Type of access.
- Returns:
New logical unit.
- Return type:
- classmethod new_free(filename=None, typ=0, access=0)[source]¶
Factory that returns a new free LogicalUnitFile for the given name.
- Parameters:
filename (Path|str) – Path of the file. If empty, it will be automatically named using the unit number.
new (bool) – True means that this is a new file. The file is removed if it exists. False means that the file may exist.
ascii (bool) – If True the file is opened in text mode.
- Returns:
New logical unit.
- Return type:
- classmethod register(unit, filename, action, typ=0, access=0)[source]¶
Register a logical unit to the fortran manager.
- Parameters:
unit (int) – Logical unit number.
filename (Path|str) – Path of the file. None or empty means to be named automatically ‘fort.<unit>’.
action (Action) – Type of action for registering.
typ (FileType) – Type of the file.
access (FileAccess) – Type of access.
- property unit¶
Attributes that holds the logical unit associated to this file
- property filename¶
Attributes that holds the file name
- classmethod filename_from_unit(unit)[source]¶
Return the filename associated to a unit number.
- Parameters:
unit (int) – Number of a logical unit.
- Returns:
Filename of the logical unit or ‘fort.<unit>’ if unknown or None if unit=6.
- Return type:
str
- classmethod from_number(unit)[source]¶
Return the logical unit associated to a unit number.
- Parameters:
unit (int) – Number of a logical unit.
- Returns:
- Registered objects for this number. None
otherwise.
- Return type:
- class code_aster.Helpers.LogicalUnit.ReservedUnitUsed(*units)[source]¶
Bases:
objectContext manager for usage of reserved logical units.
These units are released when entering the context and register again on exit.
- Parameters:
units (int, [int...]) – One or more unit to manage.
- class code_aster.Helpers.LogicalUnit.DefineUnitFile[source]¶
Bases:
ExecuteCommandExecute legacy operator DEFI_FICHIER.
debugging — Debugging utilities¶
This module defines some convenient utilities that are not intended to be used in production.
Check for dependency between datastructures¶
Use the --hook_post_exec command line argument to enable a hook called
after each command.
For example: use in the .export file:
A args --hook_post_exec=code_aster.Helpers.debugging.check_dependencies
- class code_aster.Helpers.debugging.DataStructureFilter(current, dump)[source]¶
Bases:
objectThis object store the path to DataStructure objects that are referenced in a dump.
- Parameters:
current (str) – Name of the current result.
dump (str) – Text dump of a DataStructure.
- set_parent_context(context)[source]¶
Set the parent context.
If the checker is directly called on a keyword (without checking the command itself) the values defined upper may be required to evaluate blocks conditions but the parent context has not been filled.
This parent context could be an optional argument in visit* functions.
- code_aster.Helpers.debugging.dump_datastructure(obj)[source]¶
Return a dump (IMPR_CO) of a DataStructure.
- Parameters:
obj (DataStructure) – Object to be dumped.
- Returns:
Output of IMPR_CO/debugPrint.
- Return type:
str
- code_aster.Helpers.debugging.track_dependencies(inst, keywords)[source]¶
Hook that tracks commands dependencies.
- Parameters:
inst (function) – the ExecuteCommand instance.
keywords (dict) – User keywords.
- code_aster.Helpers.debugging.check_dependencies(inst, _)[source]¶
Hook that check dependencies
- Parameters:
inst (function) – the ExecuteCommand instance.
- code_aster.Helpers.debugging.register_context(ctxt, storage)[source]¶
Register context as existing objects.
- Parameters:
ctxt (dict) – Context/dict containing objects to be registered.
storage (dict) – Dict that stores the type of each object.