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

Class Toaster

source code

object --+
         |
        Toaster
Known Subclasses:

Toaster base class. Toasters run spells on large quantities of files. They load each file and pass the data structure to any number of spells.
Nested Classes [hide private]
  FILEFORMAT
The file format class (a subclass of pyffi.object_models.FileFormat).
Instance Methods [hide private]
 
__init__(self, spellclass=None, options=None, spellnames=None, logger=None)
Initialize the toaster.
source code
 
_update_options(self)
Synchronize some fields with given options.
source code
 
_update_spellclass(self)
Update spell class from given list of spell names.
source code
 
msg(self, message)
Write log message with logger.info, taking into account indent.
source code
 
msgblockbegin(self, message)
Acts like msg, but also increases indent after writing the message.
source code
 
msgblockend(self, message=None)
Acts like msg, but also decreases indent before writing the message, but if the message argument is None, then no message is printed.
source code
 
is_admissible_branch_class(self, branchtype)
Helper function which checks whether a given branch type should have spells cast on it or not, based in exclude and include options.
source code
 
cli(self)
Command line interface: initializes spell classes and options from the command line, and run the toast method.
source code
 
inspect_filename(self, filename)
Returns whether to toast a filename or not, based on skip_regexs and only_regexs.
source code
 
toast(self, top)
Walk over all files in a directory tree and cast spells on every file.
source code
 
toast_archives(self, top)
Toast all files in all archives.
source code
 
_toast(self, stream)
Run toaster on particular stream and data.
source code
tuple of three strs
get_toast_head_root_ext(self, filename)
Get the name of where the input file filename would be written to by the toaster: head, root, and extension.
source code
 
get_toast_stream(self, filename, test_exists=False)
Calls get_toast_head_root_ext(filename) to determine the name of the toast file, and return a stream for writing accordingly.
source code
 
write(self, stream, data)
Writes the data to data and raises an exception if the write fails, but restores file if fails on overwrite.
source code
 
writepatch(self, stream, data)
Creates a binary patch for the updated file.
source code

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

Static Methods [hide private]
 
parse_inifile(option, opt, value, parser, toaster=None)
Initializes spell classes and options from an ini file.
source code
Class Variables [hide private]
  SPELLS = []
List of all available pyffi.spells.Spell classes.
  EXAMPLES = ''
Some examples which describe typical use of the toaster.
  ALIASDICT = {}
Dictionary with aliases for spells.
  DEFAULT_OPTIONS = {'applypatch': False, 'archives': False, 'ar...
List of spell classes of the particular Toaster instance.
  options = {}
The options of the toaster, as dict.
  spellnames = []
A list of the names of the spells.
  top = ''
Name of the top folder to toast.
  indent = 0
An int which describes the current indentation level for messages.
  logger = logging.getLogger("pyffi.toaster")
A logging.Logger for toaster log messages.
  include_types = []
Tuple of types corresponding to the include key of options.
  exclude_types = []
Tuple of types corresponding to the exclude key of options.
  only_regexs = []
Tuple of regular expressions corresponding to the only key of options.
  skip_regexs = []
Tuple of regular expressions corresponding to the skip key of options.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, spellclass=None, options=None, spellnames=None, logger=None)
(Constructor)

source code 
Initialize the toaster.
Parameters:
  • spellclass (Spell) - Deprecated, use spellnames.
  • options (dict) - The options (as keyword arguments).
  • spellnames (list of str) - List of names of spells.
Overrides: object.__init__

msg(self, message)

source code 
Write log message with logger.info, taking into account indent.
Parameters:
  • message (str) - The message to write.

toast(self, top)

source code 
Walk over all files in a directory tree and cast spells on every file.
Parameters:
  • top (str) - The directory or file to toast.

_toast(self, stream)

source code 
Run toaster on particular stream and data. Used as helper function.

get_toast_head_root_ext(self, filename)

source code 
Get the name of where the input file filename would be written to by the toaster: head, root, and extension.
Parameters:
  • filename (str) - The name of the hypothetical file to be toasted.
Returns: tuple of three strs
The head, root, and extension of the destination, or (None, None, None) if --dryrun is specified.

get_toast_stream(self, filename, test_exists=False)

source code 

Calls get_toast_head_root_ext(filename) to determine the name of the toast file, and return a stream for writing accordingly.

Then return a stream where result can be written to, or in case test_exists is True, test if result would overwrite a file. More specifically, if test_exists is True, then no streams are created, and True is returned if the file already exists, and False is returned otherwise.


Class Variable Details [hide private]

DEFAULT_OPTIONS

List of spell classes of the particular Toaster instance.
Value:
{'applypatch': False,
 'archives': False,
 'arg': '',
 'createpatch': False,
 'destdir': '',
 'diffcmd': '',
 'dryrun': False,
 'examples': False,
...