import operator
from traceback import format_exc, extract_stack, format_list

from util import get_segments
from ..util import set_LOOKUPS
from ..segment import segment_list
from ..transform import *
from ..configuration import dir_map

#TODO change this to only run one segment, cmd should start new process for each segment
def run(**opt):
    opt['segments'] = get_segments('validate', **opt)
    set_LOOKUPS()
    try:
        for segment in segment_list:
            if segment.get('label') == 'subject':
                continue
            
            #segment.validate_rules = True
            opt['rules'] = dir_map['pre_process_rules_dir']
            rules = get_rules(['1', '2', '3'], segment, **opt)
            
            opt['rules'] = dir_map['process_rules_dir']
            rules = get_rules(['1', '2', '3', '4'], segment, **opt)
            
    except:
        if opt['verbose']:
            raise
        return (format_exc(), format_list(extract_stack())) 
        