#!/usr/bin/env python
# -*- python -*-
from __future__ import print_function
import os, sys, re, time, datetime, argparse
from LMODdb       import LMODdb
from BeautifulTbl import BeautifulTbl

class CmdLineOptions(object):
  """ Command line Options class """

  def __init__(self):
    """ Empty Ctor """
    pass

  def execute(self):
    """ Specify command line arguments and parse the command line"""
    parser = argparse.ArgumentParser()
    now    = time.strftime("%Y-%m-%d")
    parser.add_argument("--dbname",     dest='dbname',     action="store", default = "lmod",       help="lmod db name")
    parser.add_argument("--start",      dest='startDate',  action="store", default = "1970-01-01", help="start date")
    parser.add_argument("--end",        dest='endDate',    action="store", default = now,          help="end date")

    args = parser.parse_args()
    return args

def dbConfigFn(dbname):
  """
  Build config file name from dbname.
  @param dbname: db name
  """
  return dbname + "_db.conf"

def main():
  args     = CmdLineOptions().execute()
  configFn = dbConfigFn(args.dbname)
  lmod     = LMODdb(configFn)

  lmod.dump_db(args.startDate, args.endDate)

if ( __name__ == '__main__'): main()
