picodulce-themes/create_repo.py
2024-12-17 07:13:31 +00:00

42 lines
1.3 KiB
Python

import os
import json
# Function to process each JSON file and extract the manifest values
def extract_theme_info(filename):
with open(filename, 'r', encoding='utf-8') as file:
data = json.load(file)
if 'manifest' in data:
manifest = data['manifest']
return {
"name": manifest.get("name", ""),
"description": manifest.get("description", ""),
"author": manifest.get("author", ""),
"license": manifest.get("license", ""),
"link": f"https://git.lupin.com.ar/nix/picodulce-themes/raw/branch/main/{filename}"
}
return None
# List to store theme data
themes = []
# Loop through all files in the current directory
for filename in os.listdir('.'):
if filename.endswith('.json'):
theme_info = extract_theme_info(filename)
if theme_info:
themes.append(theme_info)
# Sort the themes list alphabetically by the 'name' key
themes.sort(key=lambda theme: theme['name'])
# Create the repo.json structure
repo_data = {
"themes": themes
}
# Write to repo.json
with open('repo.json', 'w', encoding='utf-8') as outfile:
json.dump(repo_data, outfile, indent=2)
print("repo.json has been generated and sorted alphabetically.")