def get_notebook_contents(nb_path): if not isinstance(nb_path, string_types) or len(nb_path) == 0: raise_error("Couldn't export notebook contents") # Extract file contents given the path to the notebook try: notebook_output, _ = export_by_name("notebook", nb_path) python_output, _ = export_by_name("python", nb_path) except OSError: # python 2 does not support FileNotFoundError raise_error("Couldn't export notebook contents") return (notebook_output, python_output)
def start(self, argv=None): """Entrypoint of NbConvert application. Parameters ---------- argv : list Commandline arguments """ #Parse the commandline options. self.parse_command_line(argv) #Call base super(NbConvertApp, self).start() #The last arguments in list will be used by nbconvert if len(self.extra_args) is not 3: print("Wrong number of arguments, use --help flag for usage", file=sys.stderr) sys.exit(-1) export_type = (self.extra_args)[1] ipynb_file = (self.extra_args)[2] #Export return_value = export_by_name(export_type, ipynb_file) if return_value is None: print("Error: '%s' template not found." % export_type) return else: (output, resources, exporter) = return_value #TODO: Allow user to set output directory and file. destination_filename = None destination_directory = None if self.write: #Get the file name without the '.ipynb' (6 chars) extension and then #remove any addition periods and spaces. The resulting name will #be used to create the directory that the files will be exported #into. out_root = ipynb_file[:-6].replace('.', '_').replace(' ', '_') destination_filename = os.path.join(out_root + '.' + exporter.file_extension) destination_directory = out_root + '_files' if not os.path.exists(destination_directory): os.mkdir(destination_directory) #Write the results if self.stdout or not (destination_filename is None and destination_directory is None): self._write_results(output, resources, destination_filename, destination_directory)
def start(self, argv=None): """Entrypoint of NbConvert application. Parameters ---------- argv : list Commandline arguments """ #Parse the commandline options. self.parse_command_line(argv) #Call base super(NbConvertApp, self).start() #The last arguments in list will be used by nbconvert if len(self.extra_args) is not 3: print( "Wrong number of arguments, use --help flag for usage", file=sys.stderr) sys.exit(-1) export_type = (self.extra_args)[1] ipynb_file = (self.extra_args)[2] #Export return_value = export_by_name(export_type, ipynb_file) if return_value is None: print("Error: '%s' template not found." % export_type) return else: (output, resources, exporter) = return_value #TODO: Allow user to set output directory and file. destination_filename = None destination_directory = None if self.write: #Get the file name without the '.ipynb' (6 chars) extension and then #remove any addition periods and spaces. The resulting name will #be used to create the directory that the files will be exported #into. out_root = ipynb_file[:-6].replace('.', '_').replace(' ', '_') destination_filename = os.path.join(out_root+'.'+exporter.file_extension) destination_directory = out_root+'_files' if not os.path.exists(destination_directory): os.mkdir(destination_directory) #Write the results if self.stdout or not (destination_filename is None and destination_directory is None): self._write_results(output, resources, destination_filename, destination_directory)