#!/usr/bin/env python3
import os
import yaml

if __name__ == "__main__this_is_broken":
    if "GO_PIPELINE_LABEL" in os.environ:
        version = os.environ["GO_PIPELINE_LABEL"]
        appimage_yaml = yaml.safe_load(open("AppImageBuilder.yml"))
        appimage_old_version = appimage_yaml["AppDir"]["app_info"]["version"]
        appimage_yaml["AppDir"]["app_info"]["version"] = version
        with open(f"AppImageBuilder{version}.yml","wb") as yaml_file:
            yaml.safe_dump(appimage_yaml, yaml_file, encoding = 'utf-8')
            print(f"New AppImageBuilder file written: {yaml_file.name}")
    else:
        print("No GO_PIPELINE_LABEL found, doing nothing")

if __name__ == "__main__":
    if "GO_PIPELINE_LABEL" in os.environ:
        version = os.environ["GO_PIPELINE_LABEL"]
        src_version = open("AppImageBuilder.yml").readlines()
        with open(f"AppImageBuilder{version}.yml","w") as new_version:
            for line in src_version:
                cp_line = line.replace("version: _devel_", f'version: "{version}"')
                new_version.write(f"{cp_line}")




