operations.py 文件源码

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

项目:hyperhelp 作者: OdatNurd 项目源码 文件源码
def _load_index(package, index_file):
    """
    Takes a package name and its associated hyperhelp.json index resource name
    and loads it. Returns None on failure or a HelpData tuple for the loaded
    help information on success.
    """
    try:
        _log("Loading help index for package %s", package)
        json = sublime.load_resource(index_file)
        raw_dict = sublime.decode_value(json)

    except:
        return _log("Unable to load help index from '%s'", index_file)

    # Extract all known top level dictionary keys from the help index
    description = raw_dict.pop("description", "No description available")
    doc_root = raw_dict.pop("doc_root", None)
    toc = raw_dict.pop("toc", None)
    help_files = raw_dict.pop("help_files", dict())
    package_files = raw_dict.pop("package_files", dict())
    urls = raw_dict.pop("urls", dict())

    # Warn about unknown keys still in the dictionary; they are harmless, but
    # probably the author did something dodgy.
    for key in raw_dict.keys():
        _log("Unknown key '%s' in help index for package '%s'", key, package)

    if doc_root is None:
        doc_root = path.split(index_file)[0]
    else:
        doc_root = path.normpath("Packages/%s/%s" % (package, doc_root))

    # Pull in all the topics.
    topics = dict()
    _process_topic_dict(package, topics, help_files)
    _process_topic_dict(package, topics, package_files)
    _process_topic_dict(package, topics, urls)

    if toc is None:
        toc = [topics.get(topic) for topic in sorted(topics.keys())]
    else:
        _validate_toc(package, toc, topics)

    return HelpData(package, description, index_file, doc_root, topics,
                    sorted(help_files.keys()),
                    sorted(package_files.keys()),
                    list(urls.keys()),
                    toc)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号