gavo.rscdef.scripting module

Support code for attaching scripts to objects.

Scripts can be either in python or in SQL. They always live on make instances. For details, see Scripting in the reference documentation.

class gavo.rscdef.scripting.ACSQLScriptRunner(script)[source]

Bases: gavo.rscdef.scripting.SQLScriptRunner

A runner for “autocommitted” SQL scripts.

These are like SQLScriptRunners, except that for every statement, a savepoint is created, and for SQL errors, the savepoint is restored (in other words ACSQL scripts turn SQL errors into warnings).

run(dbTable, **kwargs)[source]
exception gavo.rscdef.scripting.Error(msg='', hint=None)[source]

Bases: gavo.utils.excs.Error

class gavo.rscdef.scripting.PythonScriptRunner(script)[source]

Bases: gavo.rscdef.scripting.ScriptRunner

A runner for python scripts.

The scripts can access the current table as table (and thus run SQL statements through table.connection.execute(query, pars)).

Additional keyword arguments are available under their names.

You are in the namespace of usual procApps (like procs, rowgens, and the like).

run(dbTable, **kwargs)[source]
class gavo.rscdef.scripting.SQLScriptRunner(script)[source]

Bases: gavo.rscdef.scripting.ScriptRunner

A runner for SQL scripts.

These will always use the table’s querier to execute the statements.

Keyword arguments to run are ignored.

run(dbTable, **kwargs)[source]
class gavo.rscdef.scripting.Script(parent, **kwargs)[source]

Bases: gavo.base.structure.Structure, gavo.base.structure.RestrictionMixin

A script, i.e., some executable item within a resource descriptor.

The content of scripts is given by their type – usually, they are either python scripts or SQL with special rules for breaking the script into individual statements (which are basically like python’s).

The special language AC_SQL is like SQL, but execution errors are ignored. This is not what you want for most data RDs (it’s intended for housekeeping scripts).

See `Scripting`_.

attrSeq = [<gavo.base.structure.DataContent object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.attrdef.EnumeratedUnicodeAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.base.attrdef.EnumeratedUnicodeAttribute object>]
completedCallbacks = []

returns the content with all macros expanded.

managedAttrs = {'content_': <gavo.base.structure.DataContent object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'lang': <gavo.base.attrdef.EnumeratedUnicodeAttribute object>, 'name': <gavo.base.attrdef.UnicodeAttribute object>, 'notify': <gavo.base.attrdef.BooleanAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute object>, 'type': <gavo.base.attrdef.EnumeratedUnicodeAttribute object>}
name_ = 'script'
typeDesc_ = 'Embedded executable code with a type definition'
class gavo.rscdef.scripting.ScriptRunner(script)[source]

Bases: object

An object encapsulating the preparation and execution of scripts.

They are constructed with instances of Script below and have a method run(dbTable, **kwargs).

You probably should not override __init__ but instead override _prepare(script) which is called by __init__.

class gavo.rscdef.scripting.ScriptingMixin[source]

Bases: gavo.base.common.StructCallbacks

A mixin that gives objects a getRunner method and a script attribute.

The getRunner() method returns a callable that takes the current table (we expect db tables, really), the phase and possibly further keyword arguments, as appropriate for the phase.

Objects mixing this in must define an acceptedScriptTypes attribute containing a set of script types they support. Any other script type will be rejected.

Objects mixing this in must also support define a method getExpander() returning an object mixin in a MacroPackage.

acceptedScriptTypes = {}