from os.path import join

import cardsharp as cs
from util import *
from ..configuration import config, db_info
from ..segment import Segment
from ..recid_rules_db.load import db_load

def load_recid_db(cmd):
    args = cmd.args
    #create the options dictionary
    for _seg in ['arrest', 'sentence']:
        #initialize the segment and load the variable metadata
        opt = {
               'in_dir': join(args.in_dir, 'transform', _seg),
               'stand_db_info': db_info['stand'],
               'recid_db_info': db_info['recid'],
               'meta_dir': args.metadata,
               'log_dir': create_log_dir(join(config.log_dir, 'set_%i' % config.current_set, 'db_load')),
               'tmp_out_dir': config.tmp_out_dir,
               'out_format': args.out_format,
               'verbose': args.verbose
              }
        segment = Segment(_seg, 'transform', **opt)
        segment.load_metadata_variables()
        #opt['segment'] = segment
#        cs.wait()
        db_load(segment, **opt)
        
#        cmd.task_queue.put(opt)
# 
#    cmd.start() #start the worker threads
#    cmd.task_queue.join() #wait for the workers to finish
#    cmd.flush() #flush the cmd logs
