Skip to content

Commit

Permalink
Merge pull request #79 from tanjeffreyz/dev
Browse files Browse the repository at this point in the history
Fixed submodule errors
  • Loading branch information
tanjeffreyz authored May 27, 2022
2 parents eb37f2a + a2166f8 commit 34eb83d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion resources
17 changes: 0 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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()
38 changes: 38 additions & 0 deletions src/modules/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import threading
import time
import git
import cv2
import inspect
from os.path import splitext, basename
Expand Down Expand Up @@ -54,6 +55,7 @@ def start(self):
:return: None
"""

Bot._update_submodules()
print('\n[~] Started main bot loop')
self.thread.start()

Expand Down Expand Up @@ -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')

0 comments on commit 34eb83d

Please sign in to comment.