diff --git a/CB/Core.py b/CB/Core.py index 9b6e25d..0e1d39c 100644 --- a/CB/Core.py +++ b/CB/Core.py @@ -30,7 +30,8 @@ def init_config(self): self.config = {'Addons': [], 'CurseCache': {}, 'Backup': {'Enabled': True, 'Number': 7}, - 'Version': __version__} + 'Version': __version__, + 'WAUsername': ''} self.save_config() if not os.path.isdir('WTF-Backup') and self.config['Backup']['Enabled']: os.mkdir('WTF-Backup') @@ -57,6 +58,9 @@ def update_config(self): self.config.pop('URLCache', None) if 'CurseCache' not in self.config.keys(): self.config['CurseCache'] = {} + # 2.1.0 + if 'WAUsername' not in self.config.keys(): + self.config['WAUsername'] = '' self.config['Version'] = __version__ self.save_config() diff --git a/CB/WeakAura.py b/CB/WeakAura.py new file mode 100644 index 0000000..a733d4a --- /dev/null +++ b/CB/WeakAura.py @@ -0,0 +1,46 @@ +import os +import re +import requests +from pathlib import Path +from . import retry + + +class WeakAuraUpdater: + def __init__(self, username): + self.url = re.compile('(\w+)/(\d+)') + self.username = username + self.storage_location = [] + self.wa_outdated = [] + self.wa_ids = [] + self.wa_list = {} + self.locate_storage() + self.parse_storage() + + def locate_storage(self): + account_list = os.listdir(os.path.join('WTF', 'Account')) + for account in account_list: + storage_path = Path(f'WTF/Account/{account}/SavedVariables/WeakAuras.lua') + if os.path.isfile(storage_path): + self.storage_location.append(storage_path) + + def parse_storage(self): + for storage in self.storage_location: + with open(storage) as fp: + for _, line in enumerate(fp): + if '["url"]' in line: + search = self.url.search(line) + if search.group(1) and search.group(2): + self.wa_list[search.group(1)] = int(search.group(2)) + self.wa_ids.append(search.group(1)) + self.wa_ids = list(dict.fromkeys(self.wa_ids)) + + @retry() + def check_updates(self): + payload = requests.get(f'https://data.wago.io/api/check/weakauras?ids={",".join(self.wa_ids)}').json() + for aura in payload: + if 'username' in aura and (not self.username or aura['username'] != self.username): + if aura['version'] > self.wa_list[aura['slug']]: + self.wa_outdated.append(aura['name']) + self.wa_outdated.sort() + return self.wa_outdated + diff --git a/CB/__init__.py b/CB/__init__.py index 048900e..7f7d2ba 100644 --- a/CB/__init__.py +++ b/CB/__init__.py @@ -1,4 +1,4 @@ -__version__ = '2.0.0' +__version__ = '2.1.0' __license__ = 'GPLv3' __copyright__ = '2019, Paweł Jastrzębski ' __docformat__ = 'restructuredtext en' diff --git a/CurseBreaker.py b/CurseBreaker.py index e15dbb7..7a5107e 100644 --- a/CurseBreaker.py +++ b/CurseBreaker.py @@ -6,6 +6,7 @@ import requests import traceback from tqdm import tqdm +from pathlib import Path from colorama import init, Fore from terminaltables import SingleTable from prompt_toolkit import PromptSession, HTML, print_formatted_text as printft @@ -14,6 +15,7 @@ from distutils.version import StrictVersion from CB import __version__ from CB.Core import Core +from CB.WeakAura import WeakAuraUpdater class TUI: @@ -96,7 +98,7 @@ def start(self): elif time.time() - starttime > 5: break if not keypress: - if len(self.core.config['Addons']) > 37: + if len(self.core.config['Addons']) > 35: self.setup_console(True) self.print_header() try: @@ -105,6 +107,10 @@ def start(self): self.setup_table() printft(HTML('\nBacking up WTF directory:')) self.core.backup_wtf() + if self.core.config['WAUsername'] != 'DISABLED' and \ + os.path.isdir(Path('Interface/AddOns/WeakAuras')): + self.setup_table() + self.c_wa_status(False, False) except Exception as e: self.handle_exception(e) printft('') @@ -185,7 +191,7 @@ def setup_console(self, buffer=False): def setup_completer(self): commands = ['install', 'uninstall', 'update', 'force_update', 'status', 'orphans', 'search', 'toggle_backup', - 'toggle_dev', 'uri_integration', 'help', 'exit'] + 'toggle_dev', 'toggle_wa', 'uri_integration', 'wa_status', 'help', 'exit'] addons = sorted(self.core.config['Addons'], key=lambda k: k['Name'].lower()) for addon in addons: commands.extend([f'uninstall {addon["Name"]}', f'update {addon["Name"]}', f'force_update {addon["Name"]}', @@ -309,6 +315,35 @@ def c_toggle_backup(self, _): printft('Backup of WTF directory is now:', HTML('ENABLED') if status else HTML('DISABLED')) + def c_toggle_wa(self, args): + if args: + if args == self.core.config['WAUsername']: + printft(HTML(f'Auras created by {self.core.config["WAUsername"]}' + f' are now included.')) + self.core.config['WAUsername'] = '' + else: + self.core.config['WAUsername'] = args.strip() + printft(HTML(f'Auras created by {self.core.config["WAUsername"]}' + f' are now ignored.')) + else: + if self.core.config['WAUsername'] == 'DISABLED': + self.core.config['WAUsername'] = '' + printft(HTML('WeakAuras version check is now: ENABLED')) + else: + self.core.config['WAUsername'] = 'DISABLED' + printft(HTML('WeakAuras version check is now: DISABLED')) + self.core.save_config() + + def c_wa_status(self, _, verbose=True): + wa = WeakAuraUpdater('' if self.core.config['WAUsername'] == 'DISABLED' else self.core.config['WAUsername']) + status = wa.check_updates() + if verbose: + printft(HTML('Outdated WeakAuras:')) + for aura in status: + printft(aura) + else: + printft(HTML(f'\nThe number of outdated WeakAuras: {len(status)}')) + def c_search(self, args): if args: results = self.core.search(args) @@ -336,6 +371,8 @@ def c_help(self, _): printft(HTML('toggle_backup\n\tEnable/disable automatic daily backup of WTF directory.')) printft(HTML('toggle_dev\n\tThis command accepts an addon name as an argument.\n\tPriori' 'tize alpha/beta versions for the provided addon.')) + printft(HTML('toggle_wa [Username]\n\tEnable/disable automatic WeakAuras version check.' + '\n\tIf a username is provided check will start to ignore the specified author.')) printft(HTML('uri_integration\n\tEnable integration with CurseForge page. "Install" butt' 'on will now start this application.')) printft(HTML('\nSupported URLs:\n\thttps://www.curseforge.com/wow/addons/[ad'