| 46 | |
| 47 | |
| 48 | def ensure_roles_file(root_dir: Path = PROJECT_ROOT) -> Path: |
| 49 | data_dir = root_dir / "data" |
| 50 | roles_path = data_dir / "roles.json" |
| 51 | if roles_path.exists(): |
| 52 | return roles_path |
| 53 | |
| 54 | template_path = root_dir / "config" / "roles.example.json" |
| 55 | if template_path.exists(): |
| 56 | shutil.copyfile(template_path, roles_path) |
| 57 | return roles_path |
| 58 | |
| 59 | roles_path.write_text( |
| 60 | json.dumps(DEFAULT_ROLES_TEMPLATE, ensure_ascii=False, indent=2) + "\n", |
| 61 | encoding="utf-8", |
| 62 | ) |
| 63 | return roles_path |
| 64 | |
| 65 | |
| 66 | def _database_has_required_tables(db_path: Path) -> bool: |