Cogeno API

cogeno is a Python module that provides access to the public functions of the class: CodeGenerator and the sub-classes of it. See Code generation functions for a description of all cogeno module’s functions.

The interfaces listed hereafter are the internal interface of cogeno.

CodeGenerator

class CodeGenerator

Public Functions

__init__(self self)
cogeno_state(self self)

numeric cogeno state id

Public Static Attributes

cogeno.generator.CodeGenerator.cogeno_module = None
list cogeno.generator.CodeGenerator.cogeno_module_states = []

The CodeGenerator class includes (sub-classes) several mixin classes:

ErrorMixin

class ErrorMixin

Subclassed by cogeno.generator.CodeGenerator

Public Functions

error(self self, msg msg = ' Error raised by cogeno generator.', frame_index frame_index = 0, lineno lineno = 0)

Raise Error exception.

Extra information is added that maps the python snippet line seen by the Python interpreter to the line of the file that inlines the python snippet.

Parameters
  • msg: [optional] exception message

  • frame_index: [optional] Call frame index. The call frame offset of the function calling error(). Zero if directly called in a snippet. Add one for every level of function call.

  • lineno: [optional] line number within template

GenericMixin

Warning

doxygenclass: Cannot find class “cogeno::generic::GenericMixin” in doxygen xml output for project “cogeno” from directory: /home/docs/checkouts/readthedocs.org/user_builds/cogeno/checkouts/stable/docs/_build/doxy/xml

LockMixin

class LockMixin

Subclassed by cogeno.generator.CodeGenerator

Public Functions

lock_file(self self)

Lock file used for the current context.

Return

lock file name

lock(self self)

Get the global cogeno lock.

try:
     with cogeno.lock().acquire(timeout = 10):
         ...
except cogeno.lock_timeout():
    cogeno.error(...)
except:
    raise

Return

Lock object

lock_timeout(self self)

Lock timeout.

Return

Lock timeout object

OptionsMixin

class OptionsMixin

Subclassed by cogeno.generator.CodeGenerator

Public Functions

option(self self, name name)

Get option of actual context.

Return

option value

Parameters
  • name: Name of option

options_add_argument(self self, args args, kwargs kwargs)

Add option arguments to option parser of actual context.

Cogeno modules may add arguments to the cogeno option parser. The argument variables given to cogeno are rescanned after new option arguments are provided.

def mymodule(cogeno):
    if not hasattr(cogeno, '_mymodule'):
        cogeno._mymodule = None

        cogeno.options_add_argument('-m', '--mymodule', metavar='FILE',
            dest='mymodule_file', action='store',
            type=lambda x: cogeno.options_is_valid_file(x),
            help='Load mymodule data from FILE.')

   if getattr(cogeno, '_mymodule') is not None:
       return cogeno._mymodule

   if cogeno.option('mymodule_file'):
       mymodule_file = cogeno.option('mymodule_file')
   else:
       cogeno.error(..., 2)

   ...
   cogeno._mymodule = ...

options_is_valid_file(self self, filepath filepath)
options_is_valid_directory(self self, directorypath directorypath)

StdModulesMixin

class StdModulesMixin

Subclassed by cogeno.generator.CodeGenerator

Public Functions

edts(self self)

Get the extended device tree database.

Return

Extended device tree database.

cmake(self self)

Get the cmake variables database.

Return

CMake variables database.

cmake_variable(self self, variable_name variable_name, default default = "<unset>")

Get the value of a CMake variable.

If variable_name is not provided to cogeno by CMake the default value is returned.

A typical set of CMake variables that are not available in the CMakeCache.txt file and have to be provided as defines to cogeno if needed:

  • “PROJECT_NAME”

  • ”PROJECT_SOURCE_DIR”

  • ”PROJECT_BINARY_DIR”

  • ”CMAKE_SOURCE_DIR”

  • ”CMAKE_BINARY_DIR”

  • ”CMAKE_CURRENT_SOURCE_DIR”

  • ”CMAKE_CURRENT_BINARY_DIR”

  • ”CMAKE_CURRENT_LIST_DIR”

  • ”CMAKE_FILES_DIRECTORY”

  • ”CMAKE_PROJECT_NAME”

  • ”CMAKE_SYSTEM”

  • ”CMAKE_SYSTEM_NAME”

  • ”CMAKE_SYSTEM_VERSION”

  • ”CMAKE_SYSTEM_PROCESSOR”

  • ”CMAKE_C_COMPILER”

  • ”CMAKE_CXX_COMPILER”

  • ”CMAKE_COMPILER_IS_GNUCC”

  • ”CMAKE_COMPILER_IS_GNUCXX”

Return

value

Parameters
  • variable_name: Name of the CMake variable

  • default: Default value

cmake_cache_variable(self self, variable_name variable_name, default default = "<unset>")

Get the value of a CMake variable from CMakeCache.txt.

If variable_name is not given in CMakeCache.txt the default value is returned.

Return

value

Parameters
  • variable_name: Name of the CMake variable

  • default: Default value

config_properties(self self)

Get all config properties.

The property names are the ones config file.

Return

A dictionary of config properties.

config_property(self self, property_name property_name, default default = "<unset>")

Get the value of a configuration property fromthe config file.

If property_name is not given in .config the default value is returned.

Return

property value

Parameters
  • property_name: Name of the property

  • default: Property value to return per default.

Context

class Context

Context for code generation.

Public Functions

__init__(self self, generator generator, parent_context parent_context = None, generation_globals generation_globals = None, options options = None, eval_begin eval_begin = None, eval_end eval_end = None, eval_adjust eval_adjust = None, delete_code delete_code = None, template_file template_file = None, template template = None, template_source_type template_source_type = None, script_type script_type = None, template_tabsize template_tabsize = None, templates_paths templates_paths = None, modules_paths modules_paths = None, jinja2_environment jinja2_environment = None, output_file output_file = None, log_file log_file = None, lock_file lock_file = None)
__str__(self self)
__repr__(self self)
parent(self self)
generation_globals(self self)
script_is_inline(self self)
script_is_python(self self)
script_is_jinja2(self self)
script_type(self self)
template_is_snippet(self self)

Template is a snippet.

Snippets are parts of the template of the parent context.

Return

True in case the template is a snippet, False otherwise.

template_is_file(self self)
template_is_string(self self)
out(self self, line line)

Add line.

outl(self self, line line)

Add line with newline.