world_snapshot/scripts/load_path.py

58 lines
1.6 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 -*-
"""world_snapshot 模块 RBAC 权限注册脚本W-04"""
import os
import sys
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
SAGE_ROOT = None
for cand in (os.path.join(SCRIPT_DIR, '..', '..', '..'),
os.path.expanduser('~/repos/sage'),
os.path.expanduser('~/sage')):
cand = os.path.abspath(cand)
if os.path.isdir(os.path.join(cand, 'wwwroot')) and os.path.isdir(os.path.join(cand, 'py3', 'bin')):
SAGE_ROOT = cand
break
if not SAGE_ROOT:
print('ERROR: sage root not found, skip RBAC registration')
sys.exit(0)
sys.path.insert(0, os.path.join(SAGE_ROOT, 'py3', 'bin'))
sys.path.insert(0, os.path.join(SAGE_ROOT))
try:
from set_role_perm import set_role_perm # noqa: E402
except Exception as e: # noqa: BLE001
print(f'ERROR: cannot import set_role_perm: {e}')
sys.exit(0)
MOD = 'world_snapshot'
PATHS_LOGINED = [
f'/{MOD}',
f'/{MOD}/index.ui',
f'/{MOD}/api/snapshot_create.dspy',
f'/{MOD}/api/snapshot_get.dspy',
f'/{MOD}/api/snapshot_list.dspy',
f'/{MOD}/api/snapshot_update.dspy',
f'/{MOD}/api/snapshot_delete.dspy',
f'/{MOD}/api/snapshot_restore.dspy',
f'/{MOD}/api/snapshot_types.dspy',
f'/{MOD}/api/snapshot_statuses.dspy',
f'/{MOD}/api/snapshot_worlds.dspy',
]
def main():
for path in PATHS_LOGINED:
try:
set_role_perm(path, 'logined')
print(f'OK {path} -> logined')
except Exception as e: # noqa: BLE001
print(f'ERR {path}: {e}')
print('world_snapshot RBAC registration done')
if __name__ == '__main__':
main()