2018-10-13 15:37:20 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""
|
|
|
|
Grabs the latest version of every libretro core from the build bot.
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = "Melon Bread"
|
|
|
|
__version__ = "0.1.0"
|
|
|
|
__license__ = "MIT"
|
|
|
|
|
2018-10-15 23:29:44 -04:00
|
|
|
import argparse
|
2018-10-15 13:35:51 -04:00
|
|
|
import os
|
|
|
|
import zipfile
|
|
|
|
from shutil import rmtree
|
|
|
|
from urllib.request import urlretrieve
|
|
|
|
|
|
|
|
URL = 'https://buildbot.libretro.com/nightly'
|
|
|
|
|
2018-10-20 23:17:47 -04:00
|
|
|
PLATFORM = 'linux'
|
|
|
|
|
|
|
|
ARCHITECTURE = 'x86_64'
|
2018-10-15 13:35:51 -04:00
|
|
|
|
|
|
|
CORE_LOCATION = '~/.config/retroarch/cores/'
|
|
|
|
|
2018-10-13 15:37:20 -04:00
|
|
|
|
2018-10-15 23:29:44 -04:00
|
|
|
def main(args):
|
2018-10-15 13:35:51 -04:00
|
|
|
""" Where the magic happens """
|
2018-10-20 23:17:47 -04:00
|
|
|
|
2018-10-15 13:35:51 -04:00
|
|
|
download_cores()
|
|
|
|
extract_cores()
|
2018-10-16 00:29:45 -04:00
|
|
|
if not args.keep:
|
|
|
|
clean_up()
|
2018-10-15 13:35:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
def download_cores():
|
|
|
|
""" Downloads every core to the working directory """
|
|
|
|
|
|
|
|
cores = []
|
|
|
|
|
2018-10-15 23:21:33 -04:00
|
|
|
# Makes core directory to store archives if needed
|
2018-10-15 13:35:51 -04:00
|
|
|
if not os.path.isdir('cores'):
|
|
|
|
os.makedirs("cores")
|
|
|
|
|
2018-10-15 23:21:33 -04:00
|
|
|
# Downloads a list of all the cores available
|
2018-10-20 23:17:47 -04:00
|
|
|
urlretrieve('{}/{}/{}/latest/.index-extended'.format(URL, PLATFORM, ARCHITECTURE),
|
2018-10-15 13:35:51 -04:00
|
|
|
'cores/index')
|
|
|
|
print('Obtained core index!')
|
|
|
|
|
2018-10-15 23:21:33 -04:00
|
|
|
# Adds all the core's file names to a list
|
2018-10-15 13:35:51 -04:00
|
|
|
core_index = open('cores/index')
|
|
|
|
|
|
|
|
for line in core_index:
|
|
|
|
file_name = line.split(' ', 2)[2:]
|
|
|
|
cores.append(file_name[0].rstrip())
|
|
|
|
core_index.close()
|
|
|
|
cores.sort()
|
|
|
|
|
2018-10-15 23:21:33 -04:00
|
|
|
# Downloads each core from the list
|
2018-10-15 13:35:51 -04:00
|
|
|
for core in cores:
|
2018-10-20 23:17:47 -04:00
|
|
|
urlretrieve('{}/{}/{}/latest/{}'.format(URL, PLATFORM, ARCHITECTURE, core),
|
2018-10-15 13:35:51 -04:00
|
|
|
'cores/{}'.format(core))
|
|
|
|
print('Downloaded {} ...'.format(core))
|
|
|
|
|
2018-10-15 23:21:33 -04:00
|
|
|
# Removes index file for easier extraction
|
2018-10-15 13:35:51 -04:00
|
|
|
os.remove('cores/index')
|
|
|
|
|
|
|
|
|
|
|
|
def extract_cores():
|
|
|
|
""" Extracts each downloaded core to the RA core directory """
|
|
|
|
print('Extracting all cores to: {}'.format(CORE_LOCATION))
|
2018-10-15 23:21:33 -04:00
|
|
|
|
2018-10-15 13:35:51 -04:00
|
|
|
for file in os.listdir('cores'):
|
|
|
|
archive = zipfile.ZipFile('cores/{}'.format(file))
|
|
|
|
archive.extractall(CORE_LOCATION)
|
|
|
|
print('Extracted {} ...'.format(file))
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def clean_up():
|
|
|
|
""" Removes all the downloaded files """
|
|
|
|
rmtree('cores/')
|
2018-10-13 15:37:20 -04:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
""" This is executed when run from the command line """
|
2018-10-15 23:29:44 -04:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
2018-10-16 00:29:45 -04:00
|
|
|
parser.add_argument('-k', '--keep', action='store_true',
|
2018-10-20 23:17:47 -04:00
|
|
|
help='Keeps downloaded core archives')
|
2018-10-16 00:29:45 -04:00
|
|
|
|
2018-10-15 23:29:44 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
main(args)
|
2018-10-15 13:35:51 -04:00
|
|
|
pass
|