mrv.automation.report
Covered: 34 lines
Missed: 1 lines
Skipped 24 lines
Percent: 97 %
 2
"""contains report implementations allowing to analyse the callgraph of """
 3
__docformat__ = "restructuredtext"
 6
class ReportBase( object ):
 7
	"""Provides main interface for all reports as well as the basic implementation"""
10
	def __init__( self, callgraph ):
11
		"""intiialize the report with the given callgraph"""
12
		self._callgraph = callgraph
18
	def makeReport( self ):
19
		""":return: report as result of a prior Callgraph analysis"""
20
		raise NotImplementedError( "This method needs to be implemented by subclasses" )
25
class Plan( ReportBase ):
26
	"""Create a plan-like text describing how the target is being made"""
28
	def _analyseCallgraph( self  ):
29
		"""Create a list of ProcessData instances that reflects the call order"""
30
		kwargs = {}
31
		kwargs[ 'reverse' ] = True
32
		return self._callgraph.toCallList( **kwargs )
35
	def makeReport( self, headline=None ):
36
		"""
37
		:return: list of strings ( lines ) resembling a plan-like formatting
38
			of the call graph
39
		:param headline: line to be given as first line """
40
		cl = self._analyseCallgraph( )
42
		out = []
43
		if headline:
44
			out.append( headline )
46
		for i,pedge in enumerate( cl ):
47
			sp,ep = pedge
48
			i += 1 		# plans start at 1
50
			if ep:
51
				line = "%i. %s provides %r through %s to %s" % ( i, sp.process.id(), sp.result(), sp.plug, ep.process.noun )
52
			else:
54
				line = "%i. %s %s %r when asked for %s" % ( i, sp.process.id(), sp.process.verb, sp.result(), sp.plug )
55
			out.append( line )
57
		return out