Skip to content

Commit

Permalink
🧑‍💻 (hooks): Add activity unique uuid check
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Feb 15, 2024
1 parent c204fb3 commit 411d6d4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,13 @@ repos:
additional_dependencies: ["ruamel.yaml"]
files: .*\.activity\.yml
types: [yaml]

- id: check_yaml_content_activities_unique_uuid
name: Check activity.yml files for unique uuid
description: |
This hook checks activity.yml files for unique uuid
entry: python3 Tools/Hooks/check_yaml_content_activities_unique_uuid.py
language: python
files: .*\.activity\.yml
types: [yaml]
pass_filenames: false
36 changes: 36 additions & 0 deletions Tools/Hooks/check_yaml_content_activities_unique_uuid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/python3

# Leka - LekaOS
# Copyright 2020 APF France handicap
# SPDX-License-Identifier: Apache-2.0

from pathlib import Path
import sys

DIRECTORY_PATH = 'Modules/ContentKit/Resources/Content'

path = Path(DIRECTORY_PATH)
activity_files = path.rglob('*.activity.yml')

uuids_files = {}
duplicates_found = False

for file in activity_files:
uuid = file.name.split('-', 1)[0]
if uuid in uuids_files:
uuids_files[uuid].append(file)
else:
uuids_files[uuid] = [file]

for uuid, files in uuids_files.items():
if len(files) > 1:
duplicates_found = True
print(f"❌ Duplicate UUID: {uuid}")
for file in files:
print(f" - {file}")
print()

if duplicates_found:
sys.exit(1)
else:
sys.exit(0)

0 comments on commit 411d6d4

Please sign in to comment.