Exemple #1
0
def ImportTestcasesFromDirectory(
  session: db.session_t, testcases_dir: pathlib.Path
) -> None:
  """Import Testcases from a directory of protos.

  Args:
    session: A database session.
    testcases_dir: Directory containing (only) Testcase protos.
  """
  files_to_delete = []
  last_commit_time = time.time()
  if not testcases_dir.is_dir():
    app.Fatal("directory %s does not exist", testcases_dir)
  for path in progressbar.ProgressBar()(testcases_dir.iterdir()):
    deeplearning.deepsmith.testcase.Testcase.FromFile(session, path)
    files_to_delete.append(path)
    app.Log(1, "Imported testcase %s", path)
    if time.time() - last_commit_time > 10:
      session.commit()
      if FLAGS.delete_after_import:
        for path in files_to_delete:
          path.unlink()
      files_to_delete = []
      last_commit_time = time.time()
      app.Log(1, "Committed database")
  session.commit()
  if FLAGS.delete_after_import:
    for path in files_to_delete:
      path.unlink()
Exemple #2
0
def ImportResultsFromDirectory(session: db.session_t,
                               results_dir: pathlib.Path) -> None:
  """Import Results from a directory of protos.

  Args:
    session: A database session.
    results_dir: Directory containing (only) Result protos.
  """
  files_to_delete = []
  last_commit_time = time.time()
  if not results_dir.is_dir():
    logging.fatal('directory %s does not exist', results_dir)
  for path in progressbar.ProgressBar()(results_dir.iterdir()):
    deeplearning.deepsmith.result.Result.FromFile(session, path)
    files_to_delete.append(path)
    logging.info('Imported result %s', path)
    if time.time() - last_commit_time > 10:
      session.commit()
      if FLAGS.delete_after_import:
        for path in files_to_delete:
          path.unlink()
      files_to_delete = []
      last_commit_time = time.time()
      logging.info('Committed database')
  session.commit()
  if FLAGS.delete_after_import:
    for path in files_to_delete:
      path.unlink()