from sys import argv
from modules.pinger import *

if len(argv) > 1:
    flag = argv[1]
else:
    flag = ""

# Gets Configuration Files
ConfigFiles = []
for config_file in os.listdir("./InfrastructureItems"):
    if config_file.endswith(".txt"):
        ConfigFiles.append("InfrastructureItems/" + config_file)

print "Testing All Core Systems...\n"

for i in range(len(ConfigFiles)):
    print systemname % ConfigFiles[i]
    devices = open(ConfigFiles[i], "r")
    lines = devices.readlines()
    pinger(lines, flag)
    devices.close()
    print systemname
print "\n\n\n"
def health_check(verbose):
    import os
    while True:
        os.system('cls')
        print "\n"
        print "Welcome to the Health Check Scanner"
        print "\n"
        print "Press 1 to run a full environment scan."
        print "Press 2 to run a scan against an specific environment."
        print "Press 3 to Exit."
        print "\n"

        choice = raw_input("Enter your choice: ")
        if choice == "1":
            if "v" in verbose:
                flag = "v"
            else:
                flag = ""

            config_files = []
            for config_file in os.listdir("./InfrastructureItems"):
                if config_file.endswith(".txt"):
                    config_files.append("InfrastructureItems/" + config_file)

            print "Testing All Core Systems...\n"

            for i in range(len(config_files)):
                print systemname % config_files[i]
                devices = open(config_files[i], "r")
                lines = devices.readlines()
                pinger(lines, flag)
                devices.close()
            print "\n\033[1;37mScan Completed Successfully.\033[1;m\n"
            raw_input("Press enter to continue...")
            os.system("cls")

        elif choice == "2":
            if "v" in verbose:
                flag = "v"
            else:
                flag = ""

            options = []
            for config_file in os.listdir("./InfrastructureItems"):
                if config_file.endswith(".txt"):
                    options.append(config_file)
            nums_and_files = zip(range(len(options)), options)
            os.system("cls")
            print "\nAvailable lists to modify: \n"
            for x in nums_and_files:
                print x
            choice = raw_input(
                "Please type number of desired environment to scan or type 'exit' to quit: "
            )

            if not choice.isdigit():
                os.system("cls")
                break
            elif int(choice) in range(len(options)):
                file_location = "./InfrastructureItems/" + options[int(choice)]
                selected_file = open(file_location, "r")
                config_files = [0]
                print "\nTesting selected System...\n"
                for i in range(len(config_files)):
                    devices = selected_file
                    lines = devices.readlines()
                    pinger(lines, flag)
                    devices.close()
                print "\n\033[1;37mScan Completed Successfully.\033[1;m\n"
                selected_file.close()
                raw_input("Press enter to continue...")
                os.system("cls")

            else:
                os.system('cls')
                break

        elif choice == "3":
            os.system('cls')
            break
def health_check(verbose):
    import os
    while True:
        os.system('cls')
        print "\n"
        print "Welcome to the Health Check Scanner"
        print "\n"
        print "Press 1 to run a full environment scan."
        print "Press 2 to run a scan against an specific environment."
        print "Press 3 to Exit."
        print "\n"

        choice = raw_input("Enter your choice: ")
        if choice == "1":
            if "v" in verbose:
                flag = "v"
            else:
                flag = ""

            config_files = []
            for config_file in os.listdir("./InfrastructureItems"):
                if config_file.endswith(".txt"):
                    config_files.append("InfrastructureItems/" + config_file)

            print "Testing All Core Systems...\n"

            for i in range(len(config_files)):
                print systemname % config_files[i]
                devices = open(config_files[i], "r")
                lines = devices.readlines()
                pinger(lines, flag)
                devices.close()
            print "\n\033[1;37mScan Completed Successfully.\033[1;m\n"
            raw_input("Press enter to continue...")
            os.system("cls")

        elif choice == "2":
            if "v" in verbose:
                flag = "v"
            else:
                flag = ""

            options = []
            for config_file in os.listdir("./InfrastructureItems"):
                if config_file.endswith(".txt"):
                    options.append(config_file)
            nums_and_files = zip(range(len(options)), options)
            os.system("cls")
            print "\nAvailable lists to modify: \n"
            for x in nums_and_files:
                print x
            choice = raw_input("Please type number of desired environment to scan or type 'exit' to quit: ")

            if not choice.isdigit():
                os.system("cls")
                break
            elif int(choice) in range(len(options)):
                file_location = "./InfrastructureItems/" + options[int(choice)]
                selected_file = open(file_location, "r")
                config_files = [0]
                print "\nTesting selected System...\n"
                for i in range(len(config_files)):
                    devices = selected_file
                    lines = devices.readlines()
                    pinger(lines, flag)
                    devices.close()
                print "\n\033[1;37mScan Completed Successfully.\033[1;m\n"
                selected_file.close()
                raw_input("Press enter to continue...")
                os.system("cls")

            else:
                os.system('cls')
                break

        elif choice == "3":
            os.system('cls')
            break