#NEWLINE# def html_report( outdir , modules , excludes = None , errors = None ) : #NEWLINE# #INDENT# "\n    Creates an ``index.html`` in the specified ``outdir``. Also attempts to create\n    a ``modules`` subdirectory to create module detail html pages, which are named\n    `module.__name__` + '.html'.\n\n    It uses `templates.default_module_index` to create the index page. The template\n    contains the following sections which need to be rendered and assembled into\n    `index.html`.\n\n    TOP: Contains the HTML declaration and head information, as well as the\n         inline stylesheet. It doesn't require any variables.\n\n    CONTENT_HEADER: The header portion of the body. Requires the following variable:\n                    * ``%(test_timestamp)s``\n\n    CONTENT_BODY: A table of contents to the different module detail pages, with some\n                  basic stats. Requires the following variables:\n                  * ``%(module_stats)s`` This is the actual content of the table and is\n                    generated by looping through the modules we want to report on and\n                    concatenanting together rendered ``MODULE_STAT`` template (see below).\n                  * ``%(total_lines)d``\n                  * ``%(total_executed)d``\n                  * ``%(total_excluded)d``\n                  * ``%(overall_covered)0.1f``\n\n    EXCEPTIONS_LINK: Link to the excludes and errors index page which shows\n                     packages and modules which were not part of the coverage\n                     analysis. Requires the following variable:\n                     * ``%(exceptions_link)s`` Link to the index page.\n                     * ``%(exceptions_desc)s`` Describe the exception.\n\n    ERRORS_LINK: Link to the errors index page which shows packages and modules which\n                 had problems being imported. Requires the following variable:\n                 * ``%(errors_link)s`` Link to the index page.\n\n    BOTTOM: Just a closing ``</body></html>``\n\n    MODULE_STAT: Used to assemble the content of ``%(module_stats)s`` for ``CONTENT_BODY``.\n                 Requires the following variables:\n                 * ``%(severity)s`` (normal, warning, critical) used as CSS class identifier\n                   to style the coverage percentage.\n                 * ``%(module_link)s``\n                 * ``%(module_name)s``\n                 * ``%(total_count)d``\n                 * ``%(executed_count)d``\n                 * ``%(excluded_count)d``\n                 * ``%(percent_covered)0.1f``\n    " #NEWLINE# test_timestamp = time . strftime ( '%a %Y-%m-%d %H:%M %Z' ) #NEWLINE# m_subdirname = 'modules' #NEWLINE# m_dir = os . path . join ( outdir , m_subdirname ) #NEWLINE# if ( not os . path . exists ( m_dir ) ) : #NEWLINE# #INDENT# os . makedirs ( m_dir ) #NEWLINE# #UNINDENT# total_lines = 0 #NEWLINE# total_executed = 0 #NEWLINE# total_excluded = 0 #NEWLINE# total_stmts = 0 #NEWLINE# module_stats = list ( ) #NEWLINE# m_names = list ( modules . keys ( ) ) #NEWLINE# m_names . sort ( ) #NEWLINE# for n in m_names : #NEWLINE# #INDENT# m_vars = ModuleVars ( n , modules [ n ] ) #NEWLINE# if ( not m_vars . total_count ) : #NEWLINE# #INDENT# excludes . append ( m_vars . module_name ) #NEWLINE# del modules [ n ] #NEWLINE# continue #NEWLINE# #UNINDENT# m_vars . module_link = p2url ( os . path . join ( m_subdirname , ( m_vars . module_name + '.html' ) ) ) #NEWLINE# module_stats . append ( ( module_index . MODULE_STAT % m_vars . __dict__ ) ) #NEWLINE# total_lines += m_vars . total_count #NEWLINE# total_executed += m_vars . executed_count #NEWLINE# total_excluded += m_vars . excluded_count #NEWLINE# total_stmts += len ( m_vars . stmts ) #NEWLINE# #UNINDENT# module_stats = os . linesep . join ( module_stats ) #NEWLINE# if total_stmts : #NEWLINE# #INDENT# overall_covered = ( ( float ( total_executed ) / total_stmts ) * 100 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# overall_covered = 0.0 #NEWLINE# #UNINDENT# m_names = list ( modules . keys ( ) ) #NEWLINE# m_names . sort ( ) #NEWLINE# i = 0 #NEWLINE# for ( i , n ) in enumerate ( m_names ) : #NEWLINE# #INDENT# m_vars = ModuleVars ( n ) #NEWLINE# nav = dict ( up_link = p2url ( os . path . join ( '..' , 'index.html' ) ) , up_label = 'index' ) #NEWLINE# if ( i > 0 ) : #NEWLINE# #INDENT# m = ModuleVars ( m_names [ ( i - 1 ) ] ) #NEWLINE# nav [ 'prev_link' ] = os . path . basename ( m . module_link ) #NEWLINE# nav [ 'prev_label' ] = m . module_name #NEWLINE# #UNINDENT# if ( ( i + 1 ) < len ( modules ) ) : #NEWLINE# #INDENT# m = ModuleVars ( m_names [ ( i + 1 ) ] ) #NEWLINE# nav [ 'next_link' ] = os . path . basename ( m . module_link ) #NEWLINE# nav [ 'next_label' ] = m . module_name #NEWLINE# #UNINDENT# html_module_detail ( os . path . join ( m_dir , ( m_vars . module_name + '.html' ) ) , n , nav ) #NEWLINE# #UNINDENT# fo = open ( os . path . join ( outdir , 'index.html' ) , 'w+' ) #NEWLINE# fo . write ( module_index . TOP ) #NEWLINE# fo . write ( ( module_index . CONTENT_HEADER % vars ( ) ) ) #NEWLINE# fo . write ( ( module_index . CONTENT_BODY % vars ( ) ) ) #NEWLINE# if excludes : #NEWLINE# #INDENT# _file = 'excludes.html' #NEWLINE# exceptions_link = _file #NEWLINE# exception_desc = 'Excluded packages and modules' #NEWLINE# fo . write ( ( module_index . EXCEPTIONS_LINK % vars ( ) ) ) #NEWLINE# html_module_excludes ( os . path . join ( outdir , _file ) , excludes ) #NEWLINE# #UNINDENT# if errors : #NEWLINE# #INDENT# _file = 'errors.html' #NEWLINE# exceptions_link = _file #NEWLINE# exception_desc = 'Error packages and modules' #NEWLINE# fo . write ( ( module_index . EXCEPTIONS_LINK % vars ( ) ) ) #NEWLINE# html_module_errors ( os . path . join ( outdir , _file ) , errors ) #NEWLINE# #UNINDENT# fo . write ( module_index . BOTTOM ) #NEWLINE# fo . close ( ) #NEWLINE# if settings . COVERAGE_BADGE_TYPE : #NEWLINE# #INDENT# badge = open ( os . path . join ( os . path . dirname ( __file__ ) , 'badges' , settings . COVERAGE_BADGE_TYPE , ( '%s.png' % int ( overall_covered ) ) ) , 'rb' ) . read ( ) #NEWLINE# open ( os . path . join ( outdir , 'coverage_status.png' ) , 'wb' ) . write ( badge )