Example #1
0
    def preprocess(self, nb, resources):
        """Concatenates the cells from the header and footer notebooks to the
        given cells.

        """
        new_cells = []

        # header
        if self.header:
            with open(self.header, 'r') as fh:
                header_nb = read_nb(fh, as_version=current_nbformat)
            new_cells.extend(header_nb.cells)

        # body
        new_cells.extend(nb.cells)

        # footer
        if self.footer:
            with open(self.footer, 'r') as fh:
                footer_nb = read_nb(fh, as_version=current_nbformat)
            new_cells.extend(footer_nb.cells)

        nb.cells = new_cells
        super(IncludeHeaderFooter, self).preprocess(nb, resources)

        return nb, resources
Example #2
0
 def setup(self):
     self.nbs = {}
     for basename, filename in self.files.items():
         with open(filename, "r") as fh:
             self.nbs[basename] = read_nb(fh, as_version=current_nbformat)
Example #3
0
 def _read_nb(self, filename):
     fullpath = os.path.join(os.path.dirname(__file__), filename)
     with open(fullpath, "r") as fh:
         nb = read_nb(fh, as_version=current_nbformat)
     return nb