Skip to content

Commit

Permalink
generalized update prompt for all future submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
tanjeffreyz committed May 29, 2022
1 parent bc563fe commit 146998d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
32 changes: 20 additions & 12 deletions src/gui/menu/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,27 @@ class Update(MenuBarItem):
def __init__(self, parent, **kwargs):
super().__init__(parent, 'Update', **kwargs)

self.add_command(label='Resources', command=self._resources)
for path in config.bot.submodules:
name = path.capitalize()
self.add_command(
label=name,
command=lambda: UpdatePrompt(self, name, path)
)

def _resources(self):
ResourcesPrompt(self)


class ResourcesPrompt(tk.Toplevel):
class UpdatePrompt(tk.Toplevel):
RESOLUTION = '500x400'

def __init__(self, parent, **kwargs):
def __init__(self, parent, name, path, **kwargs):
super().__init__(parent, **kwargs)

self.path = path

self.grab_set()
self.title('Update Resources')
self.title(f'Update {name}')
icon = tk.PhotoImage(file='assets/icon.png')
self.iconphoto(False, icon)
self.geometry(ResourcesPrompt.RESOLUTION)
self.geometry(UpdatePrompt.RESOLUTION)
self.resizable(False, False)

self.columnconfigure(0, weight=1)
Expand Down Expand Up @@ -72,7 +76,7 @@ def __init__(self, parent, **kwargs):
def _update(self, force=False):
if force and self.dirty:
if not askyesno(title='Overwrite Local Changes',
message='Rebuilding resources will overwrite all local changes. '
message=f"Rebuilding '{self.path}' will overwrite all local changes. "
'Do you wish to proceed?',
icon='warning'):
return
Expand All @@ -82,10 +86,14 @@ def _update(self, force=False):
def _refresh_display(self):
self.list_var.set(['Searching for local changes...'])
self.update()
repo = git.Repo('resources')
repo = git.Repo(self.path)
diffs = []
for item in repo.index.diff(None) + repo.index.diff('HEAD'):
diffs.append(f'{item.change_type} - {item.a_path}')
paths = set()
for item in repo.index.diff(None) + repo.index.diff('HEAD'): # Unstaged and staged changes
path = item.a_path
if path not in paths: # Only show changes once per file, unstaged has precedence over staged
diffs.append(f'{item.change_type} - {path}')
paths.add(path)
self.dirty = len(diffs) > 0
if len(diffs) == 0:
diffs.append('No local changes found, safe to update')
Expand Down
5 changes: 3 additions & 2 deletions src/modules/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self):
self.rune_active = False
self.rune_pos = (0, 0)
self.rune_closest_pos = (0, 0) # Location of the Point closest to rune
self.submodules = {}
self.submodules = []
self.module_name = None
self.buff = components.Buff()

Expand Down Expand Up @@ -230,6 +230,7 @@ def update_submodules(self, force=False):

utils.print_separator()
print('[~] Retrieving latest submodules:')
self.submodules = []
repo = git.Repo.init()
with open('.gitmodules', 'r') as file:
lines = file.readlines()
Expand All @@ -238,7 +239,7 @@ def update_submodules(self, force=False):
if lines[i].startswith('[') and i < len(lines) - 2:
path = lines[i + 1].split('=')[1].strip()
url = lines[i + 2].split('=')[1].strip()
self.submodules[path] = url
self.submodules.append(path)
try:
repo.git.clone(url, path) # First time loading submodule
print(f" - Initialized submodule '{path}'")
Expand Down

0 comments on commit 146998d

Please sign in to comment.