Skip to content

Commit

Permalink
Added simple version check for WeakAuras
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Aug 28, 2019
1 parent e7e0c03 commit 21ab8e2
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()

Expand Down
46 changes: 46 additions & 0 deletions CB/WeakAura.py
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion CB/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '2.0.0'
__version__ = '2.1.0'
__license__ = 'GPLv3'
__copyright__ = '2019, Paweł Jastrzębski <[email protected]>'
__docformat__ = 'restructuredtext en'
Expand Down
41 changes: 39 additions & 2 deletions CurseBreaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -105,6 +107,10 @@ def start(self):
self.setup_table()
printft(HTML('\n<ansigreen>Backing up WTF directory:</ansigreen>'))
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('')
Expand Down Expand Up @@ -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"]}',
Expand Down Expand Up @@ -309,6 +315,35 @@ def c_toggle_backup(self, _):
printft('Backup of WTF directory is now:',
HTML('<ansigreen>ENABLED</ansigreen>') if status else HTML('<ansired>DISABLED</ansired>'))

def c_toggle_wa(self, args):
if args:
if args == self.core.config['WAUsername']:
printft(HTML(f'Auras created by <ansiwhite>{self.core.config["WAUsername"]}</ansiwhite>'
f' are now included.'))
self.core.config['WAUsername'] = ''
else:
self.core.config['WAUsername'] = args.strip()
printft(HTML(f'Auras created by <ansiwhite>{self.core.config["WAUsername"]}</ansiwhite>'
f' are now ignored.'))
else:
if self.core.config['WAUsername'] == 'DISABLED':
self.core.config['WAUsername'] = ''
printft(HTML('WeakAuras version check is now: <ansigreen>ENABLED</ansigreen>'))
else:
self.core.config['WAUsername'] = 'DISABLED'
printft(HTML('WeakAuras version check is now: <ansired>DISABLED</ansired>'))
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('<ansigreen>Outdated WeakAuras:</ansigreen>'))
for aura in status:
printft(aura)
else:
printft(HTML(f'\n<ansigreen>The number of outdated WeakAuras:</ansigreen> {len(status)}'))

def c_search(self, args):
if args:
results = self.core.search(args)
Expand Down Expand Up @@ -336,6 +371,8 @@ def c_help(self, _):
printft(HTML('<ansigreen>toggle_backup</ansigreen>\n\tEnable/disable automatic daily backup of WTF directory.'))
printft(HTML('<ansigreen>toggle_dev</ansigreen>\n\tThis command accepts an addon name as an argument.\n\tPriori'
'tize alpha/beta versions for the provided addon.'))
printft(HTML('<ansigreen>toggle_wa [Username]</ansigreen>\n\tEnable/disable automatic WeakAuras version check.'
'\n\tIf a username is provided check will start to ignore the specified author.'))
printft(HTML('<ansigreen>uri_integration</ansigreen>\n\tEnable integration with CurseForge page. "Install" butt'
'on will now start this application.'))
printft(HTML('\n<ansibrightgreen>Supported URLs:</ansibrightgreen>\n\thttps://www.curseforge.com/wow/addons/[ad'
Expand Down

0 comments on commit 21ab8e2

Please sign in to comment.