fix [#28191] Exception when enabling a script for a newer Blender build

This commit is contained in:
Campbell Barton 2011-08-09 14:16:22 +00:00
parent 08e184f302
commit da6bc69ca9
2 changed files with 14 additions and 6 deletions

View File

@ -220,8 +220,8 @@ General functions
.. note::
This function is not effective immediately, the scene is queued
and added on the next logic cycle where it will be available
from `getSceneList`
and added on the next logic cycle where it will be available
from `getSceneList`
:arg name: The name of the scene
:type name: string

View File

@ -1076,17 +1076,25 @@ class WM_OT_addon_enable(bpy.types.Operator):
bl_idname = "wm.addon_enable"
bl_label = "Enable Add-On"
module = StringProperty(name="Module", description="Module name of the addon to enable")
module = StringProperty(
name="Module",
description="Module name of the addon to enable",
)
def execute(self, context):
mod = addon_utils.enable(self.module)
if mod:
# check if add-on is written for current blender version, or raise a warning
info = addon_utils.module_bl_info(mod)
if info.get("blender", (0, 0, 0)) > bpy.app.version:
self.report("WARNING','This script was written for a newer version of Blender and might not function (correctly).\nThe script is enabled though.")
info_ver = info.get("blender", (0, 0, 0))
if info_ver > bpy.app.version:
self.report({'WARNING'}, ("This script was written Blender "
"version %d.%d.%d and might not "
"function (correctly).\n"
"The script is enabled though.") %
info_ver)
return {'FINISHED'}
else:
return {'CANCELLED'}