forked from ladybug-tools/ladybug-grasshopper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LB_Versioner.json
28 lines (28 loc) 路 5.16 KB
/
LB_Versioner.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
"version": "1.6.1",
"nickname": "Versioner",
"outputs": [
[]
],
"inputs": [
{
"access": "item",
"name": "_update",
"description": "Set to True to update your installation of Ladybug Tools to the\nlatest development version or to be at the version specified below.",
"type": "bool",
"default": null
},
{
"access": "item",
"name": "version_",
"description": "An optional text string for the version of the grasshopper\nplugin which you would like to update to. The input should contain\nonly integers separated by two periods (eg. 1.0.0). The version does\nnot need to be newer than the current installation and can be older\nbut grasshopper plugin versions less than 0.3.0 are not supported.\nA list of all versions of the Grasshopper plugin can be found\nhere - https://github.com/ladybug-tools/lbt-grasshopper/releases",
"type": "string",
"default": null
}
],
"subcategory": "5 :: Version",
"code": "\nimport os\nimport tempfile\nimport subprocess\n\ntry:\n from ladybug.config import folders\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.versioning.diff import current_userobject_version\n from ladybug_{{cad}}.versioning.change import latest_github_version\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, give_warning, \\\n give_popup_message, is_user_admin\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component) and _update:\n # get the paths to the executables\n lb_{{cad}}_exe = os.path.join(folders.python_scripts_path, 'ladybug-{{cad}}.exe') \\\n if os.name == 'nt' else os.path.join(folders.python_scripts_path, 'ladybug-{{cad}}')\n executor_path = os.path.join(\n folders.ladybug_tools_folder, '{{plugin}}', 'ladybug_{{plugin}}_dotnet',\n 'Ladybug.Executor.exe')\n\n # run the command to update everything\n if os.name == 'nt' and os.path.isfile(executor_path) and \\\n 'Program Files' in executor_path and not is_user_admin():\n cmd = [\n executor_path, folders.python_exe_path,\n '-m ladybug_{{cad}} change-installed-version'\n ]\n else:\n cmd = [lb_{{cad}}_exe, 'change-installed-version']\n if version_ is not None:\n cmd.extend(['--version', version_])\n use_shell = True if os.name == 'nt' else False\n process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=use_shell)\n cmd_output = process.communicate() # ensure that the canvas is frozen\n stdout = cmd_output[0]\n print(stdout)\n if 'Error' in stdout:\n if 'ladybug-{{cad}}.exe' not in stdout:\n raise ValueError(stdout)\n else: # recent Windows permission issue; reinstall ladybug-{{cad}}\n cmd = cmds = [folders.python_exe_path, '-m', 'pip', 'install', 'ladybug-{{cad}}', '-U']\n process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=use_shell)\n cmd_output = process.communicate() # ensure that the canvas is frozen\n\n # give a completion message\n if version_ is None:\n temp_dir = tempfile.gettempdir()\n version_ = latest_github_version('lbt-{{plugin}}', temp_dir)\n version = 'LATEST' if version_ is None else version_\n success_msg = 'Change to Version {} Successful!'.format(version)\n restart_msg = 'RESTART RHINO to load the new components + library.'\n sync_msg = 'The \"LB Sync {{Plugin}} File\" component can be used\\n' \\\n 'to sync {{Plugin}} definitions with your new installation.'\n for msg in (success_msg, restart_msg, sync_msg):\n print (msg)\n give_popup_message('\\n'.join([restart_msg, sync_msg]), success_msg)\n\n # do a check to see if the versioner has, itself, been updated\n new_version = current_userobject_version(ghenv.Component)\n current_version = ghenv.Component.Message\n if new_version != current_version:\n msg = 'The Versioner component has, itself, been changed between the\\n' \\\n 'current version ({}) and the version you are changing to ({}).\\n' \\\n 'It is recommended that you resart {{Cad}} and run the new Versioner\\n' \\\n 'coponent to ensure that everything is consistent.'.format(\n current_version, new_version)\n print (msg)\n give_warning(ghenv.Component, msg)\nelse: # give a message to the user about what to do\n print ('Make sure you are connected to the internet and set _update to True!')\n",
"category": "Ladybug",
"name": "LB Versioner",
"description": "This component updates the Ladybug Tools core libraries and grasshopper components\nto either the latest development version available (default) or to a specific\nversion of the grasshopper plugin.\n_\nThe input version_ does not need to be newer than the current installation and can\nbe older but grasshopper plugin versions less than 0.3.0 are not supported.\nA list of all versions of the Grasshopper plugin and corresponding release notes\ncan be found at: https://github.com/ladybug-tools/lbt-grasshopper/releases\n-"
}