scene/scripts/load_path.py
2026-08-29 12:44:22 +08:00

76 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""scene 模块 RBAC 路径注册(无通配符,全显式路径)。
用法python load_path.py (在 Sage/宿主应用根目录执行,自动探测)。
"""
import os
import sys
def find_sage_root():
for candidate in (
os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", ".."),
os.path.expanduser("~/repos/sage"),
os.path.expanduser("~/sage"),
):
c = os.path.abspath(candidate)
if os.path.isdir(os.path.join(c, "wwwroot")) and os.path.isdir(os.path.join(c, "py3", "bin")):
return c
return None
SAGE_ROOT = find_sage_root()
if not SAGE_ROOT:
print("WARN: 未找到 Sage 根目录,跳过 RBAC 注册(请手动在宿主 load_path.py 注册以下路径)")
SAGE_ROOT = os.path.expanduser("~/repos/sage")
sys.path.insert(0, os.path.join(SAGE_ROOT, "scripts"))
sys.path.insert(0, os.path.join(SAGE_ROOT, "py3", "bin"))
PATHS_ANY = [
"/scene",
"/scene/index.ui",
"/scene/import_page.ui",
]
PATHS_LOGINED = [
"/scene/scene_list",
"/scene/scene_list/index.ui",
"/scene/scene_list/get_scene_list.dspy",
"/scene/scene_list/add_scene_list.dspy",
"/scene/scene_list/update_scene_list.dspy",
"/scene/scene_list/delete_scene_list.dspy",
"/scene/scene_import_list",
"/scene/scene_import_list/index.ui",
"/scene/scene_import_list/get_scene_import_list.dspy",
"/scene/api/list_scenes.dspy",
"/scene/api/get_scene.dspy",
"/scene/api/create_scene.dspy",
"/scene/api/scene_update.dspy",
"/scene/api/scene_delete.dspy",
"/scene/api/scene_import.dspy",
"/scene/api/get_search_world_id.dspy",
"/scene/api/get_search_scene_type.dspy",
"/scene/api/get_search_status.dspy",
]
def main():
try:
from set_role_perm import set_role_perm
except Exception as e:
print(f"ERROR: 无法导入 set_role_perm: {e}")
sys.exit(1)
for path in PATHS_ANY:
set_role_perm(path, "any")
print(f"any {path}")
for path in PATHS_LOGINED:
set_role_perm(path, "logined")
print(f"logined {path}")
print("scene RBAC 注册完成")
if __name__ == "__main__":
main()