Feat(python-generator): protection against accidental overwriting of the output directory #40

Merged
jakob.scheid merged 6 commits from feature/protect-against-accidental-overwriting into main 2026-09-27 21:56:40 +02:00
2 changed files with 14 additions and 0 deletions
Showing only changes of commit 0261a7b3a6 - Show all commits

No files matched your search

+3
View File
@@ -20,6 +20,7 @@ import argparse
import pathlib
import sys
from ..exceptions import DirectoryNotEmptyError
from .languages.python import VALID_SECTIONS as VALID_PYTHON_SECTIONS
__all__ = [
@@ -157,6 +158,8 @@ def main(argv=None) -> int:
return error(f'{exc.filename}: not a directory')
except IsADirectoryError as exc:
return error(f'{exc.filename}: is a directory')
except DirectoryNotEmptyError as exc:
return error(f'{exc.filename}: directory not empty')
except FileExistsError as exc:
return error(f'{exc.filename}: file already exists')
except PermissionError as exc:
+11
View File
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import errno
class NamespaceError(ValueError):
"""
@@ -101,3 +103,12 @@ class PythonDefinitionError(ValueError):
class PythonArgumentStructureError(PythonDefinitionError): ...
class DirectoryNotEmptyError(OSError):
"""
Directory is not empty.
"""
def __init__(self, filename: str | None = None) -> None:
super().__init__(errno.ENOTEMPTY, 'Directory not empty', filename)