diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-09-08 08:55:37 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-09-08 08:55:37 +0400 |
commit | 1a41d2fc2938710fe2673bae9702a534f7f94d58 (patch) | |
tree | 807507648fcad7e1d3a8e0febf9717662a0e87b1 /release/scripts | |
parent | 5b428e9158c3990eed82b89d260f1f9b576cdf8f (diff) |
new bpy function bpy.path.module_names(path, recursive=False)
addon's and python initialization both had this inline.
Diffstat (limited to 'release/scripts')
-rw-r--r-- | release/scripts/modules/bpy/path.py | 30 | ||||
-rw-r--r-- | release/scripts/modules/bpy/utils.py | 16 | ||||
-rw-r--r-- | release/scripts/ui/space_userpref.py | 36 |
3 files changed, 46 insertions, 36 deletions
diff --git a/release/scripts/modules/bpy/path.py b/release/scripts/modules/bpy/path.py index 423fdb7aaab..714a3a07f95 100644 --- a/release/scripts/modules/bpy/path.py +++ b/release/scripts/modules/bpy/path.py @@ -173,3 +173,33 @@ def ensure_ext(filepath, ext, case_sensitive=False): 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 diff --git a/release/scripts/modules/bpy/utils.py b/release/scripts/modules/bpy/utils.py index 21453f06648..9b0c758404e 100644 --- a/release/scripts/modules/bpy/utils.py +++ b/release/scripts/modules/bpy/utils.py @@ -70,16 +70,8 @@ def modules_from_path(path, loaded_modules): 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 @@ def smpte_from_seconds(time, fps=None): ''' 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 @@ def smpte_from_frame(frame, fps=None, fps_base=None): ''' 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: diff --git a/release/scripts/ui/space_userpref.py b/release/scripts/ui/space_userpref.py index 4b87248d1f9..435384708c5 100644 --- a/release/scripts/ui/space_userpref.py +++ b/release/scripts/ui/space_userpref.py @@ -875,31 +875,19 @@ class USERPREF_PT_addons(bpy.types.Panel): 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 = "" - - if mod_name: - if mod_name in modules_stale: - modules_stale.remove(mod_name) - mod = USERPREF_PT_addons._addons_fake_modules.get(mod_name) + 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 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 - - if mod is None: - mod = fake_module(mod_name, mod_path) - if mod: - USERPREF_PT_addons._addons_fake_modules[mod_name] = mod + USERPREF_PT_addons._addons_fake_modules[mod_name] = mod # just incase we get stale modules, not likely for mod_stale in modules_stale: |