Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mcs 1957 windows auto downloader #702

Merged
merged 11 commits into from
Oct 13, 2023
55 changes: 44 additions & 11 deletions machine_common_sense/unity_executable_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,49 @@

LINUX_URL = "https://github.com/NextCenturyCorporation/MCS/releases/download/{ver}/MCS-AI2-THOR-Unity-App-v{ver}-linux.zip" # noqa
MAC_URL = "https://github.com/NextCenturyCorporation/MCS/releases/download/{ver}/MCS-AI2-THOR-Unity-App-v{ver}-mac.zip" # noqa
WIN64_URL = "https://github.com/NextCenturyCorporation/MCS/releases/download/{ver}/MCS-AI2-THOR-Unity-App-v{ver}-win64.zip" # noqa
LINUX_DEV_URL = "https://ai2thor-unity-releases.s3.amazonaws.com/MCS-AI2-THOR-Unity-App-vdevelop-linux.zip" # noqa
MAC_DEV_URL = "https://ai2thor-unity-releases.s3.amazonaws.com/MCS-AI2-THOR-Unity-App-vdevelop-mac.zip" # noqa
WIN64_DEV_URL = "https://ai2thor-unity-releases.s3.amazonaws.com/MCS-AI2-THOR-Unity-App-vdevelop-win64.zip" # noqa

PLATFORM_MAC = "Darwin"
PLATFORM_LINUX = "Linux"
PLATFORM_OTHER = "other"
PLATFORM_WINDOWS64 = "Windows"


class UnityExecutableProvider():
'''Automatically provides MCS AI2-THOR Unity executable for the MCS
package. Will check a cache and download if necessary'''

DOWNLOAD_FILE = "MCS-AI2-THOR-Unity-App-v{}.zip"
PLATFORM_MAC = "Darwin"
PLATFORM_LINUX = "Linux"
PLATFORM_OTHER = "other"

def __init__(self):
self._downloader = Downloader()
self._platform_init()

def _platform_init(self):
self._switcher = {
self.PLATFORM_LINUX: self._linux_init,
self.PLATFORM_MAC: self._mac_init,
self.PLATFORM_OTHER: self._other_init
PLATFORM_LINUX: self._linux_init,
PLATFORM_MAC: self._mac_init,
PLATFORM_OTHER: self._other_init,
PLATFORM_WINDOWS64: self._windows64_init
}
sys = platform.system()
self._switcher.get(sys, self.PLATFORM_OTHER)()
self._switcher.get(sys, PLATFORM_OTHER)()

def _mac_init(self):
self._cache = MacExecutionCache()

def _linux_init(self):
self._cache = LinuxExecutionCache()

def _windows64_init(self):
self._cache = Windows64ExecutionCache()

def _other_init(self):
raise Exception(
"Ai2thorProvider only supports Linux and Mac. "
"Ai2thorProvider only supports Linux, Windows and Mac. "
f"Platform={platform.system()}"
)

Expand Down Expand Up @@ -151,10 +159,12 @@ def add_zip_to_cache(self, version, zip_file: Path):
f"Unzipping {zip_file.name} to {ver_dir.as_posix()}")
zip.extractall(ver_dir)
logger.info(f"Deleting {zip_file.name}.")
zip_file.unlink()
if platform.system() in [PLATFORM_LINUX, PLATFORM_MAC]:
zip_file.unlink()
ver_dir = self._get_version_dir(version)
file = self._get_executable_file().format(version=version)
(ver_dir / file).chmod(755)
if platform.system() in [PLATFORM_LINUX, PLATFORM_MAC]:
(ver_dir / file).chmod(755)

for file in self._get_gz_files():
file = file.format(version=version)
Expand Down Expand Up @@ -246,13 +256,36 @@ def _get_required_files(self):
return self.REQUIRED_FILES


class Windows64ExecutionCache(AbstractExecutionCache):
'''Handles Windows64 specific code for running a cache for MCS Unity
executables.'''
REQUIRED_FILES = [
"MonoBleedingEdge",
"UnityPlayer.dll",
"UnityCrashHandler64.exe",
"MCS-AI2-THOR-Unity-App-v{version}-win64_Data",
"MCS-AI2-THOR-Unity-App-v{version}-win64.exe"]
EXECUTABLE_FILE = "MCS-AI2-THOR-Unity-App-v{version}-win64.exe"
GZ_FILES = ["MCS-AI2-THOR-Unity-App-v{version}-win64_Data.tar.gz"]

def _get_executable_file(self):
return self.EXECUTABLE_FILE

def _get_gz_files(self):
return self.GZ_FILES

def _get_required_files(self):
return self.REQUIRED_FILES


class Downloader():
'''Handles downloading MCS AI2THOR package'''

def get_url(self, ver):
sys = platform.system()
if (sys == "Windows"):
raise Exception("Windows is not supported")
return WIN64_URL.format(
ver=ver) if ver != "develop" else WIN64_DEV_URL
elif sys == "Linux":
return LINUX_URL.format(
ver=ver) if ver != "develop" else LINUX_DEV_URL
Expand Down
Loading