Esempio n. 1
0
def gen_pdf_file(doc_id):
    cmd = []
    cmd.append('wkhtmltopdf')
    cmd.append('http://{host_url}/{doc_id}?stylesheet=print'.format(host_url=app.config.get('HOST_URL', 'localhost'), doc_id=doc_id))
    fname = '{tmpdir}/{doc_id}.pdf'.format(tmpdir=tempfile.gettempdir(), doc_id=doc_id)
    cmd.append(fname)
    logger.debug(cmd)
    try:
        subprocess.check_call(cmd)
        logger.info("generated {fname}".format(fname=fname))
    except subprocess.CalledProcessError as error:
        logger.error("Error trying to generate pdf file with command '{cmd}': {error}".format(error=error, cmd=error.cmd))
    return fname
Esempio n. 2
0
def apply_microcommit(doc, mc):
    logger.info(json.dumps(mc, indent=4))
    d = doc.md_content.splitlines()
    start_pos = {'col': mc['range']['start']['column'], 'row': mc['range']['start']['row']}
    end_pos = {'col': mc['range']['end']['column'], 'row': mc['range']['end']['row']}
    if(mc['action'] == 'insertText'):
        try:
            d[start_pos['row']] = d[start_pos['row']][:start_pos['col']] + mc["text"] + d[end_pos['row']][end_pos['col']-len(mc["text"]):]
        except IndexError:
            d.append(mc["text"])
        logger.info("start_pos: {0}, end_pos: {1}".format(start_pos, end_pos))
    elif(mc['action'] == 'removeText'):
        d[start_pos['row']] = d[start_pos['row']][:start_pos['col']] + d[start_pos['row']][start_pos['col']:end_pos['col']].replace(mc['text'], "") + d[end_pos['row']][end_pos['col']:]
    elif(mc['action'] == 'insertLines'):
        d = d[:start_pos['row']] + mc['lines'] + d[end_pos['row']:]
    elif(mc['action'] == 'removeLines'):
        del d[start_pos['row']:end_pos['row']]
    else:
        logger.info("'action' is not recognized: {0}".format(mc['action']))
    doc.md_content = "\n".join(d)
Esempio n. 3
0
def doc_new():
    "Creates a new document, and redirects to his URL"
    doc = models.new_document()
    logger.info("New document '{doc_id}' has been created".format(doc_id=doc.url_id))
    return redirect(url_for("doc_edit", doc_id=doc.url_id))