示例#1
0
def get_doc_info(context, request):
    relpath = request.matchdict['relpath']
    if not relpath:
        raise HTTPFound(location="index.html")
    name = context.project
    version = context.version
    if version == 'latest':
        versions = context.versions
    elif version == 'stable':
        versions = context.stable_versions
    else:
        versions = [version]
    for doc_version in versions:
        doc_path = get_unpack_path(context.stage, name, doc_version)
        if doc_path.check():
            break
    if not doc_path.check():
        if version == 'stable':
            raise HTTPNotFound("No stable documentation available.")
        raise HTTPNotFound("No documentation available.")
    doc_path = doc_path.join(relpath)
    if not doc_path.check():
        raise HTTPNotFound("File %s not found in documentation." % relpath)
    return dict(doc_path=doc_path,
                relpath=relpath,
                doc_version=doc_version,
                version_mismatch=doc_version != navigation_version(context))
示例#2
0
文件: views.py 项目: r2dan/devpi
def get_doc_info(context, request, version=None, check_content=True):
    relpath = request.matchdict['relpath']
    if not relpath:
        raise HTTPFound(location="index.html")
    name = context.project
    if version is None:
        version = context.version
    if version == 'latest':
        versions = context.versions
    elif version == 'stable':
        versions = context.stable_versions
    else:
        versions = [version]
    doc_path = None
    for doc_version in versions:
        try:
            linkstore = context.stage.get_linkstore_perstage(name, doc_version)
        except context.stage.MissesRegistration:
            continue
        links = linkstore.get_links(rel='doczip')
        if not links:
            continue
        doc_path = unpack_docs(context.stage, name, doc_version,
                               links[0].entry)
        if doc_path.check():
            break
    if doc_path is None or not doc_path.check():
        if version == 'stable':
            raise HTTPNotFound("No stable documentation available.")
        raise HTTPNotFound("No documentation available.")
    doc_path = doc_path.join(relpath)
    if check_content and not doc_path.check():
        raise HTTPNotFound("File %s not found in documentation." % relpath)
    return dict(doc_path=doc_path,
                relpath=relpath,
                doc_version=doc_version,
                version_mismatch=doc_version != navigation_version(context))