|
16 | 16 |
|
17 | 17 | # Paths to the files that need to be checked |
18 | 18 | README_PATH = "README.adoc" |
19 | | -GUIDE_PATH = "guide.adoc" |
20 | 19 | NAV_PATH = "antora/modules/ROOT/nav.adoc" |
21 | 20 |
|
22 | 21 | # Directories to scan for chapter files |
@@ -96,31 +95,6 @@ def check_readme_references(chapter_files): |
96 | 95 | print(f"Error checking README.adoc: {e}") |
97 | 96 | return list(chapter_files.values()) |
98 | 97 |
|
99 | | -def check_guide_references(chapter_files): |
100 | | - """ |
101 | | - Check if all chapter files are referenced in guide.adoc. |
102 | | - Returns a list of files that are not referenced. |
103 | | - """ |
104 | | - try: |
105 | | - with open(GUIDE_PATH, 'r', encoding='utf-8') as f: |
106 | | - guide_content = f.read() |
107 | | - |
108 | | - missing_files = [] |
109 | | - for file_path, info in chapter_files.items(): |
110 | | - # Convert path to the format used in guide.adoc |
111 | | - rel_path = file_path.replace(CHAPTERS_DIR + "/", "") |
112 | | - |
113 | | - # Check if the file is referenced in guide.adoc |
114 | | - # The pattern needs to match both include:{chapters}file.adoc[] and include::{chapters}file.adoc[] |
115 | | - if not (re.search(rf'include:\{{chapters\}}{re.escape(rel_path)}', guide_content) or |
116 | | - re.search(rf'include::\{{chapters\}}{re.escape(rel_path)}', guide_content)): |
117 | | - missing_files.append(info) |
118 | | - |
119 | | - return missing_files |
120 | | - except Exception as e: |
121 | | - print(f"Error checking guide.adoc: {e}") |
122 | | - return list(chapter_files.values()) |
123 | | - |
124 | 98 | def check_nav_references(chapter_files): |
125 | 99 | """ |
126 | 100 | Check if all chapter files are referenced in nav.adoc. |
@@ -193,54 +167,6 @@ def update_readme(missing_files): |
193 | 167 | print(f"Error updating README.adoc: {e}") |
194 | 168 | return False |
195 | 169 |
|
196 | | -def update_guide(missing_files): |
197 | | - """ |
198 | | - Update guide.adoc to include missing chapter references. |
199 | | - Returns True if the file was updated, False otherwise. |
200 | | - """ |
201 | | - if not missing_files: |
202 | | - return False |
203 | | - |
204 | | - try: |
205 | | - with open(GUIDE_PATH, 'r', encoding='utf-8') as f: |
206 | | - content = f.readlines() |
207 | | - |
208 | | - # Find appropriate sections to add the missing files |
209 | | - extensions_section_idx = None |
210 | | - main_section_idx = None |
211 | | - |
212 | | - for i, line in enumerate(content): |
213 | | - if "= When and Why to use Extensions" in line: |
214 | | - extensions_section_idx = i |
215 | | - elif "= Using Vulkan" in line: |
216 | | - main_section_idx = i |
217 | | - |
218 | | - if extensions_section_idx is None or main_section_idx is None: |
219 | | - print("Could not find appropriate sections in guide.adoc") |
220 | | - return False |
221 | | - |
222 | | - # Add missing files to appropriate sections |
223 | | - for file_info in missing_files: |
224 | | - rel_path = file_info["path"].replace(CHAPTERS_DIR + "/", "") |
225 | | - |
226 | | - if file_info["is_extension"]: |
227 | | - # Add to extensions section |
228 | | - content.insert(extensions_section_idx + 2, f"include::{{chapters}}{rel_path}[]\n\n") |
229 | | - extensions_section_idx += 2 # Adjust index for next insertion |
230 | | - else: |
231 | | - # Add to main section |
232 | | - content.insert(main_section_idx + 2, f"include::{{chapters}}{rel_path}[]\n\n") |
233 | | - main_section_idx += 2 # Adjust index for next insertion |
234 | | - |
235 | | - # Write updated content back to file |
236 | | - with open(GUIDE_PATH, 'w', encoding='utf-8') as f: |
237 | | - f.writelines(content) |
238 | | - |
239 | | - return True |
240 | | - except Exception as e: |
241 | | - print(f"Error updating guide.adoc: {e}") |
242 | | - return False |
243 | | - |
244 | 170 | def update_nav(missing_files): |
245 | 171 | """ |
246 | 172 | Update nav.adoc to include missing chapter references. |
@@ -301,27 +227,22 @@ def main(): |
301 | 227 |
|
302 | 228 | # Check if all chapter files are referenced in the three files |
303 | 229 | readme_missing = check_readme_references(chapter_files) |
304 | | - guide_missing = check_guide_references(chapter_files) |
305 | 230 | nav_missing = check_nav_references(chapter_files) |
306 | 231 |
|
307 | 232 | print(f"Missing from README.adoc: {len(readme_missing)}") |
308 | | - print(f"Missing from guide.adoc: {len(guide_missing)}") |
309 | 233 | print(f"Missing from nav.adoc: {len(nav_missing)}") |
310 | 234 |
|
311 | 235 | # Update files if needed |
312 | 236 | readme_updated = update_readme(readme_missing) |
313 | | - guide_updated = update_guide(guide_missing) |
314 | 237 | nav_updated = update_nav(nav_missing) |
315 | 238 |
|
316 | 239 | if readme_updated: |
317 | 240 | print("Updated README.adoc") |
318 | | - if guide_updated: |
319 | | - print("Updated guide.adoc") |
320 | 241 | if nav_updated: |
321 | 242 | print("Updated nav.adoc") |
322 | 243 |
|
323 | 244 | # Return non-zero exit code if any files were missing references |
324 | | - if readme_missing or guide_missing or nav_missing: |
| 245 | + if readme_missing or nav_missing: |
325 | 246 | print("Some chapter files were missing references and have been added.") |
326 | 247 | return 1 |
327 | 248 | else: |
|
0 commit comments