debian.py 文件源码

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

项目:niceman 作者: ReproNim 项目源码 文件源码
def get_spec_from_release_file(content):
    """Provide specification object describing the component of the distribution
    """
    # RegExp to pull a single line "tag: value" pair from a deb822 file
    re_deb822_single_line_tag = re.compile("""
        ^(?P<tag>[a-zA-Z][^:]*):[\ ]+  # Tag - begins at start of line
        (?P<val>\S.*)$           # Value - after colon to the end of the line
    """, flags=re.VERBOSE + re.MULTILINE)

    # Split before PGP signature if present
    content = content.split("-----BEGIN PGP SIGNATURE-----")[0]

    # Parse the content for tags and values into a dictionary
    release = {
        match.group("tag"): match.group("val")
        for match in re_deb822_single_line_tag.finditer(content)
    }

    # TODO: redo with conversions of components and architectures in into lists
    # and date in machine-readable presentation
    return DebianReleaseSpec(**{
        a.name: release.get(a.name.title(), None)
        for a in attr.fields(DebianReleaseSpec)
        })
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号