mirror of
https://github.com/blender/blender
synced 2026-09-29 04:37:17 +03:00
PyAPI: add bpy.path.is_autoexec
Expose the excluded paths check used by the file selector's "Trusted Source" option so scripts can match its behavior. Ref !163464
This commit is contained in:
parent
e877ae3863
commit
20ca120140
5 changed files with 80 additions and 5 deletions
|
|
@ -35,6 +35,32 @@ class TestBpyPath(unittest.TestCase):
|
|||
self.assertEqual(ensure_ext('demoBlend', 'blend', case_sensitive=True), 'demoBlendblend')
|
||||
self.assertEqual(ensure_ext('demo', '', case_sensitive=True), 'demo')
|
||||
|
||||
def test_is_autoexec(self):
|
||||
import bpy
|
||||
from bpy.path import is_autoexec
|
||||
|
||||
prefs = bpy.context.preferences
|
||||
|
||||
use_scripts_auto_execute = prefs.filepaths.use_scripts_auto_execute
|
||||
self.addCleanup(setattr, prefs.filepaths, "use_scripts_auto_execute", use_scripts_auto_execute)
|
||||
|
||||
path_cmp = prefs.autoexec_paths.new()
|
||||
self.addCleanup(prefs.autoexec_paths.remove, path_cmp)
|
||||
path_cmp.path = "/untrusted/"
|
||||
|
||||
self.assertFalse(is_autoexec("/untrusted/"))
|
||||
self.assertFalse(is_autoexec(b"/untrusted/"))
|
||||
self.assertTrue(is_autoexec("/trusted/"))
|
||||
|
||||
path_cmp.use_glob = True
|
||||
path_cmp.path = "*/download*"
|
||||
self.assertFalse(is_autoexec("/home/user/downloads/"))
|
||||
self.assertTrue(is_autoexec("/home/user/projects/"))
|
||||
|
||||
# The preference to enable auto-execution isn't taken into account.
|
||||
prefs.filepaths.use_scripts_auto_execute = False
|
||||
self.assertFalse(is_autoexec("/home/user/downloads/"))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue