change python scripts so modules which register with blender have a register() functi...
[blender.git] / release / scripts / modules / bpy / utils.py
index 38de95aa6e49e227e4314b3b93a287f5a09cce35..8e2e86acb66a4017c9174a2aac11f053b8e8dac4 100644 (file)
@@ -12,7 +12,7 @@
 #
 #  You should have received a copy of the GNU General Public License
 #  along with this program; if not, write to the Free Software Foundation,
-#  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
 # ##### END GPL LICENSE BLOCK #####
 
@@ -27,6 +27,8 @@ import bpy as _bpy
 import os as _os
 import sys as _sys
 
+from _bpy import home_paths
+
 def load_scripts(reload_scripts=False, refresh_scripts=False):
     import traceback
     import time
@@ -54,7 +56,7 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
 
     def test_reload(module):
         try:
-            reload(module)
+            return reload(module)
         except:
             traceback.print_exc()
 
@@ -65,14 +67,14 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
             module_name = getattr(type_class, "__module__", "")
 
             if module_name and module_name != "bpy.types": # hard coded for C types
-               loaded_modules.add(module_name)
+                loaded_modules.add(module_name)
 
         for module_name in loaded_modules:
             print("Reloading:", module_name)
             test_reload(_sys.modules[module_name])
 
     for base_path in script_paths():
-        for path_subdir in ("ui", "op", "io", "cfg"):
+        for path_subdir in ("", "ui", "op", "io", "cfg"):
             path = _os.path.join(base_path, path_subdir)
             if _os.path.isdir(path):
 
@@ -87,7 +89,7 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
                     if f.endswith(".py"):
                         # python module
                         mod = test_import(f[0:-3])
-                    elif "." not in f:
+                    elif ("." not in f) and (_os.path.isfile(_os.path.join(path, f, "__init__.py"))):
                         # python package
                         mod = test_import(f)
                     else:
@@ -95,7 +97,15 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
 
                     if reload_scripts and mod:
                         print("Reloading:", mod)
-                        test_reload(mod)
+                        mod = test_reload(mod)
+
+                    if mod:
+                        register = getattr(mod, "register", None)
+                        if register:
+                            register()
+                        else:
+                            print("\nWarning! '%s%s%s' has no register function, this is now a requirement for registerable scripts." % (path, _os.sep, f))
+
 
     if _bpy.app.debug:
         print("Time %.4f" % (time.time() - t_main))
@@ -170,15 +180,12 @@ def script_paths(*args):
 
     # add user scripts dir
     user_script_path = _bpy.context.user_preferences.filepaths.python_scripts_directory
-
-    if not user_script_path:
-        # XXX - WIN32 needs checking, perhaps better call a blender internal function.
-        user_script_path = _os.path.join(_os.path.expanduser("~"), ".blender", "scripts")
-
-    user_script_path = _os.path.normpath(user_script_path)
-
-    if user_script_path not in scripts and _os.path.isdir(user_script_path):
-        scripts.append(user_script_path)
+    
+    for path in home_paths("scripts") + (user_script_path, ):
+        if path:
+            path = _os.path.normpath(path)
+            if path not in scripts and _os.path.isdir(path):
+                scripts.append(path)
 
     if not args:
         return scripts
@@ -189,7 +196,7 @@ def script_paths(*args):
         path_subdir = _os.path.join(path, subdir)
         if _os.path.isdir(path_subdir):
             script_paths.append(path_subdir)
-
+    print(script_paths)
     return script_paths