command_interpreter.core
– The core functionality¶
This module implements the core of the command interpreter and any part essential for running it
-
class
vdat.command_interpreter.core.
CommandInterpreter
(command, command_config, selected=None, multiprocessing=False, processes=None)[source]¶ Interpret and execute the command.
See The interpreter section in the documentation for more details
All the custom errors are defined in
vdat.command_interpreter.exceptions
. The ones raised in the constructor are derived from fromCIValidationError
,Parameters: - command : string
command to parse
- command_config : dict
dictionary containing the instructions to execute the
command
. A deep copy is executed- selected : list-like, optional
None or a list of the selected items; if
None
no filtering of the primary files is done; otherwise must be an object supporting the membership test operatorin
.- multiprocessing : bool
run the command using multiprocessing
- processes : int
number of processors to use
Raises: - CINoExeError
if the executable does not exists
- CIParseError
if there is some error when extracting the keywords
- CIKeywordError
for missing keywords or for keywords of wrong type
- CIKeywordTypeError
if the type of the keywords is not among the known ones
-
make_signals
()[source]¶ Get the signals from the
signals
and save them in attributes with the same names. Reimplement this method to use custom signals. Refers to thesignals
documentation for the list and names of signals to implement
-
run
()[source]¶ Collect the files, expand and run the required command
All the custom errors raised here derive from
CIRunError
.Raises: - CICommandFmtError
if the substitution of the command doesn’t work
-
_replace_alias
()[source]¶ If the command configuration has the
is_alias_of
replace the executable name
-
_check_exe
()[source]¶ Check that the executable can be found and replace it with the full path returned by
distutils.spawn.find_executable()
-
_validate_mandatory
()[source]¶ Check that all the mandatory keywords are provided.
If
mandatory
is not found, return without doing anything
-
_validate_primary
()[source]¶ Check that the primary key is present and that, if it has more that one value, only one primary key is present among the command keys
-
_replace_primary
()[source]¶ If the value of
primary
is a string, does nothing. Otherwise find which of the primaries is used in the command and replace ``self.config[‘primary’] with it.Since
_validate_primary
already checks the primaries, this function can assume that the primary is used only once in the command.
-
_key_types
(keys)[source]¶ Scan the keys and check that the interpreter knows how to deal with them.
Parameters: - keys : list of strings
keys extracted from the command
Returns: - primary_func : callable
function to call to get the list of primary files
- keyword_map : dictionary
map non-primary keywords to the function used to handle them
Raises: - CIKeywordTypeError
if the type of the keyword is not known
-
_get_value_as_dict
(key)[source]¶ Get the value of
key
from the configuration. If it’s a string, convert it to a dictionary with two entries:- type:
plain
- value:
value
and re-add it in the configuration dictionary
Parameters: - key : string
key to get
Returns: - value : dictionary
dictionary defining the type
Raises: - CIKeywordError
if
value
is not a dictionary or a string
- type:
-
_filter_selected
()[source]¶ Look for the existence of the
filter_selected
option and check that it is of the correct type and thatselected
is of the correct typeReturns: - filter_func : function
function that accepts one string (one element of the primary list) and returns
True
orFalse
if that element is valid or not