85 lines
2.2 KiB
Python
85 lines
2.2 KiB
Python
"""Discover projects from the build-public-docs.sh configuration."""
|
|
|
|
import re
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
|
|
@dataclass
|
|
class Project:
|
|
"""Represents a project in the development ecosystem."""
|
|
|
|
key: str
|
|
title: str
|
|
tagline: str
|
|
owner: str
|
|
repo: str
|
|
dirname: str
|
|
|
|
@property
|
|
def path(self) -> Path:
|
|
"""Local path to project directory."""
|
|
return Path.home() / "PycharmProjects" / self.dirname
|
|
|
|
@property
|
|
def gitea_url(self) -> str:
|
|
"""URL to Gitea repository."""
|
|
return f"https://gitea.brrd.tech/{self.owner}/{self.repo}"
|
|
|
|
@property
|
|
def docs_url(self) -> str:
|
|
"""URL to public documentation."""
|
|
return f"https://pages.brrd.tech/{self.owner}/{self.repo}/"
|
|
|
|
@property
|
|
def exists(self) -> bool:
|
|
"""Check if project directory exists locally."""
|
|
return self.path.exists()
|
|
|
|
|
|
def discover_projects() -> list[Project]:
|
|
"""Parse PROJECT_CONFIG from build-public-docs.sh.
|
|
|
|
Returns:
|
|
List of Project objects discovered from the build script.
|
|
"""
|
|
build_script = Path.home() / "PycharmProjects/project-docs/scripts/build-public-docs.sh"
|
|
|
|
if not build_script.exists():
|
|
return []
|
|
|
|
projects = []
|
|
# Pattern: PROJECT_CONFIG["key"]="Title|Tagline|Owner|Repo|DirName"
|
|
pattern = r'PROJECT_CONFIG\["([^"]+)"\]="([^|]+)\|([^|]+)\|([^|]+)\|([^|]+)\|([^"]+)"'
|
|
|
|
for match in re.finditer(pattern, build_script.read_text()):
|
|
key, title, tagline, owner, repo, dirname = match.groups()
|
|
projects.append(Project(
|
|
key=key,
|
|
title=title,
|
|
tagline=tagline,
|
|
owner=owner,
|
|
repo=repo,
|
|
dirname=dirname,
|
|
))
|
|
|
|
# Sort by title for consistent display
|
|
projects.sort(key=lambda p: p.title.lower())
|
|
|
|
return projects
|
|
|
|
|
|
def get_project_by_key(key: str) -> Project | None:
|
|
"""Get a specific project by its key.
|
|
|
|
Args:
|
|
key: The project key (e.g., 'cmdforge', 'ramble')
|
|
|
|
Returns:
|
|
Project object if found, None otherwise.
|
|
"""
|
|
for project in discover_projects():
|
|
if project.key == key:
|
|
return project
|
|
return None
|