from __future__ import print_function import requests from packaging import version as v import client_controller import version from connection import client_request, host from debug import debug from lib.print_exc_plus import print_exc_plus from routes import client_commands from util import yn_dialog, main_wrapper assert all(getattr(client_controller, route) for route in client_commands) def check_for_updates(): try: server_version = client_request('server_version')['version'] client_version = version.__version__ if v.parse(server_version) != v.parse(client_version): print(f'WARNING: You have Orderer version {client_version} installed while the server is running version {server_version}.') print(f' This may or may not lead to problems.') print(f' A recent client version should be available for download at ' f' {host}/orderer.zip') except Exception: print('Unknown error while checking for updates.') def load(): print('Loading...') client_controller._fake_loading_bar('Initializing fake loading bars', duration=5) client_controller._fake_loading_bar('Loading data from disk', duration=1) client_controller._fake_loading_bar('Loading available commands', duration=3.5) client_controller._fake_loading_bar('Checking for updates', duration=0.4) try: check_for_updates() except (ConnectionError, requests.exceptions.ConnectionError): print('WARNING: There has been a problem connecting when to the server.') client_controller._fake_loading_bar('Updating indices', duration=2) client_controller._fake_loading_bar('Waiting', duration=5) print('Done.\n\n') def welcome(): print(r''' $$$$$$\ $$\ $$ __$$\ $$ | $$ / $$ | $$$$$$\ $$$$$$$ | $$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\ $$ | $$ |$$ __$$\ $$ __$$ |$$ __$$\ $$ __$$\ $$ __$$\ $$ __$$\ $$ | $$ |$$ | \__|$$ / $$ |$$$$$$$$ |$$ | \__|$$$$$$$$ |$$ | \__| $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ ____|$$ | $$$$$$ |$$ | \$$$$$$$ |\$$$$$$$\ $$ | \$$$$$$$\ $$ | \______/ \__| \_______| \_______|\__| \_______|\__| To display an overview of available commands type 'help'. ''') def one_command(): try: cmd = input('*> ').strip() except KeyboardInterrupt: if yn_dialog('Do you want to exit Orderer?'): print('Then type in `exit` :P') return else: return cmds = cmd.split(';') for cmd in cmds: cmd = cmd.split() # cmd = [cmd.strip() for cmd in cmd] # noinspection PySimplifyBooleanCheck if cmd == []: continue cmd[0] = cmd[0].lower() if cmd[0] not in client_commands: print('Invalid command:', cmd[0]) else: method_to_call = getattr(client_controller, cmd[0]) # noinspection PyBroadException try: method_to_call(*cmd[1:]) except (ConnectionError, requests.exceptions.ConnectionError): print('There has been a problem connecting when to the server.') except KeyboardInterrupt: print('Interrupted') except Exception as _: if debug: print_exc_plus() print('An unknown error occurred while executing a command.') def main(): load() welcome() while not client_controller.exiting: one_command() if debug: main = main_wrapper(main) if __name__ == '__main__': main()