# Path: src/helper_functions.py
# def grab_all(connection, cmd, *args):
#     return connection.execute(cmd, *args).fetchall()
# 
# def load_options(f_option_file="options_simple_connected.json"):
#     # Load the file into a string
#     try:
#         with open(f_option_file) as FIN:
#             raw_text = FIN.read()
#     except:
#         msg = "Couldn't find option file {}".format(f_option_file)
#         raise IOError(msg)
# 
#     # Parse the text as json
#     try:
#         return json.loads(raw_text)
#     except Exception as Ex:
#         msg = "Couldn't parse JSON file {}, {}".format(f_option_file, Ex)
#         raise IOError(msg)


import sqlite3
import logging
import argparse
from src.helper_functions import grab_all, load_options

desc = "Output the computed relations between the invariant sequences"
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('-f', '--force', default=False, action='store_true')
cargs = vars(parser.parse_args())

# Start the logger
logging.root.setLevel(logging.INFO)

ignored_functions = []

# Connect to the database and add structure info
f_seq_database = "database/sequence.db"
seq_conn = sqlite3.connect(f_seq_database, check_same_thread=False)

# Load the list of invariants to compute
options = load_options()
func_names = options["invariant_function_names"]

# These will use a different operator
special_conditionals = options["sequence_info"]["special_conditionals"]

# These variants will not be used in the powerset construction
excluded_terms = options["sequence_info"]["excluded_terms"]

# Build the lookup table
cmd = '''SELECT function_name,invariant_id FROM ref_invariant_integer
ORDER BY invariant_id'''

# Path: src/helper_functions.py
# def grab_all(connection, cmd, *args):
#     return connection.execute(cmd, *args).fetchall()
# 
# def load_options(f_option_file="options_simple_connected.json"):
#     # Load the file into a string
#     try:
#         with open(f_option_file) as FIN:
#             raw_text = FIN.read()
#     except:
#         msg = "Couldn't find option file {}".format(f_option_file)
#         raise IOError(msg)
# 
#     # Parse the text as json
#     try:
#         return json.loads(raw_text)
#     except Exception as Ex:
#         msg = "Couldn't parse JSON file {}, {}".format(f_option_file, Ex)
#         raise IOError(msg)


# Path: verification/raw_dump_relations.py
import sqlite3
import logging
import argparse
from src.helper_functions import grab_all, load_options


desc = "Output the computed relations between the invariant sequences"
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('-f', '--force', default=False, action='store_true')
cargs = vars(parser.parse_args())

# Start the logger
logging.root.setLevel(logging.INFO)

ignored_functions = []

# Connect to the database and add structure info
f_seq_database = "database/sequence.db"
seq_conn = sqlite3.connect(f_seq_database, check_same_thread=False)

# Load the list of invariants to compute
options = load_options()
func_names = options["invariant_function_names"]

# These will use a different operator
special_conditionals = options["sequence_info"]["special_conditionals"]

# These variants will not be used in the powerset construction
excluded_terms = options["sequence_info"]["excluded_terms"]

# Build the lookup table
cmd = '''SELECT function_name,invariant_id FROM ref_invariant_integer
ORDER BY invariant_id'''

ref_lookup = dict(grab_all(seq_conn, cmd))