from pathlib import PurePosixPath KINDS = ('palabras', 'silabas', 'oraciones', 'cuentos') def testing(data, collection): return any(c['id'] == collection and (c.get('is_test') or c['name'].casefold().startswith('prueba')) for c in data['collections']) def folder(data, collection, kind): if data.get('storage_layout') == 'types': return f'pruebas/{kind}/{collection}' if testing(data, collection) else kind return f'v1/colecciones/{collection}/{kind}' def manifests(data): if data.get('storage_layout') != 'types': return {} groups = {kind: [] for kind in KINDS} groups.update({f'pruebas/{kind}': [] for kind in KINDS}) for record in data['recordings']: item = data['items'][record['item_id']] target = f"pruebas/{item['kind']}" if testing(data, record['collection']) else item['kind'] groups[target].append(dict(record, file_name=PurePosixPath(record['path']).name, word_id=item['id'], dataset='pruebas' if testing(data, record['collection']) else item['kind'])) return {f'{path}/manifest.json': records for path, records in groups.items()}