CreateProgramDoc

bstanly
Create Document Under Program Control

 
 
 

by

 
 
 

Barry Stanly

 
 
 

Printed on June 25, 2017
Copyright 2016 by Barry Stanly

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is available at: https://www.gnu.org/copyleft/fdl.html.

For more information, see Nuances In Computing Hosted at [https://sourceforge.net/p/simpletextformatter](https://sourceforge.net/p/simpletextformatter)

C O N T E N T S

1 Introduction

2 Create the Document

3 Define Document Structure

4 Generate Results

5 Formatting
5.1 Manual Formatting
5.2 GUI Formatting

F I G U R E S

Figure 5.1-1 Table 1
Figure 5.2-2 GUI Menu


1 Introduction

In reading this document, Familiarity with the STF Syntax Summary is assumed. (Download document PDF)

This document shows how to create a document using the STF Python API. A simple test report was chosen for the example:

  1. The document is created

  2. The document structure is defined

  3. A table of results is generated

  4. The resulting document is then processed by some of the command files that come with STF to produce an HTML representation of the document, a PDF representation, and a Wiki representation.It is assumed that Python has been installed, the STF Python API has been installed and STF has been installed. See the installation section of the STF Syntax Summary for details.


2 Create the Document

from stflib import StfDoc
self.doc = StfDoc("TestReport.stf")
self.doc.createDocument("TrialReport","Test Report for Auto System")
self.doc.setStructure(HTML_Local=True, FrontMatter=False)
self.doc.setContents(Index=False)
self.doc.beginDocument()

This creates a file TestReport.stf in the current folder and creates a basic header for it. The top of page title is Test Report for Auto System


3 Define Document Structure

desc = "Test Report for Auto System\t\t\tWritten by:\t\t\tThe Auto Team"
self.doc.describeDocument(desc)


Note "\t" is the Python way to specify a <TAB> character and represents a blank line in a description.


4 Generate Results

The results are saved in a table stored in its own file. This external file is then included into the test report document. The reason for doing it this way is to allow the table to be included in other documents, such as a more formal test report.

... Create table in external file
self.doc.changeOutputFile("Table.sti")
Caption = "Test Results"
Header = "Test name\tResult"
cspec = "|l|l|"
self.doc.createTable(Caption, Header, cspec, Label="Tab")
 
... Add test data
tab = "\t"
row = "Test 1" + tab + "Passed"
self.doc.tableRow(row)
row = "Test 2" + tab + "Passed"
self.doc.tableRow(row)
row = "Test 3" + tab + "Passed"
self.doc.tableRow(row)
 
... End table and change output file back to default
self.doc.endTable()
self.doc.changeOutputFile("")
 
Include the table back into main document
self.doc.putVerbatim(".Include Table.sti")
self.doc.endDocument()



5 Formatting


5.1 Manual Formatting

This simple program (37 lines long) generates two files: TestReport.stf and the include file: Table.sti. To generate a PDF report, you can use a command file that is included with STF: makeDoc.bat. To use makeDoc, double click 0Dos.bat(1) and enter the following in the report directory:

C:\Users\Public\Cmds\makeDoc.bat TestReport
and TestReport.pdf and TestReport.html will be produced. If directory C:\Users\Public\Cmds was added to the path, per the installation instructions, then it is only necessary to enter:
makeDoc TestReport. The Wiki formatted version is generated by entering:
makeWiki TestReport

Alternately the commands may be entered by hand. First open a Dos window by double clicking 0Dos.bat, then enter the following:

STFxlate --latex -i TestReport
pdflatex -interaction=nonstopmode TestReport.tex

Where it is assumed that LaTeX and STFxlate have been added to the path so it is not necessary to fully qualify file names. STFxlate.bat is a command file that provides services to STFxlate.py. To see what STFxlate.bat does, edit or type C:\Users\Public\Cmds\makeDoc.bat after installation.
The resulting table looks like Table 1.

Figure 5.1-1 Table 1

Figure 5.1-1 Table 1




5.2 GUI Formatting

To generate the documents the easy way, double click on TestReport.stf in the report directory and a menu will display (assuming Executor was installed per the installation instructions.) The default menu is shown in Figure 5.2-2. The defaults for Executor are stored in C:\Users\'you'\.nic\Executor and may be customized after the first execution. Since there is no contents for this document, use makeDoc; otherwise use makeDocWithIndex, etc.

Figure 5.2-2 GUI Menu

Figure 5.2-2 GUI Menu


F O O T N O T E S



(1) 0Dos.bat is a command file that opens a command window


Related

Wiki: DocumationMagic