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.FileType[source]

Bases: object

Enumeration for file type.

static name(value)[source]

Return type as string.

static value(name)[source]

Return type as string.

class code_aster.Helpers.LogicalUnit.FileAccess[source]

Bases: object

Enumeration for file access.

static name(value)[source]

Return type as string.

static value(name)[source]

Return type as string.

class code_aster.Helpers.LogicalUnit.Action[source]

Bases: object

Enumeration for action.

static name(value)[source]

Return type as string.

static value(name)[source]

Return type as string.

class code_aster.Helpers.LogicalUnit.LogicalUnitFile(unit, filename, action, typ, access, to_register=True)[source]

Bases: object

This class defines a file associated to a fortran logical unit

__init__(unit, filename, action, typ, access, to_register=True)[source]
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:

LogicalUnitFile

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:

LogicalUnitFile

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

release()[source]

Close and free a logical unit.

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:

LogicalUnitFile

classmethod _register(fileobj)[source]

Register a logical unit.

classmethod release_from_number(unit, to_register=True)[source]

Release a logical unit from its number.

Parameters:
  • unit (int) – Number of logical unit to release.

  • to_register (bool) – Boolean to avoid calling of register.

classmethod _get_free_number()[source]

Return the next free unit.

class code_aster.Helpers.LogicalUnit.ReservedUnitUsed(*units)[source]

Bases: object

Context 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.

__init__(*units)[source]
class code_aster.Helpers.LogicalUnit.DefineUnitFile[source]

Bases: ExecuteCommand

Execute legacy operator DEFI_FICHIER.

create_result(keywords)[source]

Initialize the result.

Parameters:

keywords (dict) – Keywords arguments of user’s keywords.

exec_(keywords)[source]

Execute the command.

Parameters:

keywords (dict) – User’s keywords.

post_exec(keywords)[source]

Execute the command.

Parameters:

keywords (dict) – User’s keywords.

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: object

This 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.

__init__(current, dump)[source]

Initialization

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.

visitCommand(step, userDict=None)[source]

Visit a Command object

visitMacro(step, userDict=None)[source]

Visit a Macro object

visitBloc(step, userDict=None)[source]

Visit a Bloc object

visitFactorKeyword(step, userDict=None)[source]

Visit a FactorKeyword object

visitSimpleKeyword(step, skwValue)[source]

Visit a SimpleKeyword object

_visitComposite(step, userDict=None)[source]

Visit a composite object (containing BLOC, FACT and SIMP objects)

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.

class code_aster.Helpers.debugging.DebugArgs[source]

Bases: object

Debugging helper

raised = False

to be raised only once

Type:

bool

filename = 'debug_trace.pick'

name of the pickle file

classmethod pickle_on_error(method)[source]

Decorator to pickle the args in case of error.

classmethod reset()[source]

Reset state

class code_aster.Helpers.debugging.DebugChrono[source]

Bases: object

Helper to measure elapsed time.

classmethod measure(title)[source]

Measure elapsed time.

classmethod save(filename)[source]

Save data into a pickle file.