Skip to content

Fixed submodule errors #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')