MCPcopy
hub / github.com/ChristianLempa/boilerplates / find

Method find

cli/core/library.py:111–162  ·  view source on GitHub ↗

Find templates in this library for a specific module. Excludes templates marked as draft. Args: module_name: The module name (e.g., 'compose', 'terraform') sort_results: Whether to return results sorted alphabetically Returns: List of Pa

(self, module_name: str, sort_results: bool = False)

Source from the content-addressed store, hash-verified

109 raise TemplateNotFoundError(template_id, module_name)
110
111 def find(self, module_name: str, sort_results: bool = False) -> list[tuple[Path, str]]:
112 """Find templates in this library for a specific module.
113
114 Excludes templates marked as draft.
115
116 Args:
117 module_name: The module name (e.g., 'compose', 'terraform')
118 sort_results: Whether to return results sorted alphabetically
119
120 Returns:
121 List of Path objects representing template directories (excluding drafts)
122
123 Raises:
124 FileNotFoundError: If the module directory is not found in this library
125 """
126 logger.debug(f"Looking for templates in module '{module_name}' in library '{self.name}'")
127
128 # Build the path to the module directory
129 module_path = self.path / module_name
130
131 # Check if the module directory exists
132 if not module_path.is_dir():
133 raise LibraryError(f"Module '{module_name}' not found in library '{self.name}'")
134
135 # Track seen IDs to detect duplicates within this library
136 seen_ids = {}
137 template_dirs = []
138 try:
139 for item in module_path.iterdir():
140 has_template = self._has_template_manifest(item)
141 if has_template and not self._is_template_draft(item):
142 template_id = self._load_template_id(item)
143
144 # Check for duplicate within same library
145 if template_id in seen_ids:
146 raise DuplicateTemplateError(template_id, self.name)
147
148 seen_ids[template_id] = True
149 template_dirs.append((item, self.name))
150 elif has_template:
151 logger.debug(f"Skipping draft template: {item.name}")
152 except PermissionError as e:
153 raise LibraryError(
154 f"Permission denied accessing module '{module_name}' in library '{self.name}': {e}"
155 ) from e
156
157 # Sort if requested
158 if sort_results:
159 template_dirs.sort(key=lambda x: x[0].name.lower())
160
161 logger.debug(f"Found {len(template_dirs)} templates in module '{module_name}'")
162 return template_dirs
163
164
165class LibraryManager:

Callers 3

findMethod · 0.45
_load_all_templatesMethod · 0.45

Calls 5

_is_template_draftMethod · 0.95
_load_template_idMethod · 0.95
LibraryErrorClass · 0.85