Skip to content

Commit

Permalink
Added support for prioritising alpha/beta versions (close #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed May 5, 2019
1 parent 774940b commit 0869b54
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 13 deletions.
24 changes: 23 additions & 1 deletion CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,24 @@ 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:
shutil.rmtree(os.path.join(self.path, directory), ignore_errors=True)

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()
Expand Down Expand Up @@ -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()
Expand Down
25 changes: 16 additions & 9 deletions CB/CurseForge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion CB/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.4.1'
__version__ = '1.5.0'
__license__ = 'GPLv3'
__copyright__ = '2019, Paweł Jastrzębski <[email protected]>'
__docformat__ = 'restructuredtext en'
Expand Down
18 changes: 16 additions & 2 deletions CurseBreaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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('<ansibrightred>This addon does not exist or it is not installed yet.</ansibrightred>'))
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('<ansigreen>Usage:</ansigreen>\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:',
Expand Down Expand Up @@ -306,6 +318,8 @@ def c_help(self, _):
printft(HTML('<ansigreen>orphans</ansigreen>\n\tPrints list of orphaned directories and files.'))
printft(HTML('<ansigreen>search [Keyword]</ansigreen>\n\tExecute addon search on CurseForge.'))
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>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 0869b54

Please sign in to comment.