#!/usr/bin/env python3 # -*- coding: utf-8 -*- """world 模块 RBAC 路径注册脚本(显式注册,禁通配符)。 包含全部新 API/页面路径:wwwroot/index.ui、menu.ui 及 wwwroot/api/*.dspy。 角色:logined(需登录);menu.ui 为 any(预登录资源)。 执行:python scripts/load_path.py """ import os import sys MOD = 'world' # 显式路径注册(禁止 % / * 通配符) PATHS_LOGINED = [ '/world', '/world/index.ui', '/world/menu.ui', '/world/world_list', '/world/world_list/index.ui', '/world/world_list/get_world_list.dspy', '/world/world_list/add_world.dspy', '/world/world_list/update_world.dspy', '/world/world_list/delete_world.dspy', '/world/api/create_world.dspy', '/world/api/world_update.dspy', '/world/api/world_delete.dspy', '/world/api/get_world.dspy', '/world/api/list_worlds.dspy', '/world/api/set_world_mode.dspy', '/world/api/get_search_status.dspy', '/world/api/get_search_world_type.dspy', ] PATHS_ANY = [ '/world/menu.ui', ] def find_sage_root(): candidates = [ os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')), os.path.expanduser('~/repos/sage'), os.path.expanduser('~/sage'), ] for cand in candidates: if os.path.isdir(os.path.join(cand, 'wwwroot')) and os.path.isdir(os.path.join(cand, 'py3', 'bin')): return cand return None def main(): sage_root = find_sage_root() if not sage_root: print('ERROR: sage root not found; register paths manually in central load_path.py') sys.exit(1) sys.path.insert(0, os.path.join(sage_root, 'py3', 'bin')) try: from load_path import register_paths # noqa except ImportError: # 中央 load_path.py 未提供可导入函数时,输出待注册清单供人工接入 print('INFO: central load_path.py has no importable register_paths; ' 'falling back to central registration file (see sage/load_path.py)') register_paths = None if register_paths is not None: for p in PATHS_ANY: register_paths(p, 'any') for p in PATHS_LOGINED: register_paths(p, 'logined') print('world RBAC paths registered: %d logined, %d any' % (len(PATHS_LOGINED), len(PATHS_ANY))) else: print('world RBAC paths (register in sage/load_path.py):') for p in PATHS_LOGINED: print(' %s logined' % p) for p in PATHS_ANY: print(' %s any' % p) if __name__ == '__main__': main()