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:
Diffstat (limited to 'release/scripts/modules/bpy/path.py')
-rw-r--r--release/scripts/modules/bpy/path.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/release/scripts/modules/bpy/path.py b/release/scripts/modules/bpy/path.py
index 92d2533c2c1..9a29b713882 100644
--- a/release/scripts/modules/bpy/path.py
+++ b/release/scripts/modules/bpy/path.py
@@ -27,12 +27,15 @@ import bpy as _bpy
import os as _os
-def abspath(path):
+def abspath(path, start=None):
"""
Returns the absolute path relative to the current blend file using the "//" prefix.
+
+ :arg start: Relative to this path, when not set the current filename is used.
+ :type start: string
"""
if path.startswith("//"):
- return _os.path.join(_os.path.dirname(_bpy.data.filepath), path[2:])
+ return _os.path.join(_os.path.dirname(_bpy.data.filepath if start is None else start), path[2:])
return path
@@ -52,6 +55,17 @@ def relpath(path, start=None):
return path
+def is_subdir(path, directory):
+ """
+ Returns true if *path* in a subdirectory of *directory*.
+ Both paths must be absolute.
+ """
+ from os.path import normpath, normcase
+ path = normpath(normcase(path))
+ directory = normpath(normcase(directory))
+ return path.startswith(directory)
+
+
def clean_name(name, replace="_"):
"""
Returns a name with characters replaced that may cause problems under various circumstances, such as writing to a file.
@@ -99,6 +113,13 @@ def display_name(name):
return name_base
+def display_name_from_filepath(name):
+ """
+ Returns the path stripped of directort and extension, ensured to be utf8 compatible.
+ """
+ return _os.path.splitext(_os.path.basename(name))[0].encode("utf8", "replace").decode("utf8")
+
+
def resolve_ncase(path):
"""
Resolve a case insensitive path on a case sensitive system,
@@ -108,7 +129,7 @@ def resolve_ncase(path):
import os
def _ncase_path_found(path):
- if path == "" or os.path.exists(path):
+ if not path or os.path.exists(path):
return path, True
filename = os.path.basename(path) # filename may be a directory or a file
@@ -192,7 +213,9 @@ def module_names(path, recursive=False):
modules = []
for filename in sorted(_os.listdir(path)):
- if filename.endswith(".py") and filename != "__init__.py":
+ if filename == "modules":
+ pass # XXX, hard coded exception.
+ elif filename.endswith(".py") and filename != "__init__.py":
fullpath = join(path, filename)
modules.append((filename[0:-3], fullpath))
elif ("." not in filename):