Skip to content

Commit

Permalink
Update wizard.py to use recursive git instead of curl + tar
Browse files Browse the repository at this point in the history
  • Loading branch information
L1ghtmann authored and 0cyn committed Jan 10, 2024
1 parent 9cf0f33 commit 5af6ab5
Showing 1 changed file with 10 additions and 54 deletions.
64 changes: 10 additions & 54 deletions src/dragon/wizard.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python3

import json, os, shutil, ssl, sys, tarfile
from ruyaml import YAML
from urllib import request
import os, shutil, sys
from .util import deployable_path


Expand All @@ -29,20 +27,15 @@ def setup_wizard():
os.chdir(dragon_root_dir)

for repo in ('lib', 'include', 'frameworks', 'sdks', 'src'):
try:
get_supporting(
f'https://api.github.com/repos/DragonBuild/{repo}/releases/latest',
repo
)
except Exception as ex:
log(ex)
log('Potentially ratelimited, attempting fallback by cloning repo (this adds some overhead)')
if os.path.isdir(f'{repo}') and os.path.isdir(f'{repo}/.git'):
os.chdir(f'{repo}')
os.system('git pull origin $(git rev-parse --abbrev-ref HEAD)')
os.chdir(dragon_root_dir)
else:
os.system(f'git clone --depth=1 https://github.com/dragonbuild/{repo}')
if os.path.isdir(f'{repo}') and not os.path.isdir(f'{repo}/.git'):
shutil.rmtree(f'{repo}')
os.system(f'git clone --depth=1 --recursive https://github.com/DragonBuild/{repo}')
elif os.path.isdir(f'{repo}') and os.path.isdir(f'{repo}/.git'):
os.chdir(f'{repo}')
os.system('git pull origin $(git rev-parse --abbrev-ref HEAD)')
os.chdir(dragon_root_dir)
else:
os.system(f'git clone --depth=1 --recursive https://github.com/DragonBuild/{repo}')

log('Deploying internal configuration')
try:
Expand All @@ -57,43 +50,6 @@ def setup_wizard():
pass
log('Done!')


def get_supporting(api: str, destination: str):
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE # python doesn't bundle certs on macOS, so we have to disable SSL :)
response: dict = json.load(request.urlopen(api, context=ctx))
if os.path.exists(f'{destination}/metadata.yml'):
with open(f'{destination}/metadata.yml', 'r') as fd:
yaml=YAML(typ='safe') # default, if not specfied, is 'rt' (round-trip)
metadata = yaml.load(fd)
version = metadata['version']
if version == response['tag_name']:
log(f'Latest {destination} already installed')
return
tar_url = response['tarball_url']

try:
shutil.rmtree(f'./{destination}')
except FileNotFoundError:
pass

log(f'Updating supporting {destination} v{response["tag_name"]} from {tar_url} ...')
tar_bytes = request.urlopen(tar_url, context=ctx).read()

fname = 'tmp.tar.gz'
with open(fname, 'wb') as f:
f.write(tar_bytes)

tar = tarfile.open(fname)
extracted_name = tar.members[0].name

log(f'Extracting into {os.environ["DRAGON_ROOT_DIR"] + destination}')
tar.extractall()
os.rename(extracted_name, destination)
os.remove(fname)


if __name__ == '__main__':
setup_wizard()
os.system('dragon v')

0 comments on commit 5af6ab5

Please sign in to comment.