Package pyffi :: Module spells :: Class Spell
[hide private]
[frames] | no frames]

Class Spell

source code

object --+
         |
        Spell
Known Subclasses:

Spell base class. A spell takes a data file and then does something useful with it. The main entry point for spells is recurse, so if you are writing new spells, start with reading the documentation with recurse.
Instance Methods [hide private]
 
__init__(self, toaster=None, data=None, stream=None)
Initialize the spell data.
source code
bool
_datainspect(self)
This is called after pyffi.object_models.FileFormat.Data.inspect has been called, and before pyffi.object_models.FileFormat.Data.read is called.
source code
bool
datainspect(self)
This is called after pyffi.object_models.FileFormat.Data.inspect has been called, and before pyffi.object_models.FileFormat.Data.read is called.
source code
bool
_branchinspect(self, branch)
Check if spell should be cast on this branch or not, based on exclude and include options passed on the command line.
source code
bool
branchinspect(self, branch)
Like _branchinspect, but for customization: can be overridden to perform an extra inspection (the default implementation always returns True).
source code
 
recurse(self, branch=None)
Helper function which calls _branchinspect and branchinspect on the branch, if both successful then branchentry on the branch, and if this is succesful it calls recurse on the branch's children, and once all children are done, it calls branchexit.
source code
bool
dataentry(self)
Called before all blocks are recursed.
source code
bool
branchentry(self, branch)
Cast the spell on the given branch.
source code
 
branchexit(self, branch)
Cast a spell on the given branch, after all its children, grandchildren, have been processed, if branchentry returned True on the given branch.
source code
 
dataexit(self)
Called after all blocks have been processed, if dataentry returned True.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
bool
toastentry(cls, toaster)
Called just before the toaster starts processing all files.
source code
 
toastexit(cls, toaster)
Called when the toaster has finished processing all files.
source code
 
get_toast_stream(cls, toaster, filename, test_exists=False)
Returns the stream that the toaster will write to.
source code
Class Variables [hide private]
  data = None
The pyffi.object_models.FileFormat.Data instance this spell acts on.
  stream = None
The current file being processed.
  toaster = None
The Toaster instance this spell is called from.
  changed = False
Whether the spell changed the data.
  READONLY = True
A bool which determines whether the spell is read only or not.
  SPELLNAME = None
A str describing how to refer to the spell from the command line.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, toaster=None, data=None, stream=None)
(Constructor)

source code 
Initialize the spell data.
Parameters:
Overrides: object.__init__

_datainspect(self)

source code 
This is called after pyffi.object_models.FileFormat.Data.inspect has been called, and before pyffi.object_models.FileFormat.Data.read is called.
Returns: bool
True if the file must be processed, False otherwise.

datainspect(self)

source code 
This is called after pyffi.object_models.FileFormat.Data.inspect has been called, and before pyffi.object_models.FileFormat.Data.read is called. Override this function for customization.
Returns: bool
True if the file must be processed, False otherwise.

_branchinspect(self, branch)

source code 
Check if spell should be cast on this branch or not, based on exclude and include options passed on the command line. You should not need to override this function: if you need additional checks on whether a branch must be parsed or not, override the branchinspect method.
Parameters:
Returns: bool
True if the branch must be processed, False otherwise.

branchinspect(self, branch)

source code 
Like _branchinspect, but for customization: can be overridden to perform an extra inspection (the default implementation always returns True).
Parameters:
Returns: bool
True if the branch must be processed, False otherwise.

recurse(self, branch=None)

source code 

Helper function which calls _branchinspect and branchinspect on the branch, if both successful then branchentry on the branch, and if this is succesful it calls recurse on the branch's children, and once all children are done, it calls branchexit.

Note that _branchinspect and branchinspect are not called upon first entry of this function, that is, when called with data as branch argument. Use datainspect to stop recursion into this branch.

Do not override this function.

Parameters:

dataentry(self)

source code 

Called before all blocks are recursed. The default implementation simply returns True. You can access the data via data, and unlike in the datainspect method, the full file has been processed at this stage.

Typically, you will override this function to perform a global operation on the file data.

Returns: bool
True if the children must be processed, False otherwise.

branchentry(self, branch)

source code 

Cast the spell on the given branch. First called with branch equal to data's children, then the grandchildren, and so on. The default implementation simply returns True.

Typically, you will override this function to perform an operation on a particular block type and/or to stop recursion at particular block types.

Parameters:
Returns: bool
True if the children must be processed, False otherwise.

branchexit(self, branch)

source code 

Cast a spell on the given branch, after all its children, grandchildren, have been processed, if branchentry returned True on the given branch.

Typically, you will override this function to perform a particular operation on a block type, but you rely on the fact that the children must have been processed first.

Parameters:

dataexit(self)

source code 

Called after all blocks have been processed, if dataentry returned True.

Typically, you will override this function to perform a final spell operation, such as writing back the file in a special way, or making a summary log.

toastentry(cls, toaster)
Class Method

source code 

Called just before the toaster starts processing all files. If it returns False, then the spell is not used. The default implementation simply returns True.

For example, if the spell only acts on a particular block type, but that block type is excluded, then you can use this function to flag that this spell can be skipped. You can also use this function to initialize statistics data to be aggregated from files, to initialize a log file, and so.

Parameters:
  • toaster (Toaster) - The toaster this spell is called from.
Returns: bool
True if the spell applies, False otherwise.

toastexit(cls, toaster)
Class Method

source code 
Called when the toaster has finished processing all files.
Parameters:
  • toaster (Toaster) - The toaster this spell is called from.

get_toast_stream(cls, toaster, filename, test_exists=False)
Class Method

source code 
Returns the stream that the toaster will write to. The default implementation calls toaster.get_toast_stream, but spells that write to different file(s) can override this method.

Class Variable Details [hide private]

changed

Whether the spell changed the data. If True, the file will be written back, otherwise not.
Value:
False

READONLY

A bool which determines whether the spell is read only or not. Default value is True. Override this class attribute, and set to False, when subclassing a spell that must write files back to the disk.
Value:
True

SPELLNAME

A str describing how to refer to the spell from the command line. Override this class attribute when subclassing.
Value:
None