diff options
Diffstat (limited to 'release/scripts/modules/bpy/utils/__init__.py')
-rw-r--r-- | release/scripts/modules/bpy/utils/__init__.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py index 04aaa7bd69d..abe33b0e8ea 100644 --- a/release/scripts/modules/bpy/utils/__init__.py +++ b/release/scripts/modules/bpy/utils/__init__.py @@ -457,6 +457,41 @@ def preset_paths(subdir): return dirs +def is_path_builtin(path): + """ + Returns True if the path is one of the built-in paths used by Blender. + + :arg path: Path you want to check if it is in the built-in settings directory + :type path: str + :rtype: bool + """ + # Note that this function is is not optimized for speed, + # it's intended to be used to check if it's OK to remove presets. + # + # If this is used in a draw-loop for example, we could cache some of the values. + user_path = resource_path('USER') + + for res in ('SYSTEM', 'LOCAL'): + parent_path = resource_path(res) + if not parent_path or parent_path == user_path: + # Make sure that the current path is not empty string and that it is + # not the same as the user config path. IE "~/.config/blender" on Linux + # This can happen on portable installs. + continue + + try: + if _os.path.samefile( + _os.path.commonpath([parent_path]), + _os.path.commonpath([parent_path, path]) + ): + return True + except FileNotFoundError: + #The path we tried to look up doesn't exist + pass + + return False + + def smpte_from_seconds(time, fps=None, fps_base=None): """ Returns an SMPTE formatted string from the *time*: |