Skip to content

Commit

Permalink
Added support for GitHub releases
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Jun 29, 2020
1 parent 0119284 commit 8fc4895
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from xml.dom.minidom import parse, parseString
from . import retry, HEADERS, __version__
from .Tukui import TukuiAddon
from .GitHub import GitHubAddon
from .GitLab import GitLabAddon
from .CurseForge import CurseForgeAddon
from .WoWInterface import WoWInterfaceAddon
Expand Down Expand Up @@ -159,6 +160,8 @@ def parse_url(self, url):
elif url.endswith('1') or url.endswith('2'):
raise RuntimeError('ElvUI and Tukui cannot be installed this way.')
return TukuiAddon(url, True)
elif url.startswith('https://github.com/'):
return GitHubAddon(url)
elif url.lower() == 'elvui':
if self.clientType == 'wow_retail':
return GitLabAddon('ElvUI', '60', 'elvui/elvui', 'master')
Expand Down Expand Up @@ -193,6 +196,8 @@ def add_addon(self, url, ignore):
url = f'https://www.tukui.org/addons.php?id={url[3:]}'
elif url.startswith('tuc:'):
url = f'https://www.tukui.org/classic-addons.php?id={url[4:]}'
elif url.startswith('gh:'):
url = f'https://github.com/{url[3:]}'
if url.endswith('/'):
url = url[:-1]
addon = self.check_if_installed(url)
Expand Down Expand Up @@ -506,6 +511,8 @@ def export_addons(self):
url = f'tu:{addon["URL"].split("?id=")[-1]}'
elif addon['URL'].startswith('https://www.tukui.org/classic-addons.php?id='):
url = f'tuc:{addon["URL"].split("?id=")[-1]}'
elif addon['URL'].startswith('https://github.com/'):
url = f'gh:{addon["URL"].replace("https://github.com/", "")}'
else:
url = addon['URL'].lower()
addons.append(url)
Expand Down
37 changes: 37 additions & 0 deletions CB/GitHub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import io
import zipfile
import requests
from . import retry, HEADERS


class GitHubAddon:
@retry()
def __init__(self, url):
project = url.replace('https://github.com/', '')
self.payload = requests.get(f'https://api.github.com/repos/{project}/releases/latest', headers=HEADERS)
if self.payload.status_code == 404:
raise RuntimeError(url)
else:
self.payload = self.payload.json()
if 'assets' not in self.payload or len(self.payload['assets']) == 0 \
or self.payload['assets'][0]['content_type'] not in ['application/x-zip-compressed', 'application/zip']:
raise RuntimeError(url)
self.name = project.split('/')[1]
self.downloadUrl = self.payload['assets'][0]['browser_download_url']
self.currentVersion = self.payload['name']
self.archive = None
self.directories = []

@retry()
def get_addon(self):
self.archive = zipfile.ZipFile(io.BytesIO(requests.get(self.downloadUrl).content))
for file in self.archive.namelist():
if '/' not in os.path.dirname(file):
self.directories.append(os.path.dirname(file))
self.directories = list(filter(None, set(self.directories)))
if len(self.directories) == 0:
raise RuntimeError(f'{self.name}.\nProject package is corrupted or incorrectly packaged.')

def install(self, path):
self.archive.extractall(path)
14 changes: 9 additions & 5 deletions CurseBreaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,9 @@ def c_install(self, args):
'nloads/[[addon_name]] [bold white]|[/bold white] wowi:[[addon_id]]\n\thttps://www.tukui'
'.org/addons.php?id=[[addon_id]] [bold white]|[/bold white] tu:[[addon_id]]\n\thttps://w'
'ww.tukui.org/classic-addons.php?id=[[addon_id]] [bold white]|[/bold white] tuc:[[addon_'
'id]]\n\tElvUI [bold white]|[/bold white] ElvUI:Dev\n\tTukui\n\tSLE:Dev',
highlight=False)
'id]]\n\thttps://github.com/[[username]]/[[repository_name]] [bold white]|[/bold white] '
'gh:[[username]]/[[repository_name]]\n\tElvUI [bold white]|[/bold white] ElvUI:Dev\n\tTu'
'kui\n\tSLE:Dev', highlight=False)

def c_uninstall(self, args):
if args:
Expand All @@ -344,7 +345,8 @@ def c_uninstall(self, args):
'full links as an argument.\n[bold green]Supported URL:[/bold green]\n\thttps://www.curs'
'eforge.com/wow/addons/[[addon_name]]\n\thttps://www.wowinterface.com/downloads/[[addon_'
'name]]\n\thttps://www.tukui.org/addons.php?id=[[addon_id]]\n\thttps://www.tukui.org/cla'
'ssic-addons.php?id=[[addon_id]]', highlight=False)
'ssic-addons.php?id=[[addon_id]]\n\thttps://github.com/[[username]]/[[repository_name]]',
highlight=False)

def c_update(self, args, addline=False, update=True, force=False):
if len(self.core.cfCache) > 0 or len(self.core.wowiCache) > 0:
Expand Down Expand Up @@ -598,8 +600,10 @@ def c_help(self, _):
'name]] [bold white]|[/bold white] cf:[[addon_name]]\n\thttps://www.wowinterface.com/downloa'
'ds/[[addon_name]] [bold white]|[/bold white] wowi:[[addon_id]]\n\thttps://www.tukui.org/add'
'ons.php?id=[[addon_id]] [bold white]|[/bold white] tu:[[addon_id]]\n\thttps://www.tukui.org'
'/classic-addons.php?id=[[addon_id]] [bold white]|[/bold white] tuc:[[addon_id]]\n\tElvUI [b'
'old white]|[/bold white] ElvUI:Dev\n\tTukui\n\tSLE:Dev', highlight=False)
'/classic-addons.php?id=[[addon_id]] [bold white]|[/bold white] tuc:[[addon_id]]\n\thttps://'
'github.com/[[username]]/[[repository_name]] [bold white]|[/bold white] gh:[[username]]/[[re'
'pository_name]]\n\tElvUI [bold white]|[/bold white] ElvUI:Dev\n\tTukui\n\tSLE:Dev',
highlight=False)

def c_exit(self, _):
sys.exit(0)
Expand Down

0 comments on commit 8fc4895

Please sign in to comment.