#
#
#
import argparse
import time

from libs import fingerprint


def main():
  (filein, fileout, filejson, verbose) = parseArgs()

  db = fingerprint.DBSchema()
  if (fileout):
    retVal = db.scanDBFile(filein)
    if (retVal > 0):
      fh = open(fileout, "w")
      db.debugFingerprint()
      db.writeFingerprint(fh)
      fh.close()
    else:
      print db.getErrorString(retVal)
  elif (filejson):
    db.importDBSchema(filejson)
    db.debugFingerprint()


def parseArgs():
  verbose = False
  timestr = time.strftime('%Y-%m-%d_%H%M%S', time.localtime(time.time()))
  parser = argparse.ArgumentParser(description='Fingerprint a sqlite database based on its schema')
  parser.add_argument('-f', '--file', required=False)
  parser.add_argument('-j', '--json', required=False)
  parser.add_argument('-v', '--verbose', action='store_true')
  args = parser.parse_args()
  if (args.verbose):
    verbose = args.verbose
  fileout = args.file + "_" + timestr + '.json'
  return (args.file, fileout, args.json, verbose)


if __name__ == "__main__":
  main()
