Package gavo :: Package user :: Module rdmanipulator
[frames] | no frames]

Module rdmanipulator

source code


Helpers for manipulating serialised RDs.

The problem here is that RDs typically are formatted with lots of love,
also within elements -- e.g., like this:

        <column name="bla" type="text"
                ucd="foo.bar"
                description="A long text carefully
                        broken at the right place"
        />

There's no way one can coax a normal XML parser into giving events that'd
allow us to preserve this formatting.   Hence, when manipulating
RD sources, I need something less sophisticated -- the dump XML parser
implemented here.

Note that this will accept non-well-formed documents; don't use this except
for the limited purpose of editing supposedly well-formed documents.

Classes
  Attribute
a sentinel for XML attributes.
  NewElement
an element to be inserted into a parsed xml tree.
  Element
a sentinel for XML elements.
  Manipulator
a base class for processXML manipulators.
  NROWS
a singleton sentinel to communicate nrows in tableTriggers.
Functions
 
flatten(arg)
returns a string from a (possibly edited) parse tree.
source code
 
getAttribute(parseResult, name)
returns the Attribute element with name within parseResult.
source code
 
getXMLGrammar(manipulator) source code
 
processXML(document, manipulator)
processes an XML-document with manipulator.
source code
 
iterCoverageItems(updater)
yields coverage items for inclusion in RDs.
source code
 
iterLimitsForTable(tableDef)
returns a list of values to fill in into tableDef.
source code
 
iterLimitsForRD(rd)
returns a list of values to fill in for an entire RD.
source code
 
getChangedRD(rdId, limits)
returns a string corresponding to the RD with rdId with limits applied.
source code
 
parseCmdLine() source code
 
main() source code
Function Details

getAttribute(parseResult, name)

source code 

returns the Attribute element with name within parseResult.

If no such attribute exists, a KeyError is raised.

processXML(document, manipulator)

source code 

processes an XML-document with manipulator.

document is a string containing the XML, and the function returns serialized an XML. You're doing yourself a favour if document is a unicode string.

manipulator is an instance of a derivation of Manipulator below. There's a secret handshake between Manipulator and the grammar, so you really need to inherit, just putting in the two methods won't do.

iterCoverageItems(updater)

source code 

yields coverage items for inclusion in RDs.

NOTE: so far, we can only have one coverage item. So, it's enough to just say "fill this into axis x of coverage". If and when we have more than one coverage items, we'll have to re-think that. That's why there's the "reserved" value in the tuples. We'll have to put something in there (presumably the index of the coverage element, but perhaps we'll have a better identity at some point).

iterLimitsForTable(tableDef)

source code 

returns a list of values to fill in into tableDef.

This will be empty if the table doesn't exist. Otherwise, it will be a tuple ("limit", table-id, column-name, min, max) for every column with a reasonably numeric type that has a min and max values.

The other thing that *could* come back (but currently only does for iterLimitsForRD) is ("coverage", reserved, axis, literal); see iterCoverageItems for details.

iterLimitsForRD(rd)

source code 

returns a list of values to fill in for an entire RD.

See iterLimitsForTable.

getChangedRD(rdId, limits)

source code 

returns a string corresponding to the RD with rdId with limits applied.

Limits is a sequence of (table-id, column-name, min, max) tuples. We assume the values elements already exist.