from tests import *
from HTMLgenerator import generateLatencyGraphHTML, generateChangesHTML, generateRequestsMinGraphHTML
from configParser import getConfig
import sys

graphBoolean = sys.argv[1]


def delFolder(folder):
    for the_file in os.listdir(folder):
        file_path = os.path.join(folder, the_file)
        try:
            if os.path.isfile(file_path):
                os.unlink(file_path)
        except Exception as e:
            print(e)


if graphBoolean == "true":
    delFolder('Graphs/GraphsLatency')
    delFolder('Graphs/GraphsRequestsMin')

cfg = getConfig("config.yml")[0]

call_list = {
    'longstringOUT': longstringOUT,
    'longstringIN': longstringIN,
    'flatIN': flatIN,
    'flatOUT': flatOUT,
    'nestedIN': nestedIN,
    'nestedOUT': nestedOUT,
    'BLOBattachmentIN': BLOBattachmentIN,
    'BLOBattachmentOUT': BLOBattachmentOUT,
    'BLOBbase64IN': BLOBbase64IN,
    'BLOBbase64OUT': BLOBbase64OUT,
    'BLOBhexIN': BLOBhexIN,
    'BLOBhexOUT': BLOBhexOUT,
    'longstringattachmentOUT': longstringattachmentOUT,
    'longstringattachmentIN': longstringattachmentIN
}



for i in cfg:
    if cfg[i]['IN']['include']:
        for j in cfg[i]['threads']:
            call_list[i+"IN"](int(j), int(cfg[i]['duration']), cfg[i]['IN']['value'], graphBoolean)
    if cfg[i]['OUT']['include']:
        for j in cfg[i]['threads']:
            call_list[i+"OUT"](int(j), int(cfg[i]['duration']), cfg[i]['OUT']['value'], graphBoolean)


if graphBoolean == "true":
    generateLatencyGraphHTML("Graphs/GraphsLatency")
    generateRequestsMinGraphHTML("Graphs/GraphsRequestsMin")
    generateChangesHTML("changes.csv")

open("changes.csv", "w").close()
open("TestJMX/Attachment_File", "w").close()
