get_parent_pksk_from_path utils function

This commit is contained in:
simonwt 2026-04-01 22:14:57 +01:00
parent 4f14965ba1
commit 010d54bc87
3 changed files with 18 additions and 15 deletions

1
utils/__init__.py Normal file
View file

@ -0,0 +1 @@
from .get_parent_pksk_from_path import get_parent_pksk_from_path

View file

@ -0,0 +1,14 @@
def get_parent_pksk_from_path(parent_path):
if parent_path == '/':
return 'maintrunk#maintrunk'
entity, slug = parent_path.strip('/').split('/')
if entity == 'branch':
entity = 'subwiki'
elif entity != 'user':
entity = 'userprofile'
if entity not in ['userprofile', 'subwiki']:
raise ValueError(f"Invalid parent entity: {entity}. Must be 'userprofile' or 'branch'.")
return f"{entity}#{slug}"