scense_demo/scripts/load_path.py

68 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
# -*- coding: utf-8 -*-
"""demo 模块 RBAC 注册脚本(显式路径,禁止通配符)。
用法: cd <sage_root> && ./py3/bin/python <module>/scripts/load_path.py
兜底: 中央 ~/repos/sage/load_path.py 亦需登记以下路径(双保险)。
"""
import os
import sys
SAGE_ROOT = None
for candidate in (
os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..'),
os.path.expanduser('~/repos/sage'),
os.path.expanduser('~/sage')):
cand = os.path.abspath(candidate)
if os.path.isdir(os.path.join(cand, 'wwwroot')) and os.path.isdir(os.path.join(cand, 'py3', 'bin')):
SAGE_ROOT = cand
break
if SAGE_ROOT is None:
print('未找到 Sage 根目录,跳过 RBAC 注册(部署时由中央 load_path.py 兜底)')
sys.exit(0)
sys.path.insert(0, os.path.join(SAGE_ROOT, 'py3', 'bin'))
from set_role_perm import set_role_perm # noqa: E402
PATHS_LOGINED = [
# 模块入口
'/scense_demo',
'/scense_demo/index.ui',
# 演示控制台(前端页面 + js/css
'/scense_demo/demo_viewer.ui',
'/scense_demo/demo_viewer.js',
'/scense_demo/demo_viewer.css',
# CRUD 会话列表xls2ui 生成的 5 件套)
'/scense_demo/demo_session',
'/scense_demo/demo_session/index.ui',
'/scense_demo/demo_session/get_demo_session.dspy',
'/scense_demo/demo_session/add_demo_session.dspy',
'/scense_demo/demo_session/update_demo_session.dspy',
'/scense_demo/demo_session/delete_demo_session.dspy',
# 业务 API
'/scense_demo/api/start.dspy',
'/scense_demo/api/stop.dspy',
'/scense_demo/api/camera.dspy',
'/scense_demo/api/pause.dspy',
'/scense_demo/api/entity_edit.dspy',
'/scense_demo/api/entity_attrs.dspy',
'/scense_demo/api/hotload.dspy',
'/scense_demo/api/presence.dspy',
'/scense_demo/api/fullscreen.dspy',
'/scense_demo/api/state.dspy',
'/scense_demo/api/session_create.dspy',
'/scense_demo/api/session_update.dspy',
'/scense_demo/api/session_delete.dspy',
]
def main():
for p in PATHS_LOGINED:
set_role_perm(p, 'logined')
print('demo RBAC 注册完成: %d 条 logined 路径' % len(PATHS_LOGINED))
if __name__ == '__main__':
main()