Skip to content

Instantly share code, notes, and snippets.

@dafzor
Last active September 4, 2017 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dafzor/12e555958337c7810d5edce04c93021e to your computer and use it in GitHub Desktop.
Save dafzor/12e555958337c7810d5edce04c93021e to your computer and use it in GitHub Desktop.
"""
Retroarch update existing cores script
created by /u/dafzor based on idea from /u/toeshred
version: 2017-09-04
"""
from os import listdir, remove
from os.path import isfile, join, abspath, expandvars
from urllib.request import urlretrieve
from tempfile import gettempdir
from zipfile import ZipFile
from shutil import copyfile
# variables to edit, platform is part of the path in the cores_url
PLATFORM = "windows/x86_64"
CORES_PATH = "./cores"
# sets the temporary file we'll be using for all our cores and the download directory
TEMP_FILE = join(gettempdir(), 'temp.zip')
CORES_URL = 'http://buildbot.libretro.com/nightly/{}/latest'.format(PLATFORM)
CORES_PATH = abspath(expandvars(CORES_PATH))
# gets all the cores in the retroarch core folder
for file in [f for f in listdir(CORES_PATH) if isfile(join(CORES_PATH, f))]:
# downloads the latest version of the url
remote_file = '{}/{}.zip'.format(CORES_URL, file)
print ('downloading: {}'.format(remote_file))
urlretrieve(remote_file, TEMP_FILE)
# extracts the zip file we just downloaded
print ('extracting: ', TEMP_FILE)
zip = ZipFile(TEMP_FILE)
zip.extractall(gettempdir())
zip.close()
# copies the cores over the existing ones
target_file = join(CORES_PATH, file)
print('copying over to: ', target_file)
copyfile(join(gettempdir(), file), target_file)
# clean up the temporary file
print('deleting temp file: ', TEMP_FILE)
remove(TEMP_FILE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment