Package inca :: Module Reporter :: Class Reporter
[hide private]
[frames] | no frames]

Class Reporter

source code

Known Subclasses:

Reporter - Module for creating Inca reporters:

 from inca.Reporter import Reporter
 reporter = Reporter(
   name = 'hack.version',
   version = 0.1,
   description = 'A really helpful reporter description',
   url = 'http://url.to.more.reporter.info'
 )

This module creates Inca reporters--objects that produce XML that follows the Inca Report schema. The constructor may be called with a number of reporter attributes that can later be set and queried with their corresponding get/set functions (described below). For example:

 reporter = Reporter()
 reporter.setUrl('http://url.to.more.reporter.info')
 reporter.setVersion(0.1)
Instance Methods [hide private]
 
__del__(self)
Class destructor.
source code
 
__init__(self, **attributes)
Class constructor that returns a new Reporter object.
source code
 
_helpXml(self)
Returns help information formatted as the body of an Inca report.
source code
 
_iso8601Time(self, when)
Returns the UTC time for the time() return value when in ISO 8601 format: CCMM-MM-DDTHH:MM:SSZ
source code
 
_reportXml(self, *contents)
Returns XML report beginning with the header and input sections plus any contents specified in the arguments.
source code
 
_timeoutException(*args)
SIGALRM handler that throws an exception.
source code
 
addArg(self, name, description=None, default=None, pattern=None)
Adds a command line argument (invocation syntax -name=value) to the reporter.
source code
 
addDependency(self, *dependencies)
Add one or more dependencies to the list of modules on which this reporter depends.
source code
 
argValue(self, name, position=None)
Called after the processArgv method, this returns the value of the position'th instance (starting with 1) of the name command-line argument.
source code
 
argValues(self, name)
Called after the processArgv method, this returns an array of all values specified for the name command-line argument.
source code
 
compiledProgramOutput(self, **params)
A convenience; compiles and runs a program, removes the source and exec files, and returns the program's combined stderr/out output.
source code
 
compiledProgramStatusOutput(self, **params)
A convenience; compiles and runs a program, removes the source and exec files, and returns a tuple that contains the program's exit code and its combined stderr/out output.
source code
 
failPrintAndExit(self, msg)
A convenience; calls setResult(0, msg) and printReport() before exiting the reporter.
source code
 
getBody(self)
Returns the body of the report.
source code
 
getCompleted(self)
Returns the completion indicator of the reporter.
source code
 
getCwd(self)
Returns the initial working directory of the reporter.
source code
 
getDescription(self)
Returns the initial working directory of the reporter.
source code
 
getFailMessage(self)
Returns the failure message of the reporter.
source code
 
getName(self)
Returns the name that identifies this reporter.
source code
 
getUrl(self)
Returns the url which describes the reporter in more detail.
source code
 
getVersion(self)
Returns the version of the reporter.
source code
 
log(self, type, *msgs)
Appends each element of msgs to the list of type log messages stored in the reporter.
source code
 
loggedCommandOutput(self, cmd, timeout=None)
A convenience; appends cmd to the 'system'-type log messages stored in the reporter, then runs cmd and returns its combined stderr/stdout.
source code
 
loggedCommandStatusOutput(self, cmd, timeout=None)
A convenience; appends cmd to the 'system'-type log messages stored in the reporter, then runs cmd and returns a tuple that contains its exit code and combined stderr/stdout.
source code
 
printReport(self, verbose=None)
A convenience; prints report(verbose) to stdout.
source code
 
processArgv(self, argv)
Processes argv which is a list of command-line arguments of the form -name=value
source code
 
report(self, verbose=None)
Returns report text or XML, depending on the value (0, 1, 2) of verbose.
source code
 
reportBody(self)
Constructs and returns the XML contents of the report body.
source code
 
setBody(self, body)
Sets the body of the report to body.
source code
 
setCompleted(self, completed)
Sets the completion indicator of the reporter to completed.
source code
 
setCwd(self, cwd)
Sets the initial working directory of the reporter to cwd.
source code
 
setDescription(self, description)
Sets the description of the reporter to description.
source code
 
setFailMessage(self, msg)
Sets the failure message of the reporter to msg.
source code
 
setName(self, name)
Sets the name that identifies this reporter to name.
source code
 
setResult(self, completed, msg=None)
A convenience; calls setCompleted(completed) and setFailMessage(msg).
source code
 
setUrl(self, url)
Sets the url for the reporter to url.
source code
 
setVersion(self, version)
Sets the version of the reporter to version.
source code
 
tempFile(self, *paths)
A convenience.
source code
 
xmlElement(self, name, escape, *contents)
Returns the XML element name surrounding contents.
source code
Method Details [hide private]

__init__(self, **attributes)
(Constructor)

source code 

Class constructor that returns a new Reporter object.

The constructor may be called with any of the following named attributes as parameters:

 body
   the XML body of the report.  See the Inca Report schema for format.

 completed
   boolean indicating whether or not the reporter has completed
   generating the information it is intended to produce

 description
   a verbose description of the reporter

 fail_message
   a message describing why the reporter failed to complete its task

 name
   the name that identifies this reporter

 url
   URL to get more information about the reporter

 version
   the version of the reporter; defaults to '0'

addArg(self, name, description=None, default=None, pattern=None)

source code 

Adds a command line argument (invocation syntax -name=value) to the reporter. If supplied, the optional description will be included in the reporter help XML and display. If supplied, default indicates that the argument is optional; the argValue method will return default if the command line does not include a value for the argument. The optional pattern specifies a pattern for recognizing valid argument values; the default is '.*', which means that any text is acceptable for the argument value.

addDependency(self, *dependencies)

source code 

Add one or more dependencies to the list of modules on which this reporter depends. Dependencies are reported as part of reporter help output to assist reporter repository tools in their retrievals. NOTE: dependencies on the standard Inca reporter library modules are added by the modules themselves, so a reporter only needs to invoke this method to report external dependencies. The Inca Reporter Instance Manager presently only supports dependencies on Inca repository packages.

argValue(self, name, position=None)

source code 

Called after the processArgv method, this returns the value of the position'th instance (starting with 1) of the name command-line argument. Returns the value of the last instance if position is None. Returns None if name is not a recognized argument. Returns the default value for name if it has one and name is included fewer than position times on the command line.

argValues(self, name)

source code 

Called after the processArgv method, this returns an array of all values specified for the name command-line argument. Returns None if name is not a recognized argument. Returns a single-element array containing the default value for name if it has one and name does not appear on the command line.

compiledProgramOutput(self, **params)

source code 

A convenience; compiles and runs a program, removes the source and exec files, and returns the program's combined stderr/out output. See compiledProgramStatusOutput for a list of recognized params.

compiledProgramStatusOutput(self, **params)

source code 

A convenience; compiles and runs a program, removes the source and exec files, and returns a tuple that contains the program's exit code and its combined stderr/out output. Recognized params:

 code
   the code to compile; required

 compiler
   the compiler to invoke; defaults to cc

 language
   source file language--one of 'c', 'c++', 'fortran', or 'java';
   defaults to 'c'.

 out_switch
   the switch to use to specify the compiler output file; default '-o '

 switches
   additional switches to pass to the compiler; defaults to ''

 timeout
   max seconds compilation/execution may take; returns a non-zero exit
   status and any partial program output on time-out

log(self, type, *msgs)

source code 

Appends each element of msgs to the list of type log messages stored in the reporter. type must be one of 'debug', 'error', 'info', 'system', or 'warn'.

loggedCommandOutput(self, cmd, timeout=None)

source code 

A convenience; appends cmd to the 'system'-type log messages stored in the reporter, then runs cmd and returns its combined stderr/stdout. If timeout is specified and the command doesn't complete within timeout seconds, aborts the execution of cmd and returns any partial output.

loggedCommandStatusOutput(self, cmd, timeout=None)

source code 

A convenience; appends cmd to the 'system'-type log messages stored in the reporter, then runs cmd and returns a tuple that contains its exit code and combined stderr/stdout. If timeout is specified and the command doesn't complete within timeout seconds, aborts the execution of cmd and returns a non-zero exit code and any partial output.

processArgv(self, argv)

source code 

Processes argv which is a list of command-line arguments of the form -name=value

The following options are predefined:

 help
   yes
     Prints help information describing the reporter inputs, then
     forces the reporter to exit.  If the verbose level is 0, the
     output will be text; otherwise, it will be Inca Report XML.
   no (default)
     Normal reporter execution.

 log
   0 (default)
     log no messages
   1
     log error messages
   2
     log error and warning messages
   3
     log error, warning, and system messages
   4
     log error, warning, system, and info messages
   5
     log error, warning, system, info, and debug messages
   debug
     log only debug messages
   error
     log only error messages
   info
     log only info messages
   system
     log only system messages
   warn
     log only warning messages

 verbose
   0
     print will only produce "completed" or "failed".
   1 (default)
     print will produce Inca Report XML.
   2
     print will produce Inca Report XML that includes help information.

version
  yes
    Prints the reporter version number and exits.
  no (default)
    Normal reporter execution.

report(self, verbose=None)

source code 

Returns report text or XML, depending on the value (0, 1, 2) of verbose. Uses the value of the -verbose switch if verbose is None.

reportBody(self)

source code 

Constructs and returns the XML contents of the report body. Child classes should override the default implementation, which returns None.

setVersion(self, version)

source code 

Sets the version of the reporter to version. Recognizes and parses CVS revision strings.

tempFile(self, *paths)

source code 

A convenience. Adds each element of paths to a list of temporary files that will be deleted automatically when the reporter is destroyed.

xmlElement(self, name, escape, *contents)

source code 

Returns the XML element name surrounding contents. escape should be true only for leaf elements; in this case, each special XML character (<>&) in contents is replaced by the equivalent XML entity.