library.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from pathlib import Path
  2. import subprocess
  3. import logging
  4. logger = logging.getLogger(__name__)
  5. class Library:
  6. """Represents a single library with a specific path."""
  7. def __init__(self, name: str, path: Path, priority: int = 0):
  8. self.name = name
  9. self.path = path
  10. self.priority = priority # Higher priority = checked first
  11. def find_by_id(self, module_name, files, template_id):
  12. """Find a template by its ID in this library."""
  13. pass
  14. def find(self, module_name, files, sorted=False):
  15. """Find templates in this library for a specific module."""
  16. pass
  17. class LibraryManager:
  18. """Manages multiple libraries and provides methods to find templates."""
  19. # FIXME: For now this is static and only has one library
  20. def __init__(self):
  21. self.libraries = [
  22. Library(name="default", path=Path(__file__).parent.parent / "libraries", priority=0)
  23. ]
  24. def find_by_id(self, module_name, files, template_id):
  25. """Find a template by its ID across all libraries."""
  26. for library in self.libraries:
  27. template = library.find_by_id(module_name, files, template_id)
  28. if template:
  29. return template
  30. def find(self, module_name, files, sorted=False):
  31. """Find templates across all libraries for a specific module."""
  32. for library in self.libraries:
  33. templates = library.find(module_name, files, sorted=sorted)
  34. if templates:
  35. return templates
  36. return []