builder.py 文件源码

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

项目:kudubot 作者: namboy94 项目源码 文件源码
def build(service_directory):
    """
    Builds a Service using the service configuration
    inside the service directory.

    :param service_directory: The location of the service directory
    :return: The path to the generated executable file
    """

    service_name = os.path.basename(service_directory)
    current_dir = os.getcwd()
    os.chdir(service_directory)

    with open("service.json", 'r') as f:
        config = json.load(f)

    try:
        Popen(config["build_commands"]).wait()
    except BaseException as e:
        print(e)
        os.chdir(current_dir)
        return

    output = config["output_file"]
    st = os.stat(output)
    os.chmod(output, st.st_mode | stat.S_IEXEC)  # Make executable

    if os.path.basename(output) != service_name:
        new_output = os.path.join(os.path.dirname(output), service_name)
        os.rename(output, new_output)
        output = new_output

    os.chdir(current_dir)

    return os.path.join(service_directory, output)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号