def get(self, name): """ Retrieve a notebook and return a NotebookNode """ if not name.endswith('.ipynb'): name += '.ipynb' meta = self.store.metadata(name) if meta: try: outf = meta.gridfile except gridfs.errors.NoFile as e: raise e # nbwrite wants a string, outf is bytes sbuf = StringIO() data = outf.read() if data is None: msg = 'Expected content in {name}, got None'.format(**locals()) raise ValueError(msg) sbuf.write(data.decode('utf8')) sbuf.seek(0) nb = nbread(sbuf, as_version=4) return nb else: raise gridfs.errors.NoFile( ">{0}< does not exist in jobs bucket '{1}'".format( name, self.store.bucket))
def put(self): from nbformat import read as nbread om = get_omega(self.args) local = self.args['<path>'] name = self.args['<name>'] with open(local, 'rb') as fin: nb = nbread(fin, as_version=4) self.logger.info(om.jobs.put(nb, name))
def uploadtutorial(ctx, nbname): # uploading does not work because a native dialogue is opened # br.find_by_css('input.fileinput') # br.find_by_css('input.fileinput').click() # opens a native file dialoge from nbformat import read as nbread br = ctx.browser om = ctx.feature.om # upload directly nbfname = os.path.join(ctx.nbfiles, '{nbname}.ipynb'.format(**locals())) nbcells = nbread(nbfname, as_version=4) om.jobs.put(nbcells, nbname) # now run the notebook br.visit(ctx.feature.jynb_url) assert br.is_text_present(nbname)