__init__.py 文件源码

python
阅读 66 收藏 0 点赞 0 评论 0

项目:pydoc.io 作者: rtfd 项目源码 文件源码
def update_body(app, pagename, templatename, context, doctree):
    outdir = environ.Path(app.config.html_context['output_directory'])
    project = app.config.project
    version = app.config.version
    if not os.path.exists(outdir.root):
        os.makedirs(outdir.root)
    directory_name = "{name}-{version}".format(name=project, version=version)
    json_dir = outdir.path(directory_name)
    if not os.path.exists(json_dir.root):
        os.makedirs(json_dir.root)
    try:
        out_dir = json_dir.path('/'.join(pagename.split('/')[:-1]))
        if not os.path.exists(out_dir()):
            os.makedirs(out_dir())
        out_file = json_dir.path(pagename + '.json')
        to_write = open(out_file(), 'w+')
        to_context = copy.copy(context)
        # Use list here so we don't get an error on changing dict during iteration
        for key in list(context):
            if key not in KEYS:
                del to_context[key]
        to_write.write(json.dumps(to_context, indent=4))
    except Exception:
        log.exception('Failure in JSON search dump')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号