From 4008f75696458844ca52a598d7533b343547513c Mon Sep 17 00:00:00 2001 From: tomvanmele Date: Mon, 26 Feb 2024 13:16:03 +0100 Subject: [PATCH] initial commit --- src/compas_rhino/__init__.py | 40 +++++++++++++++++++ src/compas_rhino/install.py | 5 ++- .../print_installed_rhino_versions.py | 6 +++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/compas_rhino/print_installed_rhino_versions.py diff --git a/src/compas_rhino/__init__.py b/src/compas_rhino/__init__.py index 2d3a3d201734..dadac83b80dd 100644 --- a/src/compas_rhino/__init__.py +++ b/src/compas_rhino/__init__.py @@ -16,6 +16,7 @@ SUPPORTED_VERSIONS = ["5.0", "6.0", "7.0", "8.0"] DEFAULT_VERSION = "8.0" INSTALLED_VERSION = None +INSTALLED_RHINO_VERSIONS = [] INSTALLATION_ARGUMENTS = None @@ -30,6 +31,7 @@ "SUPPORTED_VERSIONS", "DEFAULT_VERSION", "INSTALLED_VERSION", + "INSTALLED_RHINO_VERSIONS", "IRONPYTHON_PLUGIN_GUID", "GRASSHOPPER_PLUGIN_GUID", "RHINOCYCLES_PLUGIN_GUID", @@ -202,6 +204,44 @@ def _try_remove_bootstrapper(path): # ============================================================================= +def _get_application_folder(): + if compas.WINDOWS: + return os.getenv("ProgramFiles") + + if compas.OSX: + return os.path.join("/", "Applications") + + raise Exception("Unsupported platform") + + +def _get_installed_rhino_versions(): + global INSTALLED_RHINO_VERSIONS + + appfolder = _get_application_folder() + versions = [] + + if compas.WINDOWS: + for version in ["6", "7", "8", "9"]: + if os.path.exists(os.path.join(appfolder, "Rhino {}".format(version))): + versions.append(version) + + elif compas.OSX: + if os.path.exists(os.path.join(appfolder, "Rhinocerso.app")): + versions.append("6") + + for version in ["7", "8", "9"]: + if os.path.exists(os.path.join(appfolder, "Rhino {}.app".format(version))): + versions.append(version) + + else: + raise Exception("Unsupported platform") + + versions = ["{:.1f}".format(float(v)) for v in versions] + INSTALLED_RHINO_VERSIONS = versions + + return versions + + def _get_rhino_application_folder(version): version = _check_rhino_version(version) version = version.split(".")[0] # take the major only diff --git a/src/compas_rhino/install.py b/src/compas_rhino/install.py index 0fcf7a5f6044..609040dc2896 100644 --- a/src/compas_rhino/install.py +++ b/src/compas_rhino/install.py @@ -20,7 +20,7 @@ def install(version=None, packages=None, clean=False): ---------- version : {'5.0', '6.0', '7.0', '8.0'}, optional The version number of Rhino. - Default is ``'7.0'``. + Default is the latest supported version you have installed. packages : list of str, optional List of packages to install or None to use default package list. Default is the result of ``installable_rhino_packages``, @@ -41,8 +41,11 @@ def install(version=None, packages=None, clean=False): python -m compas_rhino.install """ + version = "{:.1f}".format(float(version)) version = compas_rhino._check_rhino_version(version) + # Check if the + # We install COMPAS packages in the scripts folder # instead of directly as IPy module. # scripts_path = compas_rhino._get_rhino_scripts_path(version) diff --git a/src/compas_rhino/print_installed_rhino_versions.py b/src/compas_rhino/print_installed_rhino_versions.py new file mode 100644 index 000000000000..6fd45798fb4d --- /dev/null +++ b/src/compas_rhino/print_installed_rhino_versions.py @@ -0,0 +1,6 @@ +import compas_rhino + + +if __name__ == "__main__": + + print(compas_rhino._get_installed_rhino_versions())