Loading poolpay/__main__.py +8 −24 Original line number Diff line number Diff line Loading @@ -11,7 +11,6 @@ from poolpay.director.Director import Director from poolpay.display.PygameDisplay import PygameDisplay from poolpay.touch.EvdevTouchScreen import EvdevTouchScreen from poolpay.ui.pygame.play import play from poolpay.vault.Vault import Vault from poolpay.wire.Message import Message from poolpay.wire.Server import Server Loading @@ -21,7 +20,6 @@ logging.basicConfig( logging.info("Starting PoolPay") logging.info("Creating Vault, Display and Director") vault = Vault(paths.vault_file, paths.instance_dir) display = PygameDisplay(Path("/dev/fb1"), width=480, height=320) touch_screen = EvdevTouchScreen(Path("/dev/input/event0")) director = Director(play, display) Loading Loading @@ -59,21 +57,14 @@ def _initialize_card_reader_and_run_with_crash() -> None: exit(42) def launch_application(password: str | None) -> None: def launch_application() -> None: if director.started: logging.warning( "Application is already launched, don't launch it a second time" ) return open_vault = vault if password: logging.info("Opening vault") open_vault = vault.open(password) else: logging.info("No password to open vault was given, so assuming it was already open") with open_vault, touch_screen: with touch_screen: try: logging.info("Opening database") db.open(paths.db_file) Loading @@ -92,10 +83,10 @@ def launch_application(password: str | None) -> None: server.stop() def launch_application_as_daemon(password: str | None) -> None: def launch_application_as_daemon() -> None: logging.info("Launching main application as daemon thread") Thread( target=launch_application, args=(password,), daemon=True target=launch_application, daemon=True ).start() Loading @@ -104,9 +95,7 @@ server = Server(paths.socket_path) def on_message_received(message: Message) -> None: if message.get("action") == "unlock" and message.get("password"): logging.info("Unlock message received via wire") launch_application_as_daemon(message["password"]) logging.debug(f"Received message {message}, will do nothing.") server.on_receive(on_message_received) Loading @@ -123,12 +112,7 @@ logging.info("Registering SIGINT and SIGTERM handlers") signal.signal(signal.SIGINT, handle_signal) # for keyboard interrupt signal.signal(signal.SIGTERM, handle_signal) # for systemd interrupt if vault.is_open: # The vault has already been opened, so we don't need to wait for a password to start launch_application_as_daemon(None) # We will still launch the server, in case I ever get around to implementing more commands else: logging.info("Waiting for vault unlock password via wire server") # As documented above, we launch the server in any case # The application is the main thing of interest. The server currently has no purpose at all (it once took care # of unlocking the vault), but maybe it will have a purpose in the future. launch_application_as_daemon() server.start() poolpay/admin/__main__.py +2 −21 Original line number Diff line number Diff line Loading @@ -4,10 +4,6 @@ from rich import print from poolpay import db, paths from poolpay.admin import app from poolpay.admin.get_password import get_password from poolpay.paths import socket_path from poolpay.vault.Vault import Vault from poolpay.wire.Client import Client def parse_args() -> argparse.Namespace: Loading @@ -16,8 +12,8 @@ def parse_args() -> argparse.Namespace: ) parser.add_argument( "action", choices=["ui", "unlock"], help="the action to be done: show the admin ui (default), or unlock the PoolPay main app over wire", choices=["ui"], help="the action to be done: show the admin ui (default)", default="ui", nargs="?", ) Loading @@ -34,21 +30,6 @@ def run_app() -> None: args = parse_args() vault = Vault(paths.vault_file, paths.instance_dir) if not vault.is_open: # Vault was not open, so we get the password, and in case the action was "unlock", we unlock it password = get_password() if args.action == "unlock": with Client(socket_path) as c: c.send({"action": "unlock", "password": password}) else: print("🔓 The PoolPay database is already [green]unlocked[/green].") password = None if args.action == "ui": if password: with vault.open(password): run_app() else: run_app() Loading
poolpay/__main__.py +8 −24 Original line number Diff line number Diff line Loading @@ -11,7 +11,6 @@ from poolpay.director.Director import Director from poolpay.display.PygameDisplay import PygameDisplay from poolpay.touch.EvdevTouchScreen import EvdevTouchScreen from poolpay.ui.pygame.play import play from poolpay.vault.Vault import Vault from poolpay.wire.Message import Message from poolpay.wire.Server import Server Loading @@ -21,7 +20,6 @@ logging.basicConfig( logging.info("Starting PoolPay") logging.info("Creating Vault, Display and Director") vault = Vault(paths.vault_file, paths.instance_dir) display = PygameDisplay(Path("/dev/fb1"), width=480, height=320) touch_screen = EvdevTouchScreen(Path("/dev/input/event0")) director = Director(play, display) Loading Loading @@ -59,21 +57,14 @@ def _initialize_card_reader_and_run_with_crash() -> None: exit(42) def launch_application(password: str | None) -> None: def launch_application() -> None: if director.started: logging.warning( "Application is already launched, don't launch it a second time" ) return open_vault = vault if password: logging.info("Opening vault") open_vault = vault.open(password) else: logging.info("No password to open vault was given, so assuming it was already open") with open_vault, touch_screen: with touch_screen: try: logging.info("Opening database") db.open(paths.db_file) Loading @@ -92,10 +83,10 @@ def launch_application(password: str | None) -> None: server.stop() def launch_application_as_daemon(password: str | None) -> None: def launch_application_as_daemon() -> None: logging.info("Launching main application as daemon thread") Thread( target=launch_application, args=(password,), daemon=True target=launch_application, daemon=True ).start() Loading @@ -104,9 +95,7 @@ server = Server(paths.socket_path) def on_message_received(message: Message) -> None: if message.get("action") == "unlock" and message.get("password"): logging.info("Unlock message received via wire") launch_application_as_daemon(message["password"]) logging.debug(f"Received message {message}, will do nothing.") server.on_receive(on_message_received) Loading @@ -123,12 +112,7 @@ logging.info("Registering SIGINT and SIGTERM handlers") signal.signal(signal.SIGINT, handle_signal) # for keyboard interrupt signal.signal(signal.SIGTERM, handle_signal) # for systemd interrupt if vault.is_open: # The vault has already been opened, so we don't need to wait for a password to start launch_application_as_daemon(None) # We will still launch the server, in case I ever get around to implementing more commands else: logging.info("Waiting for vault unlock password via wire server") # As documented above, we launch the server in any case # The application is the main thing of interest. The server currently has no purpose at all (it once took care # of unlocking the vault), but maybe it will have a purpose in the future. launch_application_as_daemon() server.start()
poolpay/admin/__main__.py +2 −21 Original line number Diff line number Diff line Loading @@ -4,10 +4,6 @@ from rich import print from poolpay import db, paths from poolpay.admin import app from poolpay.admin.get_password import get_password from poolpay.paths import socket_path from poolpay.vault.Vault import Vault from poolpay.wire.Client import Client def parse_args() -> argparse.Namespace: Loading @@ -16,8 +12,8 @@ def parse_args() -> argparse.Namespace: ) parser.add_argument( "action", choices=["ui", "unlock"], help="the action to be done: show the admin ui (default), or unlock the PoolPay main app over wire", choices=["ui"], help="the action to be done: show the admin ui (default)", default="ui", nargs="?", ) Loading @@ -34,21 +30,6 @@ def run_app() -> None: args = parse_args() vault = Vault(paths.vault_file, paths.instance_dir) if not vault.is_open: # Vault was not open, so we get the password, and in case the action was "unlock", we unlock it password = get_password() if args.action == "unlock": with Client(socket_path) as c: c.send({"action": "unlock", "password": password}) else: print("🔓 The PoolPay database is already [green]unlocked[/green].") password = None if args.action == "ui": if password: with vault.open(password): run_app() else: run_app()