shellscript.py 文件源码

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

项目:charm-glusterfs 作者: openstack 项目源码 文件源码
def parse(f: IO[Any]) -> Result:
    """
    Parse a shellscript and return a ShellScript
    :param f: TextIOBase handle to the shellscript file
    :return: Result with Ok or Err
    """
    comments = []
    commands = []
    interpreter = ""

    buf = f.readlines()

    for line in buf:
        trimmed = line.strip()
        if trimmed.startswith("#!"):
            interpreter = trimmed
        elif trimmed.startswith("#"):
            comments.append(str(trimmed))
        else:
            # Skip blank lines
            if trimmed:
                commands.append(str(trimmed))
    return Ok(ShellScript(interpreter=interpreter,
                          comments=comments,
                          commands=commands))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号