#!/usr/bin/env python
# TODO: After collate has run, should open into shell for interaction
#       with the instance
from collate import Collate
import logging
import optparse

logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s %(levelname)s %(message)s')

def param_callback(option, opt, value, parser):
    setattr(parser.values, option.dest, value.split(','))

def main():
    usage = "usage: %prog [options]"
    parser = optparse.OptionParser(usage)
    parser.add_option("-a", "--set-a", dest="argsA",
                    type="string",
                    action="callback",
                    callback=param_callback,
                    default=False,
                    help="Required opt: first CSV to compare")
    parser.add_option("-b", "--set-b", dest="argsB",
                    type="string",
                    action="callback",
                    callback=param_callback,
                    default=False,
                    help="Required opt: second CSV to compare")
    options, args = parser.parse_args()

    if len(args) < 2:
        parser.error('First two args must be CSV files')
    
    if options.argsA and options.argsB:
        c = Collate(args[0], args[1], options.argsA, options.argsB)
    elif options.argsA:
        c = Collate(args[0], args[1], options.argsA)
    else:
        c = Collate(args[0], args[1])
    
    print "Lost rows:        %s" % ( c.p_erased(pretty=True) ) 
    print "Intact rows:      %s" % ( len(c.clean) ) 
    print "Added:            %s" % ( len(c.added) ) 
if __name__ == "__main__":
    main()
