#!/Users/victor/development/scripts/venv/bin/python
import optparse
import csv
import sys
import re
import itertools
from pcsv.pindent import pindent

def readCL():
    usagestr = "%prog"
    parser = optparse.OptionParser(usage=usagestr)
    parser.add_option("-f","--infile")
    parser.add_option("-c","--code")
    parser.add_option("-p","--print_formatted", action="store_true")
    options, args = parser.parse_args()
    if not options.infile:
        f_in = sys.stdin
    else:
        f_in = open(options.infile)
    return f_in, options.code, options.print_formatted
        

if __name__ == "__main__":
    f_in, code, print_formatted = readCL()
    if code:
        code_string = code
    else:
        code_string = f_in.read()

    if print_formatted:
        sys.stdout.write(pindent(code_string) + "\n")
    else:
        exec(pindent(code_string))
    
