3 Commits

Author SHA1 Message Date
vegardbm 10bffd53e8 handle quitters 2026-06-06 02:27:59 +02:00
vegardbm a91aa3c617 fix config-template comment for db type 2026-06-06 01:22:18 +02:00
vegardbm 779312cd9f fix autoflush SA warning 2026-06-06 01:21:53 +02:00
3 changed files with 40 additions and 46 deletions
+4 -1
View File
@@ -3,7 +3,7 @@ debug = true
debug_sql = false debug_sql = false
[database] [database]
# One of (sqlite, postgres) # One of (sqlite, postgresql)
type = 'sqlite' type = 'sqlite'
[database.sqlite] [database.sqlite]
@@ -38,3 +38,6 @@ dryrun = false
warn_days_before_borrowing_deadline = [ 5, 1 ] warn_days_before_borrowing_deadline = [ 5, 1 ]
days_before_queue_position_expires = 14 days_before_queue_position_expires = 14
warn_days_before_expiring_queue_position_deadline = [ 3, 1 ] warn_days_before_expiring_queue_position_deadline = [ 3, 1 ]
[general]
quit_allowed = true
+7 -17
View File
@@ -16,6 +16,7 @@ from worblehat.models import *
from worblehat.services import ( from worblehat.services import (
create_bookcase_item_from_isbn, create_bookcase_item_from_isbn,
is_valid_isbn, is_valid_isbn,
Config,
) )
from .subclis import ( from .subclis import (
@@ -47,26 +48,13 @@ class WorblehatCli(NumberedCmd):
self.sql_session_dirty = False self.sql_session_dirty = False
self.prompt_header = None self.prompt_header = None
@classmethod def run_with_safe_exit_wrapper(self) -> None:
def run_with_safe_exit_wrapper(cls, sql_session: Session) -> None:
tool = cls(sql_session)
while True: while True:
try: try:
tool.cmdloop() self.cmdloop()
except KeyboardInterrupt: except KeyboardInterrupt:
if not tool.sql_session_dirty: print("\n\n-----------------\n")
exit(0) self.do_exit("Exit")
try:
print()
if prompt_yes_no(
"Are you sure you want to exit without saving?",
default=False,
):
raise KeyboardInterrupt
except KeyboardInterrupt:
if tool.sql_session is not None:
tool.sql_session.rollback()
exit(0)
def do_show_bookcase(self, arg: str) -> None: def do_show_bookcase(self, arg: str) -> None:
bookcase_selector = InteractiveItemSelector( bookcase_selector = InteractiveItemSelector(
@@ -133,6 +121,7 @@ class WorblehatCli(NumberedCmd):
"""), """),
) )
with self.sql_session.no_autoflush:
print("Please select the bookcase where the item is placed:") print("Please select the bookcase where the item is placed:")
bookcase_selector = InteractiveItemSelector( bookcase_selector = InteractiveItemSelector(
cls=Bookcase, cls=Bookcase,
@@ -246,6 +235,7 @@ class WorblehatCli(NumberedCmd):
self.sql_session.commit() self.sql_session.commit()
else: else:
self.sql_session.rollback() self.sql_session.rollback()
if Config["general.quit_allowed"]:
exit(0) exit(0)
funcs = { funcs = {
+2 -1
View File
@@ -65,7 +65,8 @@ def main() -> None:
if args.command == "cli": if args.command == "cli":
sql_session = _connect_to_database(echo=Config["logging.debug_sql"]) sql_session = _connect_to_database(echo=Config["logging.debug_sql"])
WorblehatCli.run_with_safe_exit_wrapper(sql_session) worblehat = WorblehatCli(sql_session)
worblehat.run_with_safe_exit_wrapper()
exit(0) exit(0)
if args.command == "create-db": if args.command == "create-db":