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