Skip to content

Commit 34eb83d

Browse files
authored
Merge pull request #79 from tanjeffreyz/dev
Fixed submodule errors
2 parents eb37f2a + a2166f8 commit 34eb83d

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

setup.py

-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Creates a desktop shortcut that can run Auto Maple from anywhere."""
22

33
import os
4-
import git
54
import argparse
65
import win32com.client as client
76

@@ -36,25 +35,9 @@ def create_desktop_shortcut():
3635
print(' ~ Successfully created Auto Maple shortcut')
3736

3837

39-
def update_submodules():
40-
print('\n[~] Updating submodules:')
41-
repo = git.Repo.init()
42-
output = repo.git.submodule('update', '--init', '--recursive')
43-
changed = False
44-
for line in output.split('\n'):
45-
if line:
46-
print(f' - {line}')
47-
changed = True
48-
if changed:
49-
print(' ~ Finished updating submodules')
50-
else:
51-
print(' ~ No changes found in submodules')
52-
53-
5438
if __name__ == '__main__':
5539
parser = argparse.ArgumentParser()
5640
parser.add_argument('--stay', action='store_true')
5741
args = parser.parse_args()
5842

5943
create_desktop_shortcut()
60-
update_submodules()

src/modules/bot.py

+38
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import threading
44
import time
5+
import git
56
import cv2
67
import inspect
78
from os.path import splitext, basename
@@ -54,6 +55,7 @@ def start(self):
5455
:return: None
5556
"""
5657

58+
Bot._update_submodules()
5759
print('\n[~] Started main bot loop')
5860
self.thread.start()
5961

@@ -207,3 +209,39 @@ def load_commands(self, file):
207209
else:
208210
print(f"[!] Command book '{module_name}' was not loaded.")
209211
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

Comments
 (0)