Beispiel #1
0
def _try_delete(doc):
    unlink('docs/%s' % doc.pathname)
    if os.path.isdir('docs/.git'):
        pn = './%s' % doc.pathname
        msg = 'kb: removed "%s" via web' % doc.filename
        p = Popen(args = ['git', 'rm', '--', pn], cwd = 'docs')
        p.wait()
        p = Popen(args = ['git', 'commit', '-m', msg], cwd = 'docs')
        p.wait()
    doc.delete()
Beispiel #2
0
def _pdf_url(req, name):
    if name.startswith("/static/kbfiles/"):
        name = os.getcwd() + name
        dir = os.path.dirname(name)
        base = os.path.basename(name)
        if not os.path.exists(name):
            return "invalid-path"
        if base.endswith(".gif"):
            # pdflatex can't handle .gif files, sigh
            outdir = os.path.join(dir, ".convert")
            pngname = os.path.join(outdir, base[:-4] + '.png')
            if not os.path.exists(pngname) \
                    or os.path.getmtime(name) >= os.path.getmtime(pngname):
                mkdirp(outdir)
                unlink(pngname)
                im = Image.open(name)
                im.save(pngname, "PNG")
            return pngname
        else:
            return name
    else:
        return req.build_absolute_uri(name)