From b58558eb757191cee5710806a81202216b633422 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sat, 18 Jan 2020 15:45:52 +0100 Subject: [PATCH] move updater to own module --- .gitignore | 2 ++ ModuleUpdate.py | 36 ++++++++++++++++++++++++++++++++++++ MultiClient.py | 39 ++++++++------------------------------- MultiMystery.py | 4 ++++ MultiServer.py | 10 +++++++--- README.md | 8 +++----- 6 files changed, 60 insertions(+), 39 deletions(-) create mode 100644 ModuleUpdate.py diff --git a/.gitignore b/.gitignore index 83d5e97f..0deaca1a 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ EnemizerCLI/ .mypy_cache/ RaceRom.py weights/ +/MultiMystery/ +/Players/ diff --git a/ModuleUpdate.py b/ModuleUpdate.py new file mode 100644 index 00000000..c81817aa --- /dev/null +++ b/ModuleUpdate.py @@ -0,0 +1,36 @@ +import sys +import subprocess +import importlib + +update_ran = False + +def update_command(): + subprocess.call([sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt', '--upgrade']) + +def update(): + global update_ran + if not update_ran: + update_ran = True + with open('requirements.txt') as requirementsfile: + for line in requirementsfile.readlines(): + module, remoteversion = line.split(">=") + try: + module = importlib.import_module(module) + except: + import traceback + traceback.print_exc() + input(f'Required python module {module} not found, press enter to install it') + update_command() + else: + if hasattr(module, "__version__"): + module_version = module.__version__ + module = module.__name__ #also unloads the module to make it writable + if type(module_version) == str: + module_version = tuple(int(part.strip()) for part in module_version.split(".")) + remoteversion = tuple(int(part.strip()) for part in remoteversion.split(".")) + if module_version < remoteversion: + input(f'Required python module {module} is outdated ({module_version}<{remoteversion}), press enter to upgrade it') + update_command() + +if __name__ == "__main__": + update() \ No newline at end of file diff --git a/MultiClient.py b/MultiClient.py index 15e6b012..6d975cce 100644 --- a/MultiClient.py +++ b/MultiClient.py @@ -3,41 +3,18 @@ import asyncio import json import logging import shlex -import subprocess -import sys import urllib.parse -import importlib + +import ModuleUpdate +ModuleUpdate.update() + +import colorama +import websockets +import aioconsole + import Items import Regions -def update_command(): - subprocess.call([sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt', '--upgrade']) - -with open('requirements.txt') as requirementsfile: - for line in requirementsfile.readlines(): - module, remoteversion = line.split(">=") - try: - module = importlib.import_module(module) - except: - import traceback - traceback.print_exc() - input(f'Required python module {module} not found, press enter to install it') - update_command() - else: - if hasattr(module, "__version__"): - module_version = module.__version__ - module = module.__name__ #also unloads the module to make it writable - if type(module_version) == str: - module_version = tuple(int(part.strip()) for part in module_version.split(".")) - remoteversion = tuple(int(part.strip()) for part in remoteversion.split(".")) - if module_version < remoteversion: - input(f'Required python module {module} is outdated ({module_version}<{remoteversion}), press enter to upgrade it') - update_command() - -import aioconsole -import websockets -import colorama - class ReceivedItem: def __init__(self, item, location, player): self.item = item diff --git a/MultiMystery.py b/MultiMystery.py index 16ff18c2..4e5d8379 100644 --- a/MultiMystery.py +++ b/MultiMystery.py @@ -56,6 +56,10 @@ def feedback(text:str): if __name__ == "__main__": try: + + import ModuleUpdate + ModuleUpdate.update() + print(f"{__author__}'s MultiMystery Launcher V{__version__}") if not os.path.exists(enemizer_location): feedback(f"Enemizer not found at {enemizer_location}, please adjust the path in MultiMystery.py's config or put Enemizer in the default location.") diff --git a/MultiServer.py b/MultiServer.py index 29fad144..4d1f0504 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -1,4 +1,3 @@ -import aioconsole import argparse import asyncio import functools @@ -7,9 +6,14 @@ import logging import re import shlex import urllib.request -import websockets import zlib +import ModuleUpdate +ModuleUpdate.update() + +import websockets +import aioconsole + import Items import Regions from MultiClient import ReceivedItem, get_item_name_from_id, get_location_name_from_address @@ -348,7 +352,7 @@ async def console(ctx : Context): if receiving_player == slot and item_id == seeked_item_id: location_id, finding_player = check name_finder = ctx.player_names[team, finding_player] - hint = f"[Hint]: {name}'s {item} can be found in " \ + hint = f"[Hint]: {name}'s {item} can be found at " \ f"{get_location_name_from_address(location_id)} in {name_finder}'s World" notify_team(ctx, team, hint) else: diff --git a/README.md b/README.md index 520b4dfa..25fb755c 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,12 @@ Notice (Team #1): [Hint]: Berserker's Progressive Sword can be found in Palace o Notice (Team #1): [Hint]: Berserker's Progressive Sword can be found in Ganons Tower - Map Chest in Will's World Mystery.py - * Fix fast_ganon not working at all currently * Defaults to generating a non-race ROM (Bonta's only makes race ROMs at this time) If a race ROM is desired, pass --create-race as argument to it * When an error is generated due to a broken .yaml file, it now mentions in the error trace which file it is -MultiClient.py +Project * Update modules if they are too old, preventing a crash when trying to connect among potential other issues * Autoinstall missing modules - -Project - * Allow newer versions of modules than specified, as they will *usually* not break compatibility \ No newline at end of file + * Allow newer versions of modules than specified, as they will *usually* not break compatibility + \ No newline at end of file