handle quitters
This commit was merged in pull request #30.
This commit is contained in:
@@ -38,3 +38,6 @@ dryrun = false
|
||||
warn_days_before_borrowing_deadline = [ 5, 1 ]
|
||||
days_before_queue_position_expires = 14
|
||||
warn_days_before_expiring_queue_position_deadline = [ 3, 1 ]
|
||||
|
||||
[general]
|
||||
quit_allowed = true
|
||||
|
||||
@@ -16,6 +16,7 @@ from worblehat.models import *
|
||||
from worblehat.services import (
|
||||
create_bookcase_item_from_isbn,
|
||||
is_valid_isbn,
|
||||
Config,
|
||||
)
|
||||
|
||||
from .subclis import (
|
||||
@@ -47,26 +48,13 @@ class WorblehatCli(NumberedCmd):
|
||||
self.sql_session_dirty = False
|
||||
self.prompt_header = None
|
||||
|
||||
@classmethod
|
||||
def run_with_safe_exit_wrapper(cls, sql_session: Session) -> None:
|
||||
tool = cls(sql_session)
|
||||
def run_with_safe_exit_wrapper(self) -> None:
|
||||
while True:
|
||||
try:
|
||||
tool.cmdloop()
|
||||
except KeyboardInterrupt:
|
||||
if not tool.sql_session_dirty:
|
||||
exit(0)
|
||||
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)
|
||||
self.cmdloop()
|
||||
except KeyboardInterrupt:
|
||||
print("\n\n-----------------\n")
|
||||
self.do_exit("Exit")
|
||||
|
||||
def do_show_bookcase(self, arg: str) -> None:
|
||||
bookcase_selector = InteractiveItemSelector(
|
||||
@@ -247,7 +235,8 @@ class WorblehatCli(NumberedCmd):
|
||||
self.sql_session.commit()
|
||||
else:
|
||||
self.sql_session.rollback()
|
||||
exit(0)
|
||||
if Config["general.quit_allowed"]:
|
||||
exit(0)
|
||||
|
||||
funcs = {
|
||||
0: {
|
||||
|
||||
@@ -65,7 +65,8 @@ def main() -> None:
|
||||
|
||||
if args.command == "cli":
|
||||
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)
|
||||
|
||||
if args.command == "create-db":
|
||||
|
||||
Reference in New Issue
Block a user