import yaml
from pathlib import Path


with open("config.yml") as ymlfile:
    cfg = yaml.load(ymlfile, Loader=yaml.FullLoader)

with open("TestJMX/loadXMLtest.jmx", "r") as f:
    file = f.readlines()


folderpath = str(Path(__file__).absolute()).replace("/jmeterConfSetup.py", "")
file[38] = file[38].replace("PATH_TO_FOLDER", folderpath)
file[43] = file[43].replace("HOST_VALUE", str(cfg["host"]))
file[44] = file[44].replace("PORT_VALUE", str(cfg["port"]))
file[45] = file[45].replace("PROTOCOL_VALUE", str(cfg["protocol"]))
file[47] = file[47].replace("PATH_VALUE", str(cfg["path"]))

with open("TestJMX/loadXML.jmx", "w") as f:
    for i in file:
        f.write(i)

with open("TestJMX/loadXMLattachmenttest.jmx", "r") as f:
    file = f.readlines()


# https://uxp-hendrik-load.cloud.cyber.ee:4400/service
file[28] = file[28].replace("URL_VALUE", cfg["protocol"]+"://"+cfg["host"]+":"+str(cfg["port"])+cfg["path"])
file[29] = file[29].replace("PATH_TO_FOLDER", folderpath)

with open("TestJMX/loadXMLattachment.jmx", "w") as f:
    for i in file:
        f.write(i)
