From 0869b547fc639bbb8ec121dca0339b0e5caf69ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Sun, 5 May 2019 10:23:00 +0200 Subject: [PATCH] Added support for prioritising alpha/beta versions (close #1) --- CB/Core.py | 24 +++++++++++++++++++++++- CB/CurseForge.py | 25 ++++++++++++++++--------- CB/__init__.py | 2 +- CurseBreaker.py | 18 ++++++++++++++++-- 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/CB/Core.py b/CB/Core.py index 0879c2d..742a887 100644 --- a/CB/Core.py +++ b/CB/Core.py @@ -64,6 +64,16 @@ def check_if_installed(self, url): if addon['URL'] == url or addon['Name'] == url: return addon + def check_if_dev(self, url): + addon = self.check_if_installed(url) + if addon: + if 'Development' in addon.keys(): + return True + else: + return False + else: + return False + def cleanup(self, directories): if len(directories) > 0: for directory in directories: @@ -71,7 +81,7 @@ def cleanup(self, directories): def parse_url(self, url): if url.startswith('https://www.curseforge.com/wow/addons/'): - parser = CurseForgeAddon(url, self.config['CurseCache']) + parser = CurseForgeAddon(url, self.config['CurseCache'], self.check_if_dev(url)) if hasattr(parser, 'cacheID'): self.config['CurseCache'][url] = parser.cacheID self.save_config() @@ -146,6 +156,18 @@ def check_checksum(self, url): return len(checksums.items() & old['Checksums'].items()) != len(old['Checksums']) return False + def dev_toggle(self, url): + addon = self.check_if_installed(url) + if addon: + state = self.check_if_dev(url) + if state: + addon.pop('Development', None) + else: + addon['Development'] = True + self.save_config() + return not state + return None + def backup_toggle(self): self.config['Backup']['Enabled'] = not self.config['Backup']['Enabled'] self.save_config() diff --git a/CB/CurseForge.py b/CB/CurseForge.py index 6e0f6a1..3b8c965 100644 --- a/CB/CurseForge.py +++ b/CB/CurseForge.py @@ -9,7 +9,7 @@ class CurseForgeAddon: @retry() - def __init__(self, url, cache): + def __init__(self, url, cache, allowdev): if url in cache: project = cache[url] else: @@ -19,24 +19,31 @@ def __init__(self, url, cache): self.cacheID = project self.payload = requests.get(f'https://addons-ecs.forgesvc.net/api/addon/{project}').json() self.name = self.payload['name'] + self.allowDev = allowdev self.downloadUrl = None self.currentVersion = None self.archive = None self.directories = [] self.get_current_version() - def get_current_version(self): + def _parse_files(self, releasetype): for f in self.payload['latestFiles']: - if f['releaseType'] == 1: + if f['releaseType'] == releasetype: self.downloadUrl = f['downloadUrl'] self.currentVersion = f['fileName'] break - if not self.downloadUrl and not self.currentVersion: - for f in self.payload['latestFiles']: - if f['releaseType'] == 2: - self.downloadUrl = f['downloadUrl'] - self.currentVersion = f['fileName'] - break + + def get_current_version(self): + if self.allowDev: + self._parse_files(3) + if not self.downloadUrl and not self.currentVersion: + self._parse_files(2) + if not self.downloadUrl and not self.currentVersion: + self._parse_files(1) + else: + self._parse_files(1) + if not self.downloadUrl and not self.currentVersion: + self._parse_files(2) if not self.downloadUrl or not self.currentVersion: raise RuntimeError diff --git a/CB/__init__.py b/CB/__init__.py index 68b8204..8a421da 100644 --- a/CB/__init__.py +++ b/CB/__init__.py @@ -1,4 +1,4 @@ -__version__ = '1.4.1' +__version__ = '1.5.0' __license__ = 'GPLv3' __copyright__ = '2019, Paweł Jastrzębski ' __docformat__ = 'restructuredtext en' diff --git a/CurseBreaker.py b/CurseBreaker.py index 459850b..acaf581 100644 --- a/CurseBreaker.py +++ b/CurseBreaker.py @@ -171,11 +171,11 @@ def setup_console(self, buffer=False): def setup_completer(self): commands = ['install', 'uninstall', 'update', 'force_update', 'status', 'orphans', 'search', 'toggle_backup', - 'uri_integration', 'help', 'exit'] + 'toggle_dev', 'uri_integration', '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"]}', - f'status {addon["Name"]}']) + f'toggle_dev {addon["Name"]}', f'status {addon["Name"]}']) self.completer = WordCompleter(commands, ignore_case=True, sentence=True) def setup_table(self): @@ -276,6 +276,18 @@ def c_uri_integration(self, _): else: os.remove('CurseBreaker.reg') + def c_toggle_dev(self, args): + if args: + status = self.core.dev_toggle(args) + if status is None: + printft(HTML('This addon does not exist or it is not installed yet.')) + elif status: + printft('This addon will now prioritize alpha/beta versions.') + else: + printft('This addon will not longer prioritize alpha/beta versions.') + else: + printft(HTML('Usage:\n\tThis command accepts an addon name as an argument.')) + def c_toggle_backup(self, _): status = self.core.backup_toggle() printft('Backup of WTF directory is now:', @@ -306,6 +318,8 @@ def c_help(self, _): printft(HTML('orphans\n\tPrints list of orphaned directories and files.')) printft(HTML('search [Keyword]\n\tExecute addon search on CurseForge.')) 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('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'