#!/usr/bin/python3

# import os
import sys
import argparse

from erimp import Erimp
from train import Train

desc = 'update train a report'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('-v', action='store_true', help='raise verbosity')
parser.add_argument('-b', action='store_true', help='build, no run')
parser.add_argument('-t', action='store_true', help='do test for new features')
# parser.add_argument('-o', action='store_true', help='show overhang')
parser.add_argument('-s', action='store_true', help='show')
parser.add_argument('-l', action='store_true', help='allow feature training')
parser.add_argument('bapis', metavar='bnp', type=str, nargs='*',
                    help='bits and pieces arguments')
args = parser.parse_args()

e = Erimp(args.bapis, do_verbose=args.v)

repcode = e.given_repcode
if repcode is None:
    print("I can't figure out what your report is.")
    sys.exit()

train = Train(erimp=e, do_verbose=args.v)

if args.s:
    train.show(repcode)
    sys.exit()

# # just for testing
# if args.o:
#    print(train.overhang(repcode, do_verbose=True))
#    quit()#

report = e.report[repcode]
found_source_dates = e.d.dates(report.dirs['source'])
# if found_source_dates is not None and len(found_source_dates) > 0:
#    if (not train.donere(repcode)) and (not args.f):
#        print("I don't need a new model for " + repcode)
#        sys.exit()
# if found_source_dates is None and os.path.isdir(e.dirs['seeds']):
#    from start import Start
#    s = Start(erimp=e, do_verbose=args.v)
#    s.run_train(repcode)
#    print(f"I am done training the starting report {repcode}.")
#    sys.exit()
out = train.build_file(repcode, allow_feature_training=args.l, do_test=args.t)
if not out:
    sys.exit()
if args.b:
    sys.exit()
# train.run(repcode)
