[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1163] trunk/py/scripts/addons/rigify/ __init__.py: Rigify patch from Campbell, to clean up some of the code.

Nathan Vegdahl cessen at cessen.com
Wed Nov 17 08:03:01 CET 2010


Revision: 1163
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1163
Author:   cessen
Date:     2010-11-17 08:03:00 +0100 (Wed, 17 Nov 2010)

Log Message:
-----------
Rigify patch from Campbell, to clean up some of the code.

Modified Paths:
--------------
    trunk/py/scripts/addons/rigify/__init__.py

Modified: trunk/py/scripts/addons/rigify/__init__.py
===================================================================
--- trunk/py/scripts/addons/rigify/__init__.py	2010-11-17 06:05:16 UTC (rev 1162)
+++ trunk/py/scripts/addons/rigify/__init__.py	2010-11-17 07:03:00 UTC (rev 1163)
@@ -27,45 +27,45 @@
     "tracker_url": "",
     "category": "Rigging"}
 
-import bpy
-import bpy_types
-import os
-from imp import reload
-
-
-try:
+if "bpy" in locals():
     reload(generate)
     reload(ui)
     reload(utils)
     reload(metarig_menu)
-except NameError:
+else:
     from rigify import generate, ui, utils, metarig_menu
 
+import bpy
+import bpy_types
+import os
 
+
 def get_rig_list(path):
     """ Recursively searches for rig types, and returns a list.
     """
     rigs = []
-    files = os.listdir(os.path.dirname(__file__) + "/" + utils.RIG_DIR + "/" + path)
-    files = sorted(files)
+    MODULE_DIR = os.path.dirname(__file__)
+    RIG_DIR_ABS = os.path.join(MODULE_DIR, utils.RIG_DIR)
+    SEARCH_DIR_ABS = os.path.join(RIG_DIR_ABS, path)
+    path_strip = path.strip(os.sep)
+    files = os.listdir(SEARCH_DIR_ABS)
+    files.sort()
 
     for f in files:
-        if not f.startswith("_"):
-            if os.path.isdir(os.path.dirname(__file__) + "/" + utils.RIG_DIR + "/" + path + f):
+        if not f.startswith("_") and not f.startswith("."):
+            f_abs = os.path.join(SEARCH_DIR_ABS, f)
+            if os.path.isdir(f_abs):
                 # Check directories
                 try:
-                    rig = utils.get_rig_type((path + f).replace("/", "."))
+                    rig = utils.get_rig_type(os.path.join(path_strip, f).replace(os.sep, "."))
                 except ImportError as e:
                     print("Rigify: " + str(e))
                 else:
                     # Check if it's a rig itself
-                    try:
-                        rig.Rig
-                    except AttributeError:
+                    if not hasattr(rig, "Rig"):
                         # Check for sub-rigs
-                        ls = get_rig_list(path + f + "/")
-                        for l in ls:
-                            rigs += [f + '.' + l]
+                        ls = get_rig_list(os.path.join(path, f, "")) # "" adds a final slash
+                        rigs.extend(["%s.%s" % (f, l) for l in ls])
                     else:
                         rigs += [f]
 




More information about the Bf-extensions-cvs mailing list