Check if output directory is writable. Args: output_dir: Output directory path Returns: Validated output directory path Raises: RepositoryError: If output directory is not writable
(output_dir: Path)
| 72 | ) |
| 73 | |
| 74 | return repo_path, languages |
| 75 | |
| 76 | |
| 77 | def check_writable_output(output_dir: Path) -> Path: |
| 78 | """ |
| 79 | Check if output directory is writable. |
| 80 | |
| 81 | Args: |
| 82 | output_dir: Output directory path |
| 83 | |
| 84 | Returns: |
| 85 | Validated output directory path |
| 86 | |
| 87 | Raises: |
| 88 | RepositoryError: If output directory is not writable |
| 89 | """ |
| 90 | output_dir = Path(output_dir).expanduser().resolve() |
| 91 | |
| 92 | # Check if output directory exists |
| 93 | if output_dir.exists(): |
| 94 | if not output_dir.is_dir(): |
| 95 | raise RepositoryError(f"Output path exists but is not a directory: {output_dir}") |
| 96 | |
| 97 | # Check if writable |
| 98 | if not os.access(output_dir, os.W_OK): |
| 99 | raise RepositoryError( |
| 100 | f"Output directory is not writable: {output_dir}\n\nTry: chmod u+w {output_dir}" |
| 101 | ) |
| 102 | else: |
| 103 | # Check if parent is writable |
| 104 | parent = output_dir.parent |
| 105 | if not parent.exists(): |
| 106 | raise RepositoryError(f"Parent directory does not exist: {parent}") |
| 107 | |
| 108 | if not os.access(parent, os.W_OK): |
| 109 | raise RepositoryError( |
| 110 | f"Cannot create output directory (parent not writable): {parent}\n\n" |
| 111 | f"Try: chmod u+w {parent}" |
| 112 | ) |
| 113 | |
| 114 | return output_dir |
| 115 | |
| 116 | |
| 117 | def _get_git_repo(repo_path: Path): |
| 118 | """ |
| 119 | Find a git repository starting at repo_path and searching parent directories. |
no test coverage detected