|
2 | 2 |
|
3 | 3 | import threading
|
4 | 4 | import time
|
| 5 | +import git |
5 | 6 | import cv2
|
6 | 7 | import inspect
|
7 | 8 | from os.path import splitext, basename
|
@@ -54,6 +55,7 @@ def start(self):
|
54 | 55 | :return: None
|
55 | 56 | """
|
56 | 57 |
|
| 58 | + Bot._update_submodules() |
57 | 59 | print('\n[~] Started main bot loop')
|
58 | 60 | self.thread.start()
|
59 | 61 |
|
@@ -207,3 +209,39 @@ def load_commands(self, file):
|
207 | 209 | else:
|
208 | 210 | print(f"[!] Command book '{module_name}' was not loaded.")
|
209 | 211 | return False
|
| 212 | + |
| 213 | + @staticmethod |
| 214 | + def _update_submodules(force=False): |
| 215 | + print('\n[~] Retrieving latest submodules:') |
| 216 | + repo = git.Repo.init() |
| 217 | + changed = False |
| 218 | + with open('.gitmodules', 'r') as file: |
| 219 | + lines = file.readlines() |
| 220 | + i = 0 |
| 221 | + while i < len(lines): |
| 222 | + if lines[i].startswith('[') and i < len(lines) - 2: |
| 223 | + path = lines[i + 1].split('=')[1].strip() |
| 224 | + url = lines[i + 2].split('=')[1].strip() |
| 225 | + try: # First time loading submodule |
| 226 | + repo.git.clone(url, path) |
| 227 | + changed = True |
| 228 | + print(f" - Initialized submodule '{path}'") |
| 229 | + except git.exc.GitCommandError: |
| 230 | + sub_repo = git.Repo(path) |
| 231 | + if force: |
| 232 | + sub_repo.git.fetch('origin', 'main') |
| 233 | + sub_repo.git.reset('--hard', 'FETCH_HEAD') |
| 234 | + changed = True |
| 235 | + print(f" - Force-updated submodule '{path}'") |
| 236 | + else: |
| 237 | + try: |
| 238 | + sub_repo.git.pull('origin', 'main') |
| 239 | + changed = True |
| 240 | + print(f" - Updated submodule '{path}'") |
| 241 | + except git.exc.GitCommandError: |
| 242 | + print(f" ! Uncommitted changes in submodule '{path}'") |
| 243 | + i += 3 |
| 244 | + else: |
| 245 | + i += 1 |
| 246 | + if not changed: |
| 247 | + print(' ~ All submodules are already up to date') |
0 commit comments