mirror of
https://github.com/Melon-Bread/RetroUFO
synced 2024-11-28 18:28:21 -05:00
Added platform/architecture detection for Linux & Windows (32bit/64bit) along with many arguments 😪
This commit is contained in:
parent
c1c69e3ea7
commit
ebc29dd7ab
78
RetroUFO.py
78
RetroUFO.py
@ -4,34 +4,69 @@ Grabs the latest version of every libretro core from the build bot.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
__author__ = "Melon Bread"
|
__author__ = "Melon Bread"
|
||||||
__version__ = "0.1.0"
|
__version__ = "0.8.0"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
import platform
|
||||||
|
import sys
|
||||||
import zipfile
|
import zipfile
|
||||||
|
from pathlib import Path
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from urllib.request import urlretrieve
|
from urllib.request import urlretrieve
|
||||||
|
|
||||||
URL = 'https://buildbot.libretro.com/nightly'
|
URL = 'https://buildbot.libretro.com/nightly'
|
||||||
|
|
||||||
PLATFORM = 'linux'
|
# These are the default core locations with normal RetroArch installs based off of 'retroarch.default.cfg`
|
||||||
|
CORE_LOCATION = {
|
||||||
ARCHITECTURE = 'x86_64'
|
'linux': '{}/.config/retroarch/cores/'.format(Path.home()),
|
||||||
|
'windows': '{}/AppData/Roaming/RetroArch/cores'.format(Path.home())
|
||||||
CORE_LOCATION = '~/.config/retroarch/cores/'
|
}
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(_args):
|
||||||
""" Where the magic happens """
|
""" Where the magic happens """
|
||||||
|
|
||||||
download_cores()
|
# If a platform and/or architecture is not supplied it is grabbed automatically
|
||||||
extract_cores()
|
platform = _args.platform if _args.platform else get_platform() # TODO: rename this var to prevent conflict
|
||||||
|
architecture = _args.architecture if _args.architecture else get_architecture()
|
||||||
|
location = _args.location if _args.location else CORE_LOCATION[platform]
|
||||||
|
|
||||||
|
download_cores(platform, architecture)
|
||||||
|
extract_cores(location)
|
||||||
|
|
||||||
if not args.keep:
|
if not args.keep:
|
||||||
clean_up()
|
clean_up()
|
||||||
|
|
||||||
|
|
||||||
def download_cores():
|
def get_platform():
|
||||||
|
""" Gets the Platform and Architecture if not supplied """
|
||||||
|
|
||||||
|
if platform.system() == 'Linux':
|
||||||
|
return 'linux'
|
||||||
|
|
||||||
|
elif platform.system() == 'Windows' or 'MSYS_NT' in platform.system(): # Checks for MSYS environment as well
|
||||||
|
return 'windows'
|
||||||
|
else:
|
||||||
|
print('ERROR: Platform not found or supported')
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
def get_architecture():
|
||||||
|
""" Gets the Platform and Architecture if not supplied """
|
||||||
|
|
||||||
|
if '64' in platform.architecture()[0]:
|
||||||
|
return 'x86_64'
|
||||||
|
|
||||||
|
elif '32' in platform.architecture()[0]:
|
||||||
|
return 'x86'
|
||||||
|
else:
|
||||||
|
print('ERROR: Architecture not found or supported')
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
def download_cores(_platform, _architecture):
|
||||||
""" Downloads every core to the working directory """
|
""" Downloads every core to the working directory """
|
||||||
|
|
||||||
cores = []
|
cores = []
|
||||||
@ -41,7 +76,7 @@ def download_cores():
|
|||||||
os.makedirs("cores")
|
os.makedirs("cores")
|
||||||
|
|
||||||
# Downloads a list of all the cores available
|
# Downloads a list of all the cores available
|
||||||
urlretrieve('{}/{}/{}/latest/.index-extended'.format(URL, PLATFORM, ARCHITECTURE),
|
urlretrieve('{}/{}/{}/latest/.index-extended'.format(URL, _platform, _architecture),
|
||||||
'cores/index')
|
'cores/index')
|
||||||
print('Obtained core index!')
|
print('Obtained core index!')
|
||||||
|
|
||||||
@ -56,7 +91,7 @@ def download_cores():
|
|||||||
|
|
||||||
# Downloads each core from the list
|
# Downloads each core from the list
|
||||||
for core in cores:
|
for core in cores:
|
||||||
urlretrieve('{}/{}/{}/latest/{}'.format(URL, PLATFORM, ARCHITECTURE, core),
|
urlretrieve('{}/{}/{}/latest/{}'.format(URL, _platform, _architecture, core),
|
||||||
'cores/{}'.format(core))
|
'cores/{}'.format(core))
|
||||||
print('Downloaded {} ...'.format(core))
|
print('Downloaded {} ...'.format(core))
|
||||||
|
|
||||||
@ -64,30 +99,37 @@ def download_cores():
|
|||||||
os.remove('cores/index')
|
os.remove('cores/index')
|
||||||
|
|
||||||
|
|
||||||
def extract_cores():
|
def extract_cores(_location):
|
||||||
""" Extracts each downloaded core to the RA core directory """
|
""" Extracts each downloaded core to the RA core directory """
|
||||||
print('Extracting all cores to: {}'.format(CORE_LOCATION))
|
print('Extracting all cores to: {}'.format(_location))
|
||||||
|
|
||||||
for file in os.listdir('cores'):
|
for file in os.listdir('cores'):
|
||||||
archive = zipfile.ZipFile('cores/{}'.format(file))
|
archive = zipfile.ZipFile('cores/{}'.format(file))
|
||||||
archive.extractall(CORE_LOCATION)
|
archive.extractall(_location)
|
||||||
print('Extracted {} ...'.format(file))
|
print('Extracted {} ...'.format(file))
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def clean_up():
|
def clean_up():
|
||||||
""" Removes all the downloaded files """
|
""" Removes all the downloaded files """
|
||||||
|
if os.listdir('cores'):
|
||||||
rmtree('cores/')
|
rmtree('cores/')
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
""" This is executed when run from the command line """
|
""" This is executed when run from the command line """
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
parser.add_argument('-p', '--platform', metavar='STRING', required=False,
|
||||||
|
help='Platform you desire to download for')
|
||||||
|
|
||||||
|
parser.add_argument('-a', '--architecture', metavar='STRING', required=False,
|
||||||
|
help='Architecture for tha platform you desire to download for')
|
||||||
|
|
||||||
|
parser.add_argument('-l', '--location', metavar='STRING', required=False,
|
||||||
|
help='Location you wish the cores to extract to')
|
||||||
|
|
||||||
parser.add_argument('-k', '--keep', action='store_true',
|
parser.add_argument('-k', '--keep', action='store_true',
|
||||||
help='Keeps downloaded core archives')
|
help='Keeps downloaded core archives')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
main(args)
|
main(args)
|
||||||
pass
|
|
||||||
|
Loading…
Reference in New Issue
Block a user