|
@@ -1,115 +1,115 @@
|
|
|
-from __future__ import print_function
|
|
|
-
|
|
|
-import sys
|
|
|
-import time
|
|
|
-
|
|
|
-import client_controller
|
|
|
-from debug import debug
|
|
|
-from util import yn_dialog
|
|
|
-
|
|
|
-
|
|
|
-def fake_loading_bar(msg, duration=5.):
|
|
|
- if len(msg) >= 60:
|
|
|
- raise AssertionError('Loading bar label too large')
|
|
|
- msg += ': '
|
|
|
- print(msg, end='')
|
|
|
- sys.stdout.flush()
|
|
|
- bar_length = 79 - len(msg)
|
|
|
- for _ in range(bar_length):
|
|
|
- if not debug:
|
|
|
- time.sleep(duration / bar_length)
|
|
|
- print('#', end='')
|
|
|
- sys.stdout.flush()
|
|
|
- print('\n', end='')
|
|
|
- sys.stdout.flush()
|
|
|
-
|
|
|
-
|
|
|
-def load():
|
|
|
- print('Loading...')
|
|
|
-
|
|
|
- fake_loading_bar('Initializing fake loading bars', duration=5)
|
|
|
- fake_loading_bar('Loading data from disk', duration=1)
|
|
|
- fake_loading_bar('Loading available commands', duration=3.5)
|
|
|
- fake_loading_bar('Updating indices', duration=2)
|
|
|
- fake_loading_bar('Waiting', duration=5)
|
|
|
- print('Done.\n\n')
|
|
|
-
|
|
|
-
|
|
|
-def welcome():
|
|
|
- print('''
|
|
|
- $$$$$$\ $$\
|
|
|
- $$ __$$\ $$ |
|
|
|
- $$ / $$ | $$$$$$\ $$$$$$$ | $$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\
|
|
|
- $$ | $$ |$$ __$$\ $$ __$$ |$$ __$$\ $$ __$$\ $$ __$$\ $$ __$$\
|
|
|
- $$ | $$ |$$ | \__|$$ / $$ |$$$$$$$$ |$$ | \__|$$$$$$$$ |$$ | \__|
|
|
|
- $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ ____|$$ |
|
|
|
- $$$$$$ |$$ | \$$$$$$$ |\$$$$$$$\ $$ | \$$$$$$$\ $$ |
|
|
|
- \______/ \__| \_______| \_______|\__| \_______|\__|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-To display an overview of available commands type \'help\'.
|
|
|
-
|
|
|
-''')
|
|
|
-
|
|
|
-
|
|
|
-allowed_commands = ['help',
|
|
|
- 'login',
|
|
|
- 'register',
|
|
|
- 'change_pw',
|
|
|
- 'news',
|
|
|
- 'tradables',
|
|
|
- 'depot',
|
|
|
- 'orders',
|
|
|
- 'orders_on',
|
|
|
- 'old_orders',
|
|
|
- 'trades',
|
|
|
- 'trades_on',
|
|
|
- 'buy',
|
|
|
- 'sell',
|
|
|
- 'cancel_order',
|
|
|
- 'gift',
|
|
|
- 'leaderboard',
|
|
|
- 'activate_key',
|
|
|
- 'exit']
|
|
|
-
|
|
|
-
|
|
|
-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()
|
|
|
-
|
|
|
-
|
|
|
- if cmd == []:
|
|
|
- continue
|
|
|
- cmd[0] = cmd[0].lower()
|
|
|
- if cmd[0] not in allowed_commands:
|
|
|
- print('Invalid command:', cmd[0])
|
|
|
- else:
|
|
|
- method_to_call = getattr(client_controller, cmd[0])
|
|
|
-
|
|
|
- try:
|
|
|
- method_to_call(*cmd[1:])
|
|
|
- except TypeError:
|
|
|
- print('Invalid command syntax.')
|
|
|
- except ConnectionError:
|
|
|
- print('There has been a problem connecting when to the server.')
|
|
|
- except KeyboardInterrupt:
|
|
|
- print('Interrupted')
|
|
|
- except Exception as _:
|
|
|
- print('An unknown error occurred while executing a command.')
|
|
|
-
|
|
|
-
|
|
|
-if __name__ == '__main__':
|
|
|
- load()
|
|
|
- welcome()
|
|
|
- while not client_controller.exiting:
|
|
|
- one_command()
|
|
|
+from __future__ import print_function
|
|
|
+
|
|
|
+import sys
|
|
|
+import time
|
|
|
+
|
|
|
+import client_controller
|
|
|
+from debug import debug
|
|
|
+from util import yn_dialog
|
|
|
+
|
|
|
+
|
|
|
+def fake_loading_bar(msg, duration=5.):
|
|
|
+ if len(msg) >= 60:
|
|
|
+ raise AssertionError('Loading bar label too large')
|
|
|
+ msg += ': '
|
|
|
+ print(msg, end='')
|
|
|
+ sys.stdout.flush()
|
|
|
+ bar_length = 79 - len(msg)
|
|
|
+ for _ in range(bar_length):
|
|
|
+ if not debug:
|
|
|
+ time.sleep(duration / bar_length)
|
|
|
+ print('#', end='')
|
|
|
+ sys.stdout.flush()
|
|
|
+ print('\n', end='')
|
|
|
+ sys.stdout.flush()
|
|
|
+
|
|
|
+
|
|
|
+def load():
|
|
|
+ print('Loading...')
|
|
|
+
|
|
|
+ fake_loading_bar('Initializing fake loading bars', duration=5)
|
|
|
+ fake_loading_bar('Loading data from disk', duration=1)
|
|
|
+ fake_loading_bar('Loading available commands', duration=3.5)
|
|
|
+ fake_loading_bar('Updating indices', duration=2)
|
|
|
+ fake_loading_bar('Waiting', duration=5)
|
|
|
+ print('Done.\n\n')
|
|
|
+
|
|
|
+
|
|
|
+def welcome():
|
|
|
+ print(r'''
|
|
|
+ $$$$$$\ $$\
|
|
|
+ $$ __$$\ $$ |
|
|
|
+ $$ / $$ | $$$$$$\ $$$$$$$ | $$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\
|
|
|
+ $$ | $$ |$$ __$$\ $$ __$$ |$$ __$$\ $$ __$$\ $$ __$$\ $$ __$$\
|
|
|
+ $$ | $$ |$$ | \__|$$ / $$ |$$$$$$$$ |$$ | \__|$$$$$$$$ |$$ | \__|
|
|
|
+ $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ ____|$$ |
|
|
|
+ $$$$$$ |$$ | \$$$$$$$ |\$$$$$$$\ $$ | \$$$$$$$\ $$ |
|
|
|
+ \______/ \__| \_______| \_______|\__| \_______|\__|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+To display an overview of available commands type \'help\'.
|
|
|
+
|
|
|
+''')
|
|
|
+
|
|
|
+
|
|
|
+allowed_commands = ['help',
|
|
|
+ 'login',
|
|
|
+ 'register',
|
|
|
+ 'change_pw',
|
|
|
+ 'news',
|
|
|
+ 'tradables',
|
|
|
+ 'depot',
|
|
|
+ 'orders',
|
|
|
+ 'orders_on',
|
|
|
+ 'old_orders',
|
|
|
+ 'trades',
|
|
|
+ 'trades_on',
|
|
|
+ 'buy',
|
|
|
+ 'sell',
|
|
|
+ 'cancel_order',
|
|
|
+ 'gift',
|
|
|
+ 'leaderboard',
|
|
|
+ 'activate_key',
|
|
|
+ 'exit']
|
|
|
+
|
|
|
+
|
|
|
+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()
|
|
|
+
|
|
|
+
|
|
|
+ if cmd == []:
|
|
|
+ continue
|
|
|
+ cmd[0] = cmd[0].lower()
|
|
|
+ if cmd[0] not in allowed_commands:
|
|
|
+ print('Invalid command:', cmd[0])
|
|
|
+ else:
|
|
|
+ method_to_call = getattr(client_controller, cmd[0])
|
|
|
+
|
|
|
+ try:
|
|
|
+ method_to_call(*cmd[1:])
|
|
|
+ except TypeError:
|
|
|
+ print('Invalid command syntax.')
|
|
|
+ except ConnectionError:
|
|
|
+ print('There has been a problem connecting when to the server.')
|
|
|
+ except KeyboardInterrupt:
|
|
|
+ print('Interrupted')
|
|
|
+ except Exception as _:
|
|
|
+ print('An unknown error occurred while executing a command.')
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ load()
|
|
|
+ welcome()
|
|
|
+ while not client_controller.exiting:
|
|
|
+ one_command()
|