def verify_pod_links(self, pod):
        """Check for missing files linked to from POD's html page.

        See documentation for :class:`~verify_links.LinkVerifier`. This method
        calls LinkVerifier to check existence of all files linked to from the 
        POD's own top-level html page (after templating). If any files are
        missing, an error message listing them is written to the run's index.html 
        (located in src/html/pod_missing_snippet.html).
        """
        _log.info('Checking linked output files for %s', pod.name)
        verifier = verify_links.LinkVerifier(
            self.POD_HTML(pod),  # root HTML file to start search at
            self.WK_DIR,  # root directory to resolve relative paths
            verbose=False)
        missing_out = verifier.verify_pod_links(pod.name)
        if missing_out:
            _log.error('POD %s has missing output files:\n%s', pod.name,
                       '    \n'.join(missing_out))
            template_d = html_templating_dict(pod)
            template_d['missing_output'] = '<br>'.join(missing_out)
            util.append_html_template(
                self.html_src_file('pod_missing_snippet.html'),
                self.CASE_TEMP_HTML, template_d)
            pod.exceptions.log(
                util.MDTFFileNotFoundError(
                    f'Missing {len(missing_out)} files.'))
        else:
            _log.info('\tNo files are missing.')
Esempio n. 2
0
    def append_result_link(self, pod):
        """Update the top level index.html page with a link to *pod*'s results.

        This simply appends one of two html fragments to index.html:
        ``src/html/pod_result_snippet.html`` if *pod* completed successfully,
        or ``src/html/pod_error_snippet.html`` if an exception was raised during
        *pod*'s setup or execution.
        """
        template_d = html_templating_dict(pod)
        # add a warning banner if needed
        assert hasattr(pod, '_banner_log')
        banner_str = pod._banner_log.buffer_contents()
        if banner_str:
            banner_str = banner_str.replace('\n', '<br>\n')
            src = self.html_src_file('warning_snippet.html')
            template_d['MDTF_WARNING_BANNER_TEXT'] = banner_str
            util.append_html_template(src, self.CASE_TEMP_HTML, template_d)

        # put in the link to results
        if pod.failed:
            # report error
            src = self.html_src_file('pod_error_snippet.html')
            # template_d['error_text'] = pod.format_log(children=True)
        else:
            # normal exit
            src = self.html_src_file('pod_result_snippet.html')
        util.append_html_template(src, self.CASE_TEMP_HTML, template_d)
    def append_result_link(self, pod):
        """Update the top level index.html page with a link to this POD's results.

        This simply appends one of two html fragments to index.html: 
        pod_result_snippet.html if the POD completed successfully, or
        pod_error_snippet.html if an exception was raised during the POD's setup
        or execution.
        """
        template_d = html_templating_dict(pod)
        if pod.failed:
            # report error
            src = self.html_src_file('pod_error_snippet.html')
            template_d['error_text'] = pod.exceptions.format()
        else:
            # normal exit
            src = self.html_src_file('pod_result_snippet.html')
        util.append_html_template(src, self.CASE_TEMP_HTML, template_d)
    def make_pod_html(self, pod):
        """Perform templating on POD's html results page(s).

        A wrapper for :func:`~util.append_html_template`. Looks for all 
        html files in POD_CODE_DIR, templates them, and copies them to 
        POD_WK_DIR, respecting subdirectory structure (see doc for
        :func:`~util.recursive_copy`).
        """
        test_path = os.path.join(pod.POD_CODE_DIR,
                                 self.pod_html_template_file_name(pod))
        if not os.path.isfile(test_path):
            # POD's top-level HTML template needs to exist
            raise util.MDTFFileNotFoundError(test_path)
        template_d = html_templating_dict(pod)
        # copy and template all .html files, since PODs can make sub-pages
        source_files = util.find_files(pod.POD_CODE_DIR, '*.html')
        util.recursive_copy(
            source_files,
            pod.POD_CODE_DIR,
            pod.POD_WK_DIR,
            copy_function=(lambda src, dest: util.append_html_template(
                src, dest, template_dict=template_d, append=False)),
            overwrite=True)
Esempio n. 5
0
    def make_html(self, cleanup=True):
        """Add header and footer to the temporary output file at CASE_TEMP_HTML.
        """
        dest = os.path.join(self.WK_DIR, self._html_file_name)
        if os.path.isfile(dest):
            self.obj.log.warning("%s: '%s' exists, deleting.",
                                 self._html_file_name, self.obj.name)
            os.remove(dest)

        template_dict = self.obj.env_vars.copy()
        template_dict['DATE_TIME'] = \
            datetime.datetime.utcnow().strftime("%A, %d %B %Y %I:%M%p (UTC)")
        util.append_html_template(self.html_src_file('mdtf_header.html'), dest,
                                  template_dict)
        util.append_html_template(self.CASE_TEMP_HTML, dest, {})
        util.append_html_template(self.html_src_file('mdtf_footer.html'), dest,
                                  template_dict)
        if cleanup:
            os.remove(self.CASE_TEMP_HTML)
        shutil.copy2(self.html_src_file('mdtf_diag_banner.png'), self.WK_DIR)
        else:
            _log.info('\tNo files are missing.')

    def make_html(self, case, cleanup=True):
        """Add header and footer to CASE_TEMP_HTML.
        """
        dest = os.path.join(self.WK_DIR, self._html_file_name)
        if os.path.isfile(dest):
            _log.warning("%s: %s exists, deleting.", self._html_file_name,
                         case.name)
            os.remove(dest)

        template_dict = case.env_vars.copy()
        template_dict['DATE_TIME'] = \
            datetime.datetime.utcnow().strftime("%A, %d %B %Y %I:%M%p (UTC)")
        util.append_html_template(self.html_src_file('mdtf_header.html'), dest,
                                  template_dict)
        util.append_html_template(self.CASE_TEMP_HTML, dest, {})
        util.append_html_template(self.html_src_file('mdtf_footer.html'), dest,
                                  template_dict)
        if cleanup:
            os.remove(self.CASE_TEMP_HTML)
        shutil.copy2(self.html_src_file('mdtf_diag_banner.png'), self.WK_DIR)

    def backup_config_file(self, case):
        """Record settings in file config_save.json for rerunning.
        """
        config = core.ConfigManager()
        out_file = os.path.join(self.WK_DIR, self._backup_config_file_name)
        if not self.file_overwrite:
            out_file, _ = util.bump_version(out_file)
        elif os.path.exists(out_file):