2019-03-03 02:17:52 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""
|
|
|
|
Grabs the latest version of every libretro core from the build bot.
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = "Melon Bread"
|
|
|
|
__version__ = "0.8.0"
|
|
|
|
__license__ = "MIT"
|
|
|
|
|
2019-03-03 23:15:08 -05:00
|
|
|
import os
|
|
|
|
import platform
|
2019-03-03 02:17:52 -05:00
|
|
|
import sys
|
2019-03-03 23:15:08 -05:00
|
|
|
import zipfile
|
|
|
|
from shutil import rmtree
|
|
|
|
from urllib.request import urlretrieve
|
2019-03-03 02:17:52 -05:00
|
|
|
|
2019-03-03 23:35:50 -05:00
|
|
|
from PySide2.QtWidgets import (QApplication, QCheckBox, QComboBox, QDialog,
|
|
|
|
QFileDialog, QLineEdit, QPushButton, QTextEdit,
|
2019-03-04 01:02:16 -05:00
|
|
|
QVBoxLayout, QMessageBox)
|
2019-03-03 02:17:52 -05:00
|
|
|
|
2019-03-03 23:15:08 -05:00
|
|
|
URL = 'https://buildbot.libretro.com/nightly'
|
|
|
|
|
|
|
|
# These are the default core locations with normal RetroArch installs based off of 'retroarch.default.cfg`
|
|
|
|
CORE_LOCATION = {
|
2019-03-04 20:55:30 -05:00
|
|
|
'linux': '{}/.config/retroarch/cores'.format(os.path.expanduser('~')),
|
|
|
|
'apple/osx': '{}/Library/Applications/RetroArch.app/Contents/Resources/cores'.format(os.path.expanduser('~')), # macOS
|
|
|
|
'windows': '{}/AppData/Roaming/RetroArch/cores'.format(os.path.expanduser('~'))
|
2019-03-03 23:15:08 -05:00
|
|
|
}
|
|
|
|
|
2019-03-03 02:17:52 -05:00
|
|
|
|
2019-03-03 23:35:50 -05:00
|
|
|
class Form(QDialog):
|
2019-03-03 02:17:52 -05:00
|
|
|
def __init__(self, parent=None):
|
|
|
|
super(Form, self).__init__(parent)
|
|
|
|
self.setWindowTitle('RetroUFO')
|
|
|
|
|
|
|
|
# Create widgets
|
|
|
|
self.chkboxPlatformDetect = QCheckBox('Platform Auto-Detect')
|
|
|
|
self.chkboxPlatformDetect.setChecked(True)
|
2019-03-04 01:02:16 -05:00
|
|
|
self.chkboxPlatformDetect.stateChanged.connect(self.auto_detect)
|
2019-03-03 02:17:52 -05:00
|
|
|
|
|
|
|
self.cmbboxPlatform = QComboBox()
|
|
|
|
self.cmbboxPlatform.setEnabled(False)
|
|
|
|
self.cmbboxPlatform.setEditable(False)
|
|
|
|
self.cmbboxPlatform.addItem('Linux')
|
2019-03-04 20:55:30 -05:00
|
|
|
self.cmbboxPlatform.addItem('macOS')
|
2019-03-03 02:17:52 -05:00
|
|
|
self.cmbboxPlatform.addItem('Windows')
|
|
|
|
|
2019-03-04 01:02:16 -05:00
|
|
|
self.cmbboxArchitecture = QComboBox()
|
|
|
|
self.cmbboxArchitecture.setEnabled(False)
|
|
|
|
self.cmbboxArchitecture.setEditable(False)
|
|
|
|
self.cmbboxArchitecture.addItem('x86')
|
|
|
|
self.cmbboxArchitecture.addItem('x86_64')
|
|
|
|
|
2019-03-03 02:17:52 -05:00
|
|
|
self.chkboxLocationDetect = QCheckBox('Core Location Auto-Detect')
|
|
|
|
self.chkboxLocationDetect.setChecked(True)
|
|
|
|
self.chkboxLocationDetect.stateChanged.connect(self.auto_location)
|
|
|
|
|
|
|
|
self.leditCoreLocation = QLineEdit('')
|
|
|
|
self.leditCoreLocation.setEnabled(False)
|
|
|
|
|
|
|
|
self.btnCoreLocation = QPushButton('...')
|
|
|
|
self.btnCoreLocation.setEnabled(False)
|
|
|
|
self.btnCoreLocation.clicked.connect(self.choose_location)
|
|
|
|
|
|
|
|
self.teditLog = QTextEdit()
|
|
|
|
self.teditLog.setReadOnly(True)
|
2019-03-03 23:35:50 -05:00
|
|
|
|
2019-03-03 23:15:08 -05:00
|
|
|
self.chkboxKeepDownload = QCheckBox('Keep Downloaded Cores')
|
|
|
|
self.chkboxKeepDownload.setChecked(False)
|
|
|
|
|
2019-03-03 02:17:52 -05:00
|
|
|
self.btnGrabCores = QPushButton('Grab Cores')
|
2019-03-03 23:15:08 -05:00
|
|
|
self.btnGrabCores.clicked.connect(self.grab_cores)
|
2019-03-03 02:17:52 -05:00
|
|
|
|
|
|
|
# Create layout and add widgets
|
|
|
|
layout = QVBoxLayout()
|
|
|
|
layout.addWidget(self.chkboxPlatformDetect)
|
|
|
|
layout.addWidget(self.cmbboxPlatform)
|
2019-03-04 01:02:16 -05:00
|
|
|
layout.addWidget(self.cmbboxArchitecture)
|
2019-03-03 02:17:52 -05:00
|
|
|
layout.addWidget(self.chkboxLocationDetect)
|
|
|
|
layout.addWidget(self.leditCoreLocation)
|
|
|
|
layout.addWidget(self.btnCoreLocation)
|
|
|
|
layout.addWidget(self.teditLog)
|
2019-03-03 23:15:08 -05:00
|
|
|
layout.addWidget(self.chkboxKeepDownload)
|
2019-03-03 02:17:52 -05:00
|
|
|
layout.addWidget(self.btnGrabCores)
|
|
|
|
|
|
|
|
# Set dialog layout
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
2019-03-04 01:02:16 -05:00
|
|
|
def auto_detect(self):
|
2019-03-03 02:17:52 -05:00
|
|
|
if self.chkboxPlatformDetect.isChecked():
|
|
|
|
self.cmbboxPlatform.setEnabled(False)
|
2019-03-04 01:02:16 -05:00
|
|
|
self.cmbboxArchitecture.setEnabled(False)
|
2019-03-03 02:17:52 -05:00
|
|
|
else:
|
|
|
|
self.cmbboxPlatform.setEnabled(True)
|
2019-03-04 01:02:16 -05:00
|
|
|
self.cmbboxArchitecture.setEnabled(True)
|
2019-03-03 02:17:52 -05:00
|
|
|
|
|
|
|
def auto_location(self):
|
|
|
|
if self.chkboxLocationDetect.isChecked():
|
|
|
|
self.leditCoreLocation.setEnabled(False)
|
|
|
|
self.btnCoreLocation.setEnabled(False)
|
|
|
|
else:
|
|
|
|
self.leditCoreLocation.setEnabled(True)
|
|
|
|
self.btnCoreLocation.setEnabled(True)
|
|
|
|
|
|
|
|
def choose_location(self):
|
2019-03-03 23:35:50 -05:00
|
|
|
directory = QFileDialog.getExistingDirectory(
|
2019-03-04 20:55:30 -05:00
|
|
|
self, 'Choose Target Location', os.path.expanduser('~'))
|
2019-03-03 02:17:52 -05:00
|
|
|
|
|
|
|
self.leditCoreLocation.insert(directory)
|
|
|
|
|
2019-03-03 23:15:08 -05:00
|
|
|
def grab_cores(self):
|
2019-03-04 20:55:30 -05:00
|
|
|
self.teditLog.insertPlainText('~Starting UFO Grabber~\n')
|
2019-03-03 23:15:08 -05:00
|
|
|
""" Where the magic happens """
|
|
|
|
|
|
|
|
# If a platform and/or architecture is not supplied it is grabbed automatically
|
2019-03-04 20:55:30 -05:00
|
|
|
platform = self.get_platform() # TODO: rename this var to prevent conflict
|
|
|
|
architecture = self.get_architecture()
|
2019-03-04 01:35:52 -05:00
|
|
|
location = self.leditCoreLocation.text() if not self.chkboxLocationDetect.isChecked() \
|
|
|
|
else CORE_LOCATION[platform]
|
2019-03-03 23:15:08 -05:00
|
|
|
|
|
|
|
self.download_cores(platform, architecture)
|
|
|
|
self.extract_cores(location)
|
|
|
|
|
2019-03-03 23:35:50 -05:00
|
|
|
if not self.chkboxKeepDownload.isChecked():
|
2019-03-03 23:15:08 -05:00
|
|
|
self.clean_up()
|
|
|
|
|
|
|
|
def get_platform(self):
|
|
|
|
""" Gets the Platform and Architecture if not supplied """
|
2019-03-04 20:55:30 -05:00
|
|
|
|
|
|
|
if not self.chkboxPlatformDetect.isChecked():
|
|
|
|
if self.cmbboxPlatform.currentText() == 'macOS':
|
|
|
|
return 'apple/osx' # macOS
|
|
|
|
else:
|
|
|
|
return self.cmbboxPlatform.currentText().lower()
|
2019-03-03 23:15:08 -05:00
|
|
|
else:
|
2019-03-04 20:55:30 -05:00
|
|
|
if platform.system() == 'Linux':
|
|
|
|
return 'linux'
|
|
|
|
elif platform.system() == 'Darwin': # macOS
|
|
|
|
return 'apple/osx'
|
|
|
|
elif platform.system() == 'Windows' or 'MSYS_NT' in platform.system(): # Checks for MSYS environment as well
|
|
|
|
return 'windows'
|
|
|
|
else:
|
|
|
|
msgBox = QMessageBox.warning(self, 'Error', 'Platform not found or supported!', QMessageBox.Ok)
|
|
|
|
msgBox.exec_()
|
|
|
|
sys.exit(0)
|
2019-03-03 23:15:08 -05:00
|
|
|
|
|
|
|
def get_architecture(self):
|
|
|
|
""" 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:
|
2019-03-04 01:02:16 -05:00
|
|
|
msgBox = QMessageBox.warning(self, 'Error', 'Architecture not found or supported', QMessageBox.Ok)
|
|
|
|
msgBox.exec_()
|
2019-03-03 23:15:08 -05:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
def download_cores(self, _platform, _architecture):
|
|
|
|
""" Downloads every core to the working directory """
|
|
|
|
|
|
|
|
cores = []
|
|
|
|
|
|
|
|
# Makes core directory to store archives if needed
|
|
|
|
if not os.path.isdir('cores'):
|
|
|
|
os.makedirs("cores")
|
|
|
|
|
|
|
|
# Downloads a list of all the cores available
|
2019-03-03 23:35:50 -05:00
|
|
|
urlretrieve(
|
|
|
|
'{}/{}/{}/latest/.index-extended'.format(
|
|
|
|
URL, _platform, _architecture), 'cores/index')
|
2019-03-04 20:55:30 -05:00
|
|
|
self.teditLog.insertPlainText('\nObtained core index!')
|
2019-03-03 23:15:08 -05:00
|
|
|
|
|
|
|
# Adds all the core's file names to a list
|
|
|
|
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()
|
|
|
|
|
|
|
|
# Downloads each core from the list
|
|
|
|
for core in cores:
|
2019-03-03 23:35:50 -05:00
|
|
|
urlretrieve(
|
|
|
|
'{}/{}/{}/latest/{}'.format(URL, _platform, _architecture,
|
|
|
|
core), 'cores/{}'.format(core))
|
2019-03-04 20:55:30 -05:00
|
|
|
self.teditLog.insertPlainText('\nDownloaded {} ...'.format(core))
|
2019-03-03 23:15:08 -05:00
|
|
|
|
|
|
|
# Removes index file for easier extraction
|
|
|
|
os.remove('cores/index')
|
|
|
|
|
|
|
|
def extract_cores(self, _location):
|
|
|
|
""" Extracts each downloaded core to the RA core directory """
|
2019-03-04 20:55:30 -05:00
|
|
|
self.teditLog.insertPlainText('\nExtracting all cores to: {}'.format(_location))
|
2019-03-03 23:15:08 -05:00
|
|
|
|
|
|
|
for file in os.listdir('cores'):
|
|
|
|
archive = zipfile.ZipFile('cores/{}'.format(file))
|
|
|
|
archive.extractall(_location)
|
2019-03-04 20:55:30 -05:00
|
|
|
self.teditLog.insertPlainText('\nExtracted {} ...'.format(file))
|
2019-03-03 23:15:08 -05:00
|
|
|
|
|
|
|
def clean_up(self):
|
|
|
|
""" Removes all the downloaded files """
|
|
|
|
if os.listdir('cores'):
|
|
|
|
rmtree('cores/')
|
2019-03-03 02:17:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# Create the Qt Application
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
# Create and show the form
|
|
|
|
form = Form()
|
|
|
|
form.show()
|
|
|
|
# Run the main Qt loop
|
|
|
|
sys.exit(app.exec_())
|