def convert_files(self, group): """ Converts all notebooks and python scripts into :epkg:`HTML` for a group. @param group group name @return list of new files """ names = list(self.enumerate_group_files(group)) files = [] for name in names: if "attachments" not in name: continue ext = os.path.splitext(name)[-1] if ext == ".ipynb": self.fLOG( "[ProjectsRepository.convert_files] convert '{0}'".format( name)) out = name + ".html" if os.path.exists(out): warnings.warn( "[convert_files] overwriting '{0}'".format(out)) try: upgrade_notebook(name) nb2html(name, out, exc=False) files.append(out) except Exception as e: warnings.warn( "unable to convert a notebook '{0}' because of {1}". format(name, e)) elif ext == ".py": self.fLOG( "[ProjectsRepository.convert_files] convert '{0}'".format( name)) out = name + ".html" if os.path.exists(out): warnings.warn( "[convert_files] overwriting '{0}'".format(out)) try: py_to_html_file(name, out, False, title=os.path.relpath( name, self.get_group_location(group))) files.append(out) except Exception: # the syntax of the python file might be wrong warnings.warn( "unable to convert File \"{0}\"".format(name)) return files
def test_convert_slides_api_html(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") path = os.path.abspath(os.path.split(__file__)[0]) fold = os.path.normpath( os.path.join( path, "..", "..", "_doc", "notebooks")) nb = os.path.join(fold, "example_pyquickhelper.ipynb") self.assertExists(nb) nbr = read_nb(nb, kernel=False) temp = get_temp_folder(__file__, "temp_nb_api_html") outfile = os.path.join(temp, "out_nb_slides.slides.html") res = nb2slides(nbr, outfile) self.assertGreater(len(res), 1) for r in res: self.assertExists(r) outfile = os.path.join(temp, "out_nb_slides.html") res = nb2html(nbr, outfile) self.assertEqual(len(res), 1) for r in res: self.assertExists(r)
def test_convert_slides_api_html(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") path = os.path.abspath(os.path.split(__file__)[0]) fold = os.path.normpath( os.path.join(path, "..", "..", "_doc", "notebooks")) nb = os.path.join(fold, "example_pyquickhelper.ipynb") self.assertExists(nb) nbr = read_nb(nb, kernel=False) temp = get_temp_folder(__file__, "temp_nb_api_html") outfile = os.path.join(temp, "out_nb_slides.slides.html") res = nb2slides(nbr, outfile) self.assertGreater(len(res), 1) for r in res: self.assertExists(r) outfile = os.path.join(temp, "out_nb_slides.html") fold = 'static' if not os.path.exists(fold): os.mkdir(fold) sty = os.path.join(fold, 'style.css') if not os.path.exists(sty): sr = os.path.join(temp, '..', 'data', 'style.css') if not os.path.exists(sr): raise FileNotFoundError(sr) shutil.copy(sr, fold) res = nb2html(nbr, outfile) self.assertEqual(len(res), 1) for r in res: self.assertExists(r)
def convert_files(self, group): """ Converts all notebooks and python scripts into :epkg:`HTML` for a group. @param group group name @return list of new files """ names = list(self.enumerate_group_files(group)) files = [] for name in names: if "attachments" not in name: continue ext = os.path.splitext(name)[-1] if ext == ".ipynb": self.fLOG( "[ProjectsRepository.convert_files] convert '{0}'".format(name)) out = name + ".html" if os.path.exists(out): warnings.warn( "[convert_files] overwriting '{0}'".format(out)) try: upgrade_notebook(name) nb2html(name, out, exc=False) files.append(out) except Exception as e: warnings.warn( "unable to convert a notebook '{0}' because of {1}".format(name, e)) elif ext == ".py": self.fLOG( "[ProjectsRepository.convert_files] convert '{0}'".format(name)) out = name + ".html" if os.path.exists(out): warnings.warn( "[convert_files] overwriting '{0}'".format(out)) try: py_to_html_file(name, out, False, title=os.path.relpath( name, self.get_group_location(group))) files.append(out) except Exception: # the syntax of the python file might be wrong warnings.warn( "unable to convert File \"{0}\"".format(name)) return files