| 297 | self.config.includes_resolved = resolved |
| 298 | |
| 299 | def _backup_file(self) -> None: |
| 300 | ts = datetime.now().strftime("%Y%m%d-%H%M%S") |
| 301 | if self.backup_dir: |
| 302 | target_dir = Path(self.backup_dir).expanduser() |
| 303 | else: |
| 304 | target_dir = self.config_path.parent |
| 305 | try: |
| 306 | target_dir.mkdir(parents=True, exist_ok=True) |
| 307 | except Exception: |
| 308 | target_dir = self.config_path.parent |
| 309 | backup = (target_dir / self.config_path.name).with_suffix(f".{ts}.bak") |
| 310 | try: |
| 311 | shutil.copy2(self.config_path, backup) |
| 312 | logger.info("Backup created: %s", backup) |
| 313 | except Exception as e: |
| 314 | logger.warning("Failed to create backup: %s", e) |
| 315 | |
| 316 | def _generate_content(self) -> str: |
| 317 | lines: List[str] = [] |