73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""world_snapshot RBAC registration (per-module load_path.py).
|
|
|
|
Explicit paths only - no wildcards. Runs against the Sage root's
|
|
set_role_perm.py via the central load_path.py code path.
|
|
"""
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def find_sage_root():
|
|
here = os.path.dirname(os.path.abspath(__file__))
|
|
for cand in (os.path.join(here, '..', '..', '..'),
|
|
os.path.join(os.path.expanduser('~'), 'repos', 'sage'),
|
|
os.path.join(os.path.expanduser('~'), 'sage')):
|
|
cand = os.path.normpath(cand)
|
|
if os.path.isdir(os.path.join(cand, 'wwwroot')) and os.path.isdir(os.path.join(cand, 'py3', 'bin')):
|
|
return cand
|
|
return None
|
|
|
|
|
|
PATHS_ANY = [
|
|
'/world_snapshot/menu.ui',
|
|
'/world_snapshot/index.ui',
|
|
]
|
|
|
|
PATHS_LOGINED = [
|
|
'/world_snapshot/api/create_snapshot.dspy',
|
|
'/world_snapshot/api/snapshot_update.dspy',
|
|
'/world_snapshot/api/snapshot_delete.dspy',
|
|
'/world_snapshot/api/get_snapshot.dspy',
|
|
'/world_snapshot/api/list_snapshots.dspy',
|
|
'/world_snapshot/api/restore_snapshot.dspy',
|
|
'/world_snapshot/api/get_search_world.dspy',
|
|
'/world_snapshot/api/get_search_snapshot_type.dspy',
|
|
'/world_snapshot/api/get_search_status.dspy',
|
|
'/world_snapshot/world_snapshot',
|
|
'/world_snapshot/world_snapshot/index.ui',
|
|
'/world_snapshot/world_snapshot/get_world_snapshot.dspy',
|
|
'/world_snapshot/world_snapshot/add_world_snapshot.dspy',
|
|
'/world_snapshot/world_snapshot/update_world_snapshot.dspy',
|
|
'/world_snapshot/world_snapshot/delete_world_snapshot.dspy',
|
|
]
|
|
|
|
|
|
def main():
|
|
sage_root = find_sage_root()
|
|
if not sage_root:
|
|
print('world_snapshot load_path.py: sage root not found, skip', file=sys.stderr)
|
|
return 1
|
|
loader = os.path.join(sage_root, 'load_path.py')
|
|
if not os.path.isfile(loader):
|
|
print('world_snapshot load_path.py: central load_path.py not found, skip', file=sys.stderr)
|
|
return 1
|
|
entries = []
|
|
for p in PATHS_ANY:
|
|
entries.append((p, 'any'))
|
|
for p in PATHS_LOGINED:
|
|
entries.append((p, 'logined'))
|
|
payload = '\n'.join('{} {}'.format(p, role) for p, role in entries)
|
|
proc = subprocess.run([sys.executable, loader, payload], capture_output=True, text=True)
|
|
if proc.stdout:
|
|
print(proc.stdout)
|
|
if proc.stderr:
|
|
print(proc.stderr, file=sys.stderr)
|
|
return proc.returncode
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|