Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

The python code for the embel python script is split in two parts:

  • "utility" functions are kept in embellib.py
  • the actual work is done by embel.py calling those functions

The separation has nothing to do with generalization of the utility library. Both the embel.py and the embellib.py code is specific to the problem at hand. The only reason for the existence of embellib.py is convenience for unit-testing. To run embellib.py's unit-tests, simply call the script with no parameters:

...

There are two central utility functions in embellib.py, each representing a method from transplanting code from one file to the other:

  • ReplaceLineStartsWith looks for a line with a certain beginning in the target text and replaces it with a line with the same beginning from the source text. We use ReplaceLineStartsWith for embellishing single lines.
  • TransplantCenter expects two identical sets of markers in both a source text and a target text. Everything between those markers is "transplanted" from the source to the target. We use TransplantCenter for embellishing multi-line sections.
Understanding ReplaceLineStartsWith

...

We call FileWriteReplaceLineStartsWith with three parameters:

  • the path to the source project file with the embellished line
  • the target project file with the unebellished line
  • the start of the line if (e.Column.ItemID == "Edit"

(FileWriteReplaceLineStartsWith in turn calls ReplaceLineStartsWith.)

...

TransplantCenter uses the function ThreeSplit to split a text into three parts:

  • before the begin marker
  • after begin marker, before end marker
  • after end marker

What is important here is that the markers themselves are always part of the "center". Illustration of what ThreeSplit does:

...

As with ReplaceLineStartsWith, we have a "tiered" logic of functions:

  • FileWriteTransplantCenter overwrites the target file
  • FileTransplantCenter does the actual substitution for texts from source- and target file, but does not write anything
  • TransplantCenter does the actual substitution on read-in texts
Markers

Some code elements lend themselves quite naturally as markers. The <FixedColumns> and </FixedColumns> from the previous example are only one of several instances. The others are:

  • <WxeFunction>, </WxeFunction> for embellishing WXE headers
  • <remotion:BocReferenceValue, </remotion:BocReferenceValue> for adding the New location, Pick location action menu items

All these begin- and end markers can be found in the code, because they actually serve other purposes than serving as begin- or end markers. For those markers, variables (supposed to be constants) are declared in embellib.py.

...