# Path: logparser/logmatch/regexmatch.py
# class PatternMatch(object):
#     def __init__(self, outdir='./result/', n_workers=1, optimized=False, logformat=None):
#     def add_event_template(self, event_template, event_Id=None):
#     def _generate_template_regex(self, template):
#     def match_event(self, event_list):
#     def read_template_from_csv(self, template_filepath):
#     def match(self, log_filepath, template_filepath):
#     def _dump_match_result(self, log_filename, log_dataframe):
#     def _generate_hash_eventId(self, template_str):
#     def _get_parameter_list(self, row):
# def match_fn(event_list, template_match_dict, optimized=True):
# def regex_match(msg, template_match_dict, optimized):


import sys
import hashlib
import pandas as pd
import re
import subprocess
import os
from datetime import datetime
from ..logmatch import regexmatch

            subprocess.check_output('gcc -o ../logparser/SLCT/slct -O2 ../logparser/SLCT/cslct.c', 
                stderr=subprocess.STDOUT, shell=True)
        except:
            print("Compile error! Please check GCC installed.\n")
            raise

    headers, regex = generate_logformat_regex(log_format)
    df_log = log_to_dataframe(logname, regex, headers, log_format)

    # Generate input file
    with open('slct_input.log', 'w') as fw:
        for line in df_log['Content']:
            if rex:
                for currentRex in rex:
                    line = re.sub(currentRex, '<*>', line)
            fw.write(line + '\n')

    # Run SLCT command
    SLCT_command = extract_command(para, "slct_input.log")
    try:
        print ("Run SLCT...\n>> {}".format(SLCT_command))
        subprocess.check_call(SLCT_command, shell=True)
    except:
        print("SLCT executable is invalid! Please compile it using GCC.\n")
        raise

    # Collect and dump templates
    tempParameter = TempPara(path = "./", savePath=para['savePath'], logname="slct_input.log")
    tempProcess(tempParameter)


# Path: logparser/logmatch/regexmatch.py
# class PatternMatch(object):
#     def __init__(self, outdir='./result/', n_workers=1, optimized=False, logformat=None):
#     def add_event_template(self, event_template, event_Id=None):
#     def _generate_template_regex(self, template):
#     def match_event(self, event_list):
#     def read_template_from_csv(self, template_filepath):
#     def match(self, log_filepath, template_filepath):
#     def _dump_match_result(self, log_filename, log_dataframe):
#     def _generate_hash_eventId(self, template_str):
#     def _get_parameter_list(self, row):
# def match_fn(event_list, template_match_dict, optimized=True):
# def regex_match(msg, template_match_dict, optimized):


# Path: logparser/SLCT/SLCT.py
import sys
import hashlib
import pandas as pd
import re
import subprocess
import os
from datetime import datetime
from ..logmatch import regexmatch

            subprocess.check_output('gcc -o ../logparser/SLCT/slct -O2 ../logparser/SLCT/cslct.c', 
                stderr=subprocess.STDOUT, shell=True)
        except:
            print("Compile error! Please check GCC installed.\n")
            raise

    headers, regex = generate_logformat_regex(log_format)
    df_log = log_to_dataframe(logname, regex, headers, log_format)

    # Generate input file
    with open('slct_input.log', 'w') as fw:
        for line in df_log['Content']:
            if rex:
                for currentRex in rex:
                    line = re.sub(currentRex, '<*>', line)
            fw.write(line + '\n')

    # Run SLCT command
    SLCT_command = extract_command(para, "slct_input.log")
    try:
        print ("Run SLCT...\n>> {}".format(SLCT_command))
        subprocess.check_call(SLCT_command, shell=True)
    except:
        print("SLCT executable is invalid! Please compile it using GCC.\n")
        raise

    # Collect and dump templates
    tempParameter = TempPara(path = "./", savePath=para['savePath'], logname="slct_input.log")
    tempProcess(tempParameter)


    matcher = regexmatch.PatternMatch(outdir=para['savePath'], logformat=log_format)
