[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31822] trunk/blender/release/scripts: new bpy function bpy.path.module_names(path, recursive=False)
Campbell Barton
ideasman42 at gmail.com
Wed Sep 8 06:55:38 CEST 2010
Revision: 31822
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31822
Author: campbellbarton
Date: 2010-09-08 06:55:37 +0200 (Wed, 08 Sep 2010)
Log Message:
-----------
new bpy function bpy.path.module_names(path, recursive=False)
addon's and python initialization both had this inline.
Modified Paths:
--------------
trunk/blender/release/scripts/modules/bpy/path.py
trunk/blender/release/scripts/modules/bpy/utils.py
trunk/blender/release/scripts/ui/space_userpref.py
Modified: trunk/blender/release/scripts/modules/bpy/path.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/path.py 2010-09-08 03:34:45 UTC (rev 31821)
+++ trunk/blender/release/scripts/modules/bpy/path.py 2010-09-08 04:55:37 UTC (rev 31822)
@@ -173,3 +173,33 @@
else:
return filepath + ext
+
+
+def module_names(path, recursive=False):
+ """
+ Return a list of modules which can be imported from *path*.
+
+ :arg path: a directory to scan.
+ :type path: string
+ :arg recursive: Also return submodule names for packages.
+ :type recursive: bool
+ :return: a list of strings.
+ :rtype: list
+ """
+
+ from os.path import join, isfile
+
+ modules = []
+
+ for filename in sorted(_os.listdir(path)):
+ if filename.endswith(".py") and filename != "__init__.py":
+ modules.append(filename[0:-3])
+ elif ("." not in filename):
+ directory = join(path, filename)
+ if isfile(join(directory, "__init__.py")):
+ modules.append(filename)
+ if recursive:
+ for mod_name in module_names(directory, True):
+ modules.append("%s.%s" % (filename, mod_name))
+
+ return modules
Modified: trunk/blender/release/scripts/modules/bpy/utils.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/utils.py 2010-09-08 03:34:45 UTC (rev 31821)
+++ trunk/blender/release/scripts/modules/bpy/utils.py 2010-09-08 04:55:37 UTC (rev 31822)
@@ -70,16 +70,8 @@
modules = []
- for f in sorted(_os.listdir(path)):
- if f.endswith(".py"):
- # python module
- mod = _test_import(f[0:-3], loaded_modules)
- elif ("." not in f) and (_os.path.isfile(_os.path.join(path, f, "__init__.py"))):
- # python package
- mod = _test_import(f, loaded_modules)
- else:
- mod = None
-
+ for mod_name in _bpy.path.module_names(path):
+ mod = _test_import(mod_name, loaded_modules)
if mod:
modules.append(mod)
@@ -280,7 +272,7 @@
'''
Returns an SMPTE formatted string from the time in seconds: "HH:MM:SS:FF".
- If the fps is not given the current scene is used.
+ If the *fps* is not given the current scene is used.
'''
import math
@@ -312,7 +304,7 @@
'''
Returns an SMPTE formatted string from the frame: "HH:MM:SS:FF".
- If the fps and fps_base are not given the current scene is used.
+ If *fps* and *fps_base* are not given the current scene is used.
'''
if fps is None:
Modified: trunk/blender/release/scripts/ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/ui/space_userpref.py 2010-09-08 03:34:45 UTC (rev 31821)
+++ trunk/blender/release/scripts/ui/space_userpref.py 2010-09-08 04:55:37 UTC (rev 31822)
@@ -875,32 +875,20 @@
modules_stale = set(USERPREF_PT_addons._addons_fake_modules.keys())
for path in paths:
- for f in sorted(os.listdir(path)):
- if f.endswith(".py"):
- mod_name = f[0:-3]
- mod_path = os.path.join(path, f)
- elif ("." not in f) and (os.path.isfile(os.path.join(path, f, "__init__.py"))):
- mod_name = f
- mod_path = os.path.join(path, f, "__init__.py")
- else:
- mod_name = ""
- mod_path = ""
+ for mod_name in bpy.path.module_names(path):
+ modules_stale -= {mod_name}
+ mod = USERPREF_PT_addons._addons_fake_modules.get(mod_name)
+ if mod:
+ if mod.__time__ != os.path.getmtime(mod_path):
+ print("Reloading", mod_name, mod.__time__, os.path.getmtime(mod_path), mod_path)
+ del USERPREF_PT_addons._addons_fake_modules[mod_name]
+ mod = None
- if mod_name:
- if mod_name in modules_stale:
- modules_stale.remove(mod_name)
- mod = USERPREF_PT_addons._addons_fake_modules.get(mod_name)
+ if mod is None:
+ mod = fake_module(mod_name, mod_path)
if mod:
- if mod.__time__ != os.path.getmtime(mod_path):
- print("Reloading", mod_name)
- del USERPREF_PT_addons._addons_fake_modules[mod_name]
- mod = None
+ USERPREF_PT_addons._addons_fake_modules[mod_name] = mod
- if mod is None:
- mod = fake_module(mod_name, mod_path)
- if mod:
- USERPREF_PT_addons._addons_fake_modules[mod_name] = mod
-
# just incase we get stale modules, not likely
for mod_stale in modules_stale:
del USERPREF_PT_addons._addons_fake_modules[mod_stale]
More information about the Bf-blender-cvs
mailing list