Digitale bierlijst

seed.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. Provides functions to manage the database while the server is offline.
  3. """
  4. import argparse
  5. import csv
  6. from piket_server import db, Person, Settlement, ConsumptionType, Consumption
  7. def main():
  8. """ Main entry point. """
  9. parser = argparse.ArgumentParser()
  10. subparsers = parser.add_subparsers()
  11. # Clear command
  12. parser_clear = subparsers.add_parser("clear", help="Clear the database.")
  13. parser_clear.set_defaults(func=cmd_clear)
  14. parser_clear.add_argument("--removemydata", action="store_true")
  15. # Parser load_seeds
  16. # TODO
  17. args = parser.parse_args()
  18. args.func(args)
  19. def cmd_clear(args) -> None:
  20. """ Entry point for 'clear' subcommand. """
  21. if not args.removemydata:
  22. print("WARNING! This command will delete all contents in your database!")
  23. print("Type 'removemydata' to continue, anything else or CTRL-C to abort.")
  24. confirmation = input("> ")
  25. do_wipe = confirmation == "removemydata"
  26. else:
  27. do_wipe = True
  28. if do_wipe:
  29. print("Dropping all tables...")
  30. db.drop_all()
  31. print("All data removed. Recreating database...")
  32. db.create_all()
  33. print("Done.")
  34. return
  35. else:
  36. print("Aborting.")
  37. if __name__ == "__main__":
  38. main()