def enumerate_http_resources(package, package_path):
with (package_path / 'resource.json').open() as json_file:
resource = json.load(json_file)
for name, url in resource.get('images', {}).items():
if name != 'screenshots':
yield url, pathlib.Path(package, 'images')
for name, url in resource.get('assets', {}).get('uris', {}).items():
yield url, pathlib.Path(package, 'uris')
for k in resource.get('cli', {}).get('binaries', {}):
url = resource.get('cli', {}).get('binaries', {}).get(k, {}).get('x86-64', {}).get('url', '')
yield url, pathlib.Path(package, 'cli', k)
command_path = (package_path / 'command.json')
if command_path.exists():
with command_path.open() as json_file:
commands = json.load(json_file)
for url in commands.get("pip", []):
if url.startswith('http'):
yield url, pathlib.Path(package, 'commands')
def traverse_yield(d, key='root'):
if isinstance(d, dict):
if 'default' in d and str(d['default']).startswith('http'):
url = d['default']
if valid_download(url):
yield url, pathlib.Path(package, 'config', key)
else:
for k, v in d.items():
yield from traverse_yield(v, k)
config_path = (package_path / 'config.json')
if config_path.exists():
with config_path.open() as json_file:
config = json.load(json_file)
yield from traverse_yield(config)
评论列表
文章目录