From 7858e7a46018022b41e39abc584a004a71cf0aa9 Mon Sep 17 00:00:00 2001 From: codeking Date: Sat, 15 Mar 2025 22:42:58 +0100 Subject: [PATCH] Implement support for incremental client updates --- cli/__main__.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cli/__main__.py b/cli/__main__.py index 586815e..0593bad 100644 --- a/cli/__main__.py +++ b/cli/__main__.py @@ -3,6 +3,7 @@ from core.Errors import MissingSubscriptionError, InvalidSubscriptionError, Unkn from core.controllers.ApplicationController import ApplicationController from core.controllers.ApplicationVersionController import ApplicationVersionController from core.controllers.ClientController import ClientController +from core.controllers.ClientVersionController import ClientVersionController from core.controllers.ConfigurationController import ConfigurationController from core.controllers.InvoiceController import InvoiceController from core.controllers.LocationController import LocationController @@ -42,6 +43,10 @@ if __name__ == '__main__': application_version_observer.subscribe('downloaded', lambda event: print('\n')) client_observer.subscribe('synchronizing', lambda event: print('Synchronizing...\n')) + client_observer.subscribe('updating', lambda event: print('Updating client...')) + client_observer.subscribe('update_progressing', lambda event: print(f'Current progress: {event.meta.get('progress'):.2f}%', flush=True, end='\r')) + client_observer.subscribe('updated', lambda event: print('\n')) + connection_observer.subscribe('connecting', lambda event: print(f'[{event.subject.get("attempt_count")}/{event.subject.get("maximum_number_of_attempts")}] Performing connection attempt...\n')) invoice_observer.subscribe('retrieved', lambda event: print(f'\n{pprint.pp(event.subject)}\n')) @@ -159,6 +164,8 @@ if __name__ == '__main__': sync_parser = main_subparsers.add_parser('sync') + update_parser = main_subparsers.add_parser('update') + arguments = main_parser.parse_args() if arguments.command is None: @@ -358,9 +365,6 @@ if __name__ == '__main__': else: main_parser.error('the following argument should be a valid reference: --application/-a') - elif arguments.command == 'sync': - ClientController.sync(client_observer=client_observer, connection_observer=connection_observer) - elif arguments.command == 'get': if arguments.subcommand is None: @@ -376,3 +380,15 @@ if __name__ == '__main__': elif arguments.subcommand == 'connection': ConfigurationController.set_connection(arguments.connection_type) + + elif arguments.command == 'sync': + ClientController.sync(client_observer=client_observer, connection_observer=connection_observer) + + elif arguments.command == 'update': + + client_version = ClientController.get_version() + + if ClientVersionController.is_latest(client_version): + print('The client is already up to date.\n') + + ClientController.update(client_observer=client_observer, connection_observer=connection_observer)