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>2013-04-05 04:30:32 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-04-05 04:30:32 +0400
commit98752a1f3025a138b5a2f70f60a2cca1e89d2f66 (patch)
tree9d6adf01f7fa74d7e995675ff466532167d8ba49 /release/scripts/modules/bpy/path.py
parentdee2f0c9ac8312ff71241d86591adb8f9b06c53a (diff)
py api additions needed for fixing [#34864].
- add rna property 'as_bytes' method so you can get a string property as python bytes (bypass encoding). - make bpy.path.abspath/relpath compatible with bytes. - add 'relpath' option to bpy_extras.image_utils.load_image(), so you can load an image relative to a path.
Diffstat (limited to 'release/scripts/modules/bpy/path.py')
-rw-r--r--release/scripts/modules/bpy/path.py41
1 files changed, 30 insertions, 11 deletions
diff --git a/release/scripts/modules/bpy/path.py b/release/scripts/modules/bpy/path.py
index 6c91568cbc1..cfc0f474215 100644
--- a/release/scripts/modules/bpy/path.py
+++ b/release/scripts/modules/bpy/path.py
@@ -48,6 +48,10 @@ from _bpy_path import (extensions_audio,
)
+def _getattr_bytes(var, attr):
+ return var.path_resolve(attr, False).as_bytes()
+
+
def abspath(path, start=None, library=None):
"""
Returns the absolute path relative to the current blend file
@@ -60,13 +64,22 @@ def abspath(path, start=None, library=None):
convenience, when the library is not None its path replaces *start*.
:type library: :class:`bpy.types.Library`
"""
- if path.startswith("//"):
- if library:
- start = _os.path.dirname(abspath(library.filepath))
- return _os.path.join(_os.path.dirname(_bpy.data.filepath)
- if start is None else start,
- path[2:],
- )
+ if isinstance(path, bytes):
+ if path.startswith(b"//"):
+ if library:
+ start = _os.path.dirname(abspath(_getattr_bytes(library, "filepath")))
+ return _os.path.join(_os.path.dirname(_getattr_bytes(_bpy.data, "filepath"))
+ if start is None else start,
+ path[2:],
+ )
+ else:
+ if path.startswith("//"):
+ if library:
+ start = _os.path.dirname(abspath(library.filepath))
+ return _os.path.join(_os.path.dirname(_bpy.data.filepath)
+ if start is None else start,
+ path[2:],
+ )
return path
@@ -79,10 +92,16 @@ def relpath(path, start=None):
when not set the current filename is used.
:type start: string
"""
- if not path.startswith("//"):
- if start is None:
- start = _os.path.dirname(_bpy.data.filepath)
- return "//" + _os.path.relpath(path, start)
+ if isinstance(path, bytes):
+ if not path.startswith(b"//"):
+ if start is None:
+ start = _os.path.dirname(_getattr_bytes(_bpy.data, "filepath"))
+ return b"//" + _os.path.relpath(path, start)
+ else:
+ if not path.startswith("//"):
+ if start is None:
+ start = _os.path.dirname(_bpy.data.filepath)
+ return "//" + _os.path.relpath(path, start)
return path