Exemple #1
0
def notebook_cell_outputs_to_html(rv, outputs, _cls):
    # check this is image cell
    logging.debug("notebook_cell_outputs_to_html {}".format(_cls))
    html = None
    img_cell = False
    for output in outputs:
        if 'data' in output.keys():
            if 'image/png' in output['data']:
                img_cell = True

    for output in outputs:
        opkeys = output.keys()
        if 'name' in opkeys:
            if 'text' in output:
                html = ''.join(output['text'])
        elif 'data' in opkeys:
            if 'image/png' in output['data']:
                imgdata = output['data']['image/png']
                html = '<img src="data:image/png;base64,%s"></img>' % imgdata
            elif 'text/html' in output['data']:
                html = ''.join(output['data']['text/html'])
            elif 'text/plain' in output['data'] and not img_cell:
                html = output['data']['text/plain']
        elif 'ename' in opkeys:
            html = ansi_escape.sub('', output['traceback'][-1])
        if html is not None:
            rv.append(div(html, _cls))
Exemple #2
0
def poll_view(task_id):
    logging.debug('poll_view {}'.format(task_id))
    from wzdat.dashboard.tasks import run_view_cell

    try:
        task = run_view_cell.AsyncResult(task_id)
        state = task.state
        if state == 'PENDING':
            return 'PROGRESS:0'
        logging.debug("{} - {}".format(task.state, task.status))
        if task.state == 'PROGRESS':
            return 'PROGRESS:' + str(task.result)
        outputs = task.get()
    except Exception, e:
        logging.debug('poll_view - ' + unicode(e))
        err = task.traceback
        logging.error(err)
        err = ansi_escape.sub('', err)
        return Response('<div class="view"><pre class="ds-err">%s</pre></div>'
                        % err)
Exemple #3
0
            else:
                logging.debug(u"run info not exist")
                return 'PROGRESS:0'
        nodata = task.get()
        if nodata is not None:
            return Response(nodata)
    except NoDataFound, e:
        logging.debug(unicode(e))
        return Response(u'<div class="view"><pre class="ds-err">{}</pre></div>'
                        .format(unicode(e)))
    except Exception, e:
        logging.debug(str(e))
        logging.error(e)
        err = task.traceback
        logging.error(err)
        err = ansi_escape.sub('', err)
        return Response('<div class="view"><pre class="ds-err">%s</pre></div>'
                        % err)
    ret = _poll_rerun_output(nbapath)
    logging.debug(str(ret))
    return Response(ret)


def _poll_rerun_output(nbapath):
    rv = []
    with open(nbapath, 'r') as f:
        nb = reads(f.read(), IPYNB_VER)
        if len(nb) > 0:
            try:
                for cell in nb['cells']:
                    _type = cell['cell_type']