Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-09-08 08:55:37 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-09-08 08:55:37 +0400
commit1a41d2fc2938710fe2673bae9702a534f7f94d58 (patch)
tree807507648fcad7e1d3a8e0febf9717662a0e87b1 /release/scripts/modules/bpy/path.py
parent5b428e9158c3990eed82b89d260f1f9b576cdf8f (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/modules/bpy/path.py')
-rw-r--r--release/scripts/modules/bpy/path.py30
1 files changed, 30 insertions, 0 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