am-freescan/scripts/apply_coordinate_management.py

28 lines
1.5 KiB
Python
Raw Normal View History

"""Register the coordinate management entry through the normal menu API. No role grants or device commands."""
import json
from pathlib import Path
from verify_cmvr_native import Client
COMPONENT = 'lab/md/coordinate-system/index'
def apply():
client = Client().login()
rows = client.request('GET', '/admin-api/system/menu/list', expected=(0,))['data']
existing = next((row for row in rows if row.get('component') == COMPONENT), None)
if existing:
assert existing.get('parentId') == 20001 and existing.get('path') == 'coordinate-system', 'Existing menu route differs; do not overwrite'
return {'menuId': existing['id'], 'created': False, 'roleAssignmentsChanged': False}
assert any(row['id'] == 20001 for row in rows), 'Configuration parent menu is missing'
result = client.request('POST', '/admin-api/system/menu/create', body={
'name': '坐标系建立', 'permission': 'resource:device:list', 'type': 2, 'sort': 6,
'parentId': 20001, 'path': 'coordinate-system', 'icon': 'ep:coordinate',
'component': COMPONENT, 'componentName': 'LabCoordinateSystem',
'status': 0, 'visible': True, 'keepAlive': False, 'alwaysShow': True,
}, expected=(0,))
return {'menuId': result['data'], 'created': True, 'roleAssignmentsChanged': False}
if __name__ == '__main__':
report = apply()
(Path(__file__).resolve().parents[1] / '.local/coordinate-management-menu.json').write_text(json.dumps(report, indent=2), encoding='utf-8')
print(json.dumps(report))