directory.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from pathlib import Path
  2. from typing import Iterator
  3. from ..diagnostic import Diagnostic
  4. from .linter import Linter
  5. class Directory(Linter):
  6. def __init__(self, file: Path, settings: dict) -> None:
  7. """ Finds issues in the parent directory"""
  8. super().__init__(file, settings)
  9. def check(self) -> Iterator[Diagnostic]:
  10. if self._file.exists() and self._settings["checks"].get("diagnostic-resources-macos-app-directory-name", False):
  11. for check in self.checkForDotInDirName():
  12. yield check
  13. if self._settings["checks"].get("diagnostic-resource-file-deleted", False):
  14. for check in self.checkFilesDeleted():
  15. yield check
  16. yield
  17. def checkForDotInDirName(self) -> Iterator[Diagnostic]:
  18. """ Check if there is a dot in the directory name, MacOS has trouble signing and notarizing otherwise """
  19. if any("." in p for p in self._file.parent.parts):
  20. yield Diagnostic(
  21. file = self._file,
  22. diagnostic_name = "diagnostic-resources-macos-app-directory-name",
  23. message = f"Directory name containing a `.` not allowed {self._file.suffix}, rename directory containing this file e.q: `_`",
  24. level = "Error",
  25. offset = 1
  26. )
  27. yield
  28. def checkFilesDeleted(self) -> Iterator[Diagnostic]:
  29. """ Check if there is a file that is deleted, this causes upgrade scripts to not work properly """
  30. yield Diagnostic(
  31. file = self._file,
  32. diagnostic_name = "diagnostic-resource-file-deleted",
  33. message = f"File: {self._file} must not be deleted as it is not allowed. It will create issues upgrading Cura",
  34. level = "Error",
  35. offset = 1
  36. )
  37. yield