diff --git a/resources b/resources index 7a1c14a1..f1f80cf0 160000 --- a/resources +++ b/resources @@ -1 +1 @@ -Subproject commit 7a1c14a1298bf882bdb2508eeebef115b8179cac +Subproject commit f1f80cf02bdb95331dc5a9f962dbcd1f5e40d15f diff --git a/setup.py b/setup.py index 40d0ad52..4a92ef98 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,6 @@ """Creates a desktop shortcut that can run Auto Maple from anywhere.""" import os -import git import argparse import win32com.client as client @@ -36,25 +35,9 @@ def create_desktop_shortcut(): print(' ~ Successfully created Auto Maple shortcut') -def update_submodules(): - print('\n[~] Updating submodules:') - repo = git.Repo.init() - output = repo.git.submodule('update', '--init', '--recursive') - changed = False - for line in output.split('\n'): - if line: - print(f' - {line}') - changed = True - if changed: - print(' ~ Finished updating submodules') - else: - print(' ~ No changes found in submodules') - - if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--stay', action='store_true') args = parser.parse_args() create_desktop_shortcut() - update_submodules() diff --git a/src/modules/bot.py b/src/modules/bot.py index e1087e01..7ad8b62b 100644 --- a/src/modules/bot.py +++ b/src/modules/bot.py @@ -2,6 +2,7 @@ import threading import time +import git import cv2 import inspect from os.path import splitext, basename @@ -54,6 +55,7 @@ def start(self): :return: None """ + Bot._update_submodules() print('\n[~] Started main bot loop') self.thread.start() @@ -207,3 +209,39 @@ def load_commands(self, file): else: print(f"[!] Command book '{module_name}' was not loaded.") return False + + @staticmethod + def _update_submodules(force=False): + print('\n[~] Retrieving latest submodules:') + repo = git.Repo.init() + changed = False + with open('.gitmodules', 'r') as file: + lines = file.readlines() + i = 0 + while i < len(lines): + if lines[i].startswith('[') and i < len(lines) - 2: + path = lines[i + 1].split('=')[1].strip() + url = lines[i + 2].split('=')[1].strip() + try: # First time loading submodule + repo.git.clone(url, path) + changed = True + print(f" - Initialized submodule '{path}'") + except git.exc.GitCommandError: + sub_repo = git.Repo(path) + if force: + sub_repo.git.fetch('origin', 'main') + sub_repo.git.reset('--hard', 'FETCH_HEAD') + changed = True + print(f" - Force-updated submodule '{path}'") + else: + try: + sub_repo.git.pull('origin', 'main') + changed = True + print(f" - Updated submodule '{path}'") + except git.exc.GitCommandError: + print(f" ! Uncommitted changes in submodule '{path}'") + i += 3 + else: + i += 1 + if not changed: + print(' ~ All submodules are already up to date')