womm-cli 4.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. womm/__init__.py +53 -0
  2. womm/__main__.py +48 -0
  3. womm/_version.py +10 -0
  4. womm/assets/copier/meta/copier.yml +15 -0
  5. womm/assets/copier/meta/template/README.md.jinja +32 -0
  6. womm/assets/copier/meta/template/copier.yml.jinja +13 -0
  7. womm/assets/copier/meta/template/template/.gitkeep +0 -0
  8. womm/assets/copier/official/javascript/copier.yml +104 -0
  9. womm/assets/copier/official/javascript/template/.gitignore.jinja +35 -0
  10. womm/assets/copier/official/javascript/template/.nvmrc.jinja +1 -0
  11. womm/assets/copier/official/javascript/template/.prettierignore.jinja +10 -0
  12. womm/assets/copier/official/javascript/template/README.md.jinja +81 -0
  13. womm/assets/copier/official/javascript/template/biome.json.jinja +54 -0
  14. womm/assets/copier/official/javascript/template/eslint.config.mjs.jinja +51 -0
  15. womm/assets/copier/official/javascript/template/index.html.jinja +12 -0
  16. womm/assets/copier/official/javascript/template/package.json.jinja +88 -0
  17. womm/assets/copier/official/javascript/template/prettier.config.mjs.jinja +8 -0
  18. womm/assets/copier/official/javascript/template/src/App.jsx.jinja +10 -0
  19. womm/assets/copier/official/javascript/template/src/App.tsx.jinja +10 -0
  20. womm/assets/copier/official/javascript/template/src/App.vue.jinja +18 -0
  21. womm/assets/copier/official/javascript/template/src/index.jsx.jinja +10 -0
  22. womm/assets/copier/official/javascript/template/src/index.tsx.jinja +11 -0
  23. womm/assets/copier/official/javascript/template/src/main.js.jinja +21 -0
  24. womm/assets/copier/official/javascript/template/src/main.ts.jinja +21 -0
  25. womm/assets/copier/official/javascript/template/tsconfig.json.jinja +35 -0
  26. womm/assets/copier/official/javascript/template/vite.config.mjs.jinja +10 -0
  27. womm/assets/copier/official/javascript/template/{% if with_ci %}.github{% endif %}/workflows/ci.yml.jinja +63 -0
  28. womm/assets/copier/official/javascript/template/{% if with_tests %}tests{% endif %}/smoke.test.js.jinja +12 -0
  29. womm/assets/copier/official/javascript/template/{% if with_tests %}tests{% endif %}/smoke.test.ts.jinja +12 -0
  30. womm/assets/copier/official/javascript/template/{% if with_vscode %}.vscode{% endif %}/extensions.json.jinja +4 -0
  31. womm/assets/copier/official/javascript/template/{% if with_vscode %}.vscode{% endif %}/settings.json.jinja +27 -0
  32. womm/assets/copier/official/python/copier.yml +107 -0
  33. womm/assets/copier/official/python/template/.gitignore.jinja +40 -0
  34. womm/assets/copier/official/python/template/.pre-commit-config.yaml.jinja +19 -0
  35. womm/assets/copier/official/python/template/.python-version.jinja +1 -0
  36. womm/assets/copier/official/python/template/README.md.jinja +83 -0
  37. womm/assets/copier/official/python/template/pyproject.toml.jinja +114 -0
  38. womm/assets/copier/official/python/template/{% if framework == 'django' %}manage.py{% endif %}.jinja +23 -0
  39. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/__init__.py.jinja +3 -0
  40. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/asgi.py.jinja +9 -0
  41. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/__init__.py.jinja +0 -0
  42. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/apps.py.jinja +10 -0
  43. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/models.py.jinja +1 -0
  44. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/views.py.jinja +8 -0
  45. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/py.typed +0 -0
  46. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/settings.py.jinja +81 -0
  47. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/urls.py.jinja +11 -0
  48. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/wsgi.py.jinja +9 -0
  49. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/__init__.py.jinja +3 -0
  50. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/asgi.py.jinja +9 -0
  51. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/__init__.py.jinja +0 -0
  52. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/apps.py.jinja +10 -0
  53. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/models.py.jinja +1 -0
  54. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/views.py.jinja +8 -0
  55. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/py.typed +0 -0
  56. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/settings.py.jinja +81 -0
  57. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/urls.py.jinja +11 -0
  58. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/wsgi.py.jinja +9 -0
  59. womm/assets/copier/official/python/template/{% if with_ci %}.github{% endif %}/workflows/ci.yml.jinja +78 -0
  60. womm/assets/copier/official/python/template/{% if with_tests %}tests{% endif %}/test_smoke.py.jinja +16 -0
  61. womm/assets/copier/official/python/template/{% if with_vscode %}.vscode{% endif %}/extensions.json.jinja +8 -0
  62. womm/assets/copier/official/python/template/{% if with_vscode %}.vscode{% endif %}/settings.json.jinja +28 -0
  63. womm/bin/refresh_env.cmd +130 -0
  64. womm/cli.py +111 -0
  65. womm/commands/__init__.py +30 -0
  66. womm/commands/core/__init__.py +29 -0
  67. womm/commands/core/doctor.py +52 -0
  68. womm/commands/core/path.py +337 -0
  69. womm/commands/project/__init__.py +31 -0
  70. womm/commands/project/create.py +128 -0
  71. womm/commands/project/setup.py +438 -0
  72. womm/commands/project/template.py +160 -0
  73. womm/commands/system/__init__.py +31 -0
  74. womm/commands/system/context/__init__.py +82 -0
  75. womm/commands/system/context/backup.py +344 -0
  76. womm/commands/system/context/inventory.py +111 -0
  77. womm/commands/system/context/registration.py +290 -0
  78. womm/commands/system/deps.py +165 -0
  79. womm/commands/system/system.py +130 -0
  80. womm/exceptions/__init__.py +69 -0
  81. womm/exceptions/common/__init__.py +55 -0
  82. womm/exceptions/common/command_service.py +91 -0
  83. womm/exceptions/common/file_service.py +60 -0
  84. womm/exceptions/common/security_service.py +44 -0
  85. womm/exceptions/common/validation_service.py +70 -0
  86. womm/exceptions/context/__init__.py +27 -0
  87. womm/exceptions/context/context_service.py +55 -0
  88. womm/exceptions/project/__init__.py +29 -0
  89. womm/exceptions/project/project_service.py +59 -0
  90. womm/exceptions/system/__init__.py +25 -0
  91. womm/exceptions/system/system_service.py +53 -0
  92. womm/interfaces/__init__.py +71 -0
  93. womm/interfaces/context/__init__.py +34 -0
  94. womm/interfaces/context/menu_interface.py +686 -0
  95. womm/interfaces/context/registry_interface.py +562 -0
  96. womm/interfaces/context/script_detector_interface.py +208 -0
  97. womm/interfaces/context/script_registrar.py +264 -0
  98. womm/interfaces/core/__init__.py +26 -0
  99. womm/interfaces/core/doctor_interface.py +102 -0
  100. womm/interfaces/dependencies/__init__.py +28 -0
  101. womm/interfaces/dependencies/deps_interface.py +160 -0
  102. womm/interfaces/project/__init__.py +36 -0
  103. womm/interfaces/project/create_interface.py +162 -0
  104. womm/interfaces/project/detection_interface.py +181 -0
  105. womm/interfaces/project/manager_interface.py +99 -0
  106. womm/interfaces/project/setup_interface.py +477 -0
  107. womm/interfaces/project/template_store_interface.py +196 -0
  108. womm/interfaces/system/__init__.py +32 -0
  109. womm/interfaces/system/detector_interface.py +84 -0
  110. womm/interfaces/system/environment_interface.py +110 -0
  111. womm/interfaces/system/path_interface.py +570 -0
  112. womm/services/__init__.py +70 -0
  113. womm/services/common/__init__.py +33 -0
  114. womm/services/common/base_validation_service.py +450 -0
  115. womm/services/common/command_runner_service.py +647 -0
  116. womm/services/common/file_scanner_service.py +483 -0
  117. womm/services/common/security_validator_service.py +348 -0
  118. womm/services/context/__init__.py +37 -0
  119. womm/services/context/backup_entries.py +148 -0
  120. womm/services/context/parameters.py +515 -0
  121. womm/services/context/registry_paths.py +56 -0
  122. womm/services/context/registry_service.py +573 -0
  123. womm/services/context/validation_service.py +691 -0
  124. womm/services/dependencies/__init__.py +29 -0
  125. womm/services/dependencies/probe.py +102 -0
  126. womm/services/project/__init__.py +48 -0
  127. womm/services/project/copier_project_creation_service.py +111 -0
  128. womm/services/project/destination_guard.py +96 -0
  129. womm/services/project/detection_service.py +354 -0
  130. womm/services/project/env_utils.py +333 -0
  131. womm/services/project/javascript_environment_service.py +348 -0
  132. womm/services/project/python_environment_service.py +245 -0
  133. womm/services/project/setup_profile_resolver.py +146 -0
  134. womm/services/project/template_store_service.py +344 -0
  135. womm/services/project/validation_service.py +418 -0
  136. womm/services/system/__init__.py +32 -0
  137. womm/services/system/detector_service.py +704 -0
  138. womm/services/system/environment_service.py +494 -0
  139. womm/services/system/path_service.py +642 -0
  140. womm/shared/__init__.py +30 -0
  141. womm/shared/configs/__init__.py +51 -0
  142. womm/shared/configs/context/__init__.py +43 -0
  143. womm/shared/configs/context/context_config.py +125 -0
  144. womm/shared/configs/context/context_file_types_config.py +159 -0
  145. womm/shared/configs/context/context_limits_config.py +187 -0
  146. womm/shared/configs/context/context_paths_config.py +115 -0
  147. womm/shared/configs/context/context_types_config.py +65 -0
  148. womm/shared/configs/context/script_config.py +219 -0
  149. womm/shared/configs/dependencies/__init__.py +32 -0
  150. womm/shared/configs/dependencies/runtime_config.py +46 -0
  151. womm/shared/configs/dependencies/runtime_package_manager_config.py +48 -0
  152. womm/shared/configs/logging_config.py +89 -0
  153. womm/shared/configs/project/__init__.py +33 -0
  154. womm/shared/configs/project/project_config.py +109 -0
  155. womm/shared/configs/project/project_structure_config.py +88 -0
  156. womm/shared/configs/project/python_project_config.py +165 -0
  157. womm/shared/configs/security/__init__.py +26 -0
  158. womm/shared/configs/security/security_patterns_config.py +242 -0
  159. womm/shared/configs/system/__init__.py +28 -0
  160. womm/shared/configs/system/system_detector_config.py +210 -0
  161. womm/shared/configs/system/system_environment_config.py +101 -0
  162. womm/shared/models/__init__.py +13 -0
  163. womm/shared/models/template_source.py +65 -0
  164. womm/shared/paths.py +192 -0
  165. womm/shared/results/__init__.py +138 -0
  166. womm/shared/results/base.py +85 -0
  167. womm/shared/results/command_results.py +61 -0
  168. womm/shared/results/context_results.py +345 -0
  169. womm/shared/results/dependency_results.py +110 -0
  170. womm/shared/results/doctor_results.py +41 -0
  171. womm/shared/results/file_results.py +97 -0
  172. womm/shared/results/project_results.py +163 -0
  173. womm/shared/results/security_results.py +128 -0
  174. womm/shared/results/system_results.py +268 -0
  175. womm/shared/results/template_results.py +43 -0
  176. womm/shared/runtime.py +36 -0
  177. womm/ui/__init__.py +31 -0
  178. womm/ui/common/__init__.py +39 -0
  179. womm/ui/common/interactive_menu.py +246 -0
  180. womm/ui/common/logging.py +184 -0
  181. womm/ui/common/prompts.py +93 -0
  182. womm/ui/context/__init__.py +31 -0
  183. womm/ui/context/display.py +485 -0
  184. womm/ui/context/menu_display.py +189 -0
  185. womm/ui/context/wizard.py +557 -0
  186. womm/ui/project/__init__.py +42 -0
  187. womm/ui/project/create/create_completion_summaries.py +55 -0
  188. womm/ui/project/project_wizard.py +174 -0
  189. womm/ui/project/setup/setup_completion_summaries.py +111 -0
  190. womm/ui/project/templates/template_store_display.py +128 -0
  191. womm/ui/system/__init__.py +60 -0
  192. womm/ui/system/display.py +531 -0
  193. womm/ui/system/path_display.py +387 -0
  194. womm/utils/__init__.py +23 -0
  195. womm/utils/common/__init__.py +49 -0
  196. womm/utils/common/file_scanner_utils.py +110 -0
  197. womm/utils/common/path_resolver_utils.py +127 -0
  198. womm/utils/common/safe_fs_utils.py +135 -0
  199. womm/utils/context/__init__.py +54 -0
  200. womm/utils/context/core_utils.py +345 -0
  201. womm/utils/context/icon_utils.py +259 -0
  202. womm/utils/project/__init__.py +106 -0
  203. womm/utils/project/asset_utils.py +154 -0
  204. womm/utils/project/core_utils.py +391 -0
  205. womm/utils/project/file_utils.py +494 -0
  206. womm/utils/project/platform_utils.py +170 -0
  207. womm/utils/project/validation_utils.py +273 -0
  208. womm/utils/security/__init__.py +46 -0
  209. womm/utils/security/security_validation_utils.py +258 -0
  210. womm/utils/system/__init__.py +69 -0
  211. womm/utils/system/detector_utils.py +299 -0
  212. womm/utils/system/environment_utils.py +172 -0
  213. womm/utils/system/path_utils.py +101 -0
  214. womm_cli-4.0.0.dist-info/METADATA +203 -0
  215. womm_cli-4.0.0.dist-info/RECORD +218 -0
  216. womm_cli-4.0.0.dist-info/WHEEL +4 -0
  217. womm_cli-4.0.0.dist-info/entry_points.txt +2 -0
  218. womm_cli-4.0.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,691 @@
1
+ #!/usr/bin/env python3
2
+ # ///////////////////////////////////////////////////////////////
3
+ # CONTEXT VALIDATION SERVICE - Context Menu Validation Service
4
+ # Project: works-on-my-machine
5
+ # ///////////////////////////////////////////////////////////////
6
+
7
+ """
8
+ Context Validation Service - Singleton service for context menu validation operations.
9
+
10
+ This module provides comprehensive validation functionality
11
+ for Windows context menu operations, including input validation,
12
+ data validation, and system compatibility checks.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ # ///////////////////////////////////////////////////////////////
18
+ # IMPORTS
19
+ # ///////////////////////////////////////////////////////////////
20
+ # Standard library imports
21
+ import logging
22
+ from pathlib import Path
23
+ from threading import Lock
24
+ from typing import ClassVar
25
+
26
+ # Local imports
27
+ from ...exceptions.context import ContextServiceError
28
+ from ...shared.configs.context import ContextConfig
29
+ from ...shared.results import ContextValidationResult
30
+ from ...utils.context import (
31
+ sanitize_label,
32
+ sanitize_registry_key,
33
+ validate_backup_data,
34
+ validate_icon_path,
35
+ validate_label,
36
+ validate_registry_key,
37
+ )
38
+ from ..common.security_validator_service import SecurityValidatorService
39
+ from ..system.detector_service import SystemDetectorService
40
+
41
+ # ///////////////////////////////////////////////////////////////
42
+ # LOGGER SETUP
43
+ # ///////////////////////////////////////////////////////////////
44
+
45
+ logger = logging.getLogger(__name__)
46
+
47
+ # ///////////////////////////////////////////////////////////////
48
+ # CONTEXT VALIDATION SERVICE CLASS
49
+ # ///////////////////////////////////////////////////////////////
50
+
51
+
52
+ class ContextValidationService:
53
+ """Singleton service for context menu validation operations."""
54
+
55
+ _instance: ClassVar[ContextValidationService | None] = None
56
+ _initialized: ClassVar[bool] = False
57
+ _lock: ClassVar[Lock] = Lock()
58
+
59
+ def __new__(cls) -> ContextValidationService:
60
+ """Create or return the singleton instance.
61
+
62
+ Returns:
63
+ ContextValidationService: The singleton instance
64
+ """
65
+ with cls._lock:
66
+ if cls._instance is None:
67
+ cls._instance = super().__new__(cls)
68
+ return cls._instance
69
+
70
+ def __init__(self) -> None:
71
+ """Initialize context validation service (only once)."""
72
+ if ContextValidationService._initialized:
73
+ return
74
+
75
+ self.logger = logging.getLogger(__name__)
76
+ self.security_validator = SecurityValidatorService()
77
+ self.system_detector = SystemDetectorService()
78
+ ContextValidationService._initialized = True
79
+
80
+ # ///////////////////////////////////////////////////////////////
81
+ # PUBLIC METHODS
82
+ # ///////////////////////////////////////////////////////////////
83
+
84
+ def validate_script_path(self, script_path: str) -> ContextValidationResult:
85
+ """
86
+ Validate a script path for context menu registration.
87
+
88
+ Args:
89
+ script_path: Path to the script to validate
90
+
91
+ Returns:
92
+ ContextValidationResult: Validation result
93
+
94
+ Raises:
95
+ ContextServiceError: If script_path is invalid or an unexpected
96
+ error occurs
97
+ """
98
+ try:
99
+ # Input validation
100
+ if not script_path:
101
+ raise ContextServiceError("script_path", "Script path is required")
102
+
103
+ if not isinstance(script_path, str):
104
+ raise ContextServiceError(
105
+ "script_path",
106
+ f"Script path must be a string, got {type(script_path).__name__}",
107
+ )
108
+
109
+ script_path = script_path.strip()
110
+ if not script_path:
111
+ raise ContextServiceError(
112
+ "script_path", "Script path cannot be empty after stripping"
113
+ )
114
+
115
+ # Security validation using SecurityValidatorService
116
+ try:
117
+ validation_result = self.security_validator.validate_file_path(
118
+ script_path
119
+ )
120
+ if not validation_result.is_valid:
121
+ raise ContextServiceError(
122
+ "script_path",
123
+ f"Security validation failed: {validation_result.validation_reason}",
124
+ )
125
+ except ContextServiceError:
126
+ raise
127
+ except Exception as e:
128
+ raise ContextServiceError(
129
+ "script_path", f"Security validation failed: {e}"
130
+ ) from e
131
+
132
+ # Convert to Path object and resolve relative paths
133
+ try:
134
+ path = Path(script_path).resolve()
135
+ except Exception as e:
136
+ raise ContextServiceError(
137
+ "script_path", f"Invalid script path format: {e}"
138
+ ) from e
139
+
140
+ # Check if file exists
141
+ try:
142
+ if not path.exists():
143
+ raise ContextServiceError(
144
+ "script_path", f"Script file not found: {script_path}"
145
+ )
146
+ except (OSError, PermissionError) as e:
147
+ raise ContextServiceError(
148
+ "script_path", f"Cannot access script file: {e}"
149
+ ) from e
150
+
151
+ # Check if it's a file (not directory)
152
+ try:
153
+ if not path.is_file():
154
+ raise ContextServiceError(
155
+ "script_path", f"Path is not a file: {script_path}"
156
+ )
157
+ except (OSError, PermissionError) as e:
158
+ raise ContextServiceError(
159
+ "script_path", f"Cannot check if path is file: {e}"
160
+ ) from e
161
+
162
+ # Check file extension
163
+ extension = path.suffix.lower()
164
+ if extension not in ContextConfig.VALID_SCRIPT_EXTENSIONS:
165
+ raise ContextServiceError(
166
+ "script_path",
167
+ f"Unsupported file extension: {extension}. Supported: {', '.join(ContextConfig.VALID_SCRIPT_EXTENSIONS)}",
168
+ )
169
+
170
+ # Check file size (prevent empty files)
171
+ try:
172
+ if path.stat().st_size == 0:
173
+ raise ContextServiceError("script_path", "Script file is empty")
174
+ except (OSError, PermissionError) as e:
175
+ raise ContextServiceError(
176
+ "script_path", f"Cannot access script file: {e}"
177
+ ) from e
178
+
179
+ # Check if file is readable
180
+ try:
181
+ with open(path, encoding="utf-8", errors="ignore") as f:
182
+ f.read(1) # Try to read at least one character
183
+ except (UnicodeDecodeError, PermissionError) as e:
184
+ # For binary files like .exe, this is expected
185
+ if extension not in {".exe", ".msi"}:
186
+ raise ContextServiceError(
187
+ "script_path",
188
+ "Script file is not readable or contains invalid characters",
189
+ ) from e
190
+
191
+ # Check path length
192
+ if len(str(path)) > ContextConfig.MAX_PATH_LENGTH:
193
+ raise ContextServiceError(
194
+ "script_path",
195
+ f"Script path is too long (max {ContextConfig.MAX_PATH_LENGTH} characters)",
196
+ )
197
+
198
+ return ContextValidationResult(
199
+ success=True,
200
+ message="Script path validation successful",
201
+ input_type="script_path",
202
+ input_value=str(path.absolute()),
203
+ script_path=str(path.absolute()),
204
+ extension=extension,
205
+ file_size=path.stat().st_size,
206
+ )
207
+
208
+ except ContextServiceError:
209
+ raise
210
+ except Exception as e:
211
+ raise ContextServiceError(
212
+ "script_path",
213
+ f"Unexpected error validating script path: {e}",
214
+ details=f"Script path: {script_path}",
215
+ ) from e
216
+
217
+ @staticmethod
218
+ def validate_label(label: str) -> ContextValidationResult:
219
+ """
220
+ Validate a context menu label.
221
+
222
+ Args:
223
+ label: Label to validate
224
+
225
+ Returns:
226
+ ContextValidationResult: Validation result (``success=False`` if
227
+ the label is invalid)
228
+ """
229
+ try:
230
+ # Utility function raises exception if invalid, returns None if valid
231
+ validate_label(label)
232
+ return ContextValidationResult(
233
+ success=True,
234
+ message="Label validation successful",
235
+ input_type="label",
236
+ input_value=label,
237
+ label=label,
238
+ )
239
+ except ValueError as e:
240
+ return ContextValidationResult(
241
+ success=False,
242
+ error=str(e),
243
+ input_type="label",
244
+ input_value=label,
245
+ label=label,
246
+ )
247
+
248
+ @staticmethod
249
+ def validate_registry_key(key_name: str) -> ContextValidationResult:
250
+ """
251
+ Validate a registry key name.
252
+
253
+ Args:
254
+ key_name: Registry key name to validate
255
+
256
+ Returns:
257
+ ContextValidationResult: Validation result (``success=False`` if
258
+ the key is invalid)
259
+ """
260
+ try:
261
+ # Utility function raises exception if invalid, returns None if valid
262
+ validate_registry_key(key_name)
263
+ return ContextValidationResult(
264
+ success=True,
265
+ message="Registry key validation successful",
266
+ input_type="registry_key",
267
+ input_value=key_name,
268
+ registry_key=key_name,
269
+ )
270
+ except ValueError as e:
271
+ return ContextValidationResult(
272
+ success=False,
273
+ error=str(e),
274
+ input_type="registry_key",
275
+ input_value=key_name,
276
+ registry_key=key_name,
277
+ )
278
+
279
+ def validate_icon_path(self, icon_path: str) -> ContextValidationResult:
280
+ """
281
+ Validate an icon path.
282
+
283
+ Args:
284
+ icon_path: Icon path to validate
285
+
286
+ Returns:
287
+ ContextValidationResult: Validation result (``success=False`` if
288
+ the icon path is invalid)
289
+
290
+ Raises:
291
+ ContextServiceError: For unexpected errors
292
+ """
293
+ try:
294
+ # Utility function raises exception if invalid, returns None if valid
295
+ validate_icon_path(icon_path)
296
+
297
+ # Determine icon type
298
+ icon_type = "special" if icon_path == "auto" or not icon_path else "file"
299
+
300
+ # Additional security validation for non-special values
301
+ if icon_type != "special":
302
+ try:
303
+ validation_result = self.security_validator.validate_file_path(
304
+ icon_path
305
+ )
306
+ if not validation_result.is_valid:
307
+ return ContextValidationResult(
308
+ success=False,
309
+ error=f"Security validation failed: {validation_result.validation_reason}",
310
+ input_type="icon_path",
311
+ input_value=icon_path,
312
+ icon_path=icon_path,
313
+ icon_type=icon_type,
314
+ )
315
+ except Exception as e:
316
+ return ContextValidationResult(
317
+ success=False,
318
+ error=f"Security validation failed: {e}",
319
+ input_type="icon_path",
320
+ input_value=icon_path,
321
+ icon_path=icon_path,
322
+ icon_type=icon_type,
323
+ )
324
+
325
+ return ContextValidationResult(
326
+ success=True,
327
+ message="Icon path validation successful",
328
+ input_type="icon_path",
329
+ input_value=icon_path,
330
+ icon_path=icon_path,
331
+ icon_type=icon_type,
332
+ )
333
+
334
+ except ValueError as e:
335
+ return ContextValidationResult(
336
+ success=False,
337
+ error=str(e),
338
+ input_type="icon_path",
339
+ input_value=icon_path,
340
+ icon_path=icon_path,
341
+ icon_type="",
342
+ )
343
+ except Exception as e:
344
+ raise ContextServiceError(
345
+ "icon_path",
346
+ f"Unexpected error validating icon path: {e}",
347
+ details=f"Icon path: {icon_path}",
348
+ ) from e
349
+
350
+ @staticmethod
351
+ def validate_backup_data(
352
+ data: dict[str, str | bool | int | list | dict],
353
+ ) -> dict[str, str | bool | int | list | dict]:
354
+ """
355
+ Validate backup data structure.
356
+
357
+ Args:
358
+ data: Backup data to validate
359
+
360
+ Returns:
361
+ Validation result dictionary
362
+
363
+ Raises:
364
+ ValueError: If data is invalid
365
+ """
366
+ validate_backup_data(data)
367
+ return data
368
+
369
+ def check_permissions(self) -> ContextValidationResult:
370
+ """
371
+ Check if the current user has sufficient permissions for registry operations.
372
+
373
+ Returns:
374
+ ContextValidationResult: Permission check result
375
+
376
+ Raises:
377
+ ContextServiceError: For unexpected errors
378
+ """
379
+ try:
380
+ # Check if running on Windows using SystemDetectorService
381
+ system_info = self.system_detector.get_system_info()
382
+ if not system_info.success:
383
+ return ContextValidationResult(
384
+ success=False,
385
+ error="Failed to get system information",
386
+ input_type="permissions",
387
+ has_permissions=False,
388
+ )
389
+ platform_name = system_info.platform or ""
390
+
391
+ if platform_name != "Windows":
392
+ return ContextValidationResult(
393
+ success=False,
394
+ error="Registry operations are only supported on Windows",
395
+ input_type="permissions",
396
+ has_permissions=False,
397
+ )
398
+
399
+ import winreg
400
+
401
+ # Try to access registry for writing
402
+ test_key = "Software\\Classes\\Directory\\shell\\WOMM_TEST_PERMISSIONS"
403
+
404
+ try:
405
+ # Try to create a test key
406
+ key = winreg.CreateKey(winreg.HKEY_CURRENT_USER, test_key)
407
+ winreg.DeleteKey(winreg.HKEY_CURRENT_USER, test_key)
408
+ winreg.CloseKey(key)
409
+
410
+ return ContextValidationResult(
411
+ success=True,
412
+ message="User has sufficient permissions for registry operations",
413
+ input_type="permissions",
414
+ has_permissions=True,
415
+ )
416
+
417
+ except PermissionError:
418
+ return ContextValidationResult(
419
+ success=False,
420
+ error="Insufficient permissions. Try running as administrator",
421
+ input_type="permissions",
422
+ has_permissions=False,
423
+ )
424
+
425
+ except Exception as e:
426
+ return ContextValidationResult(
427
+ success=False,
428
+ error=f"Permission check failed: {e!s}",
429
+ input_type="permissions",
430
+ has_permissions=False,
431
+ )
432
+
433
+ except Exception as e:
434
+ raise ContextServiceError(
435
+ "permissions",
436
+ f"Unexpected error checking permissions: {e}",
437
+ details="Failed to check registry permissions",
438
+ ) from e
439
+
440
+ def validate_windows_compatibility(self) -> ContextValidationResult:
441
+ """
442
+ Check Windows compatibility for context menu operations.
443
+
444
+ Returns:
445
+ ContextValidationResult: Compatibility check result
446
+
447
+ Raises:
448
+ ContextServiceError: For unexpected errors
449
+ """
450
+ try:
451
+ # Get system info using SystemDetectorService
452
+ system_info = self.system_detector.get_system_info()
453
+ if not system_info.success:
454
+ return ContextValidationResult(
455
+ success=False,
456
+ error="Failed to get system information",
457
+ input_type="compatibility",
458
+ compatible=False,
459
+ )
460
+ platform_name = system_info.platform or ""
461
+
462
+ # Check OS
463
+ if platform_name != "Windows":
464
+ return ContextValidationResult(
465
+ success=False,
466
+ error="Context menu operations are only supported on Windows",
467
+ input_type="compatibility",
468
+ compatible=False,
469
+ )
470
+
471
+ import winreg
472
+
473
+ # Check Windows version
474
+ platform_version = ""
475
+ try:
476
+ platform_version = system_info.platform_version or ""
477
+ if platform_version:
478
+ # Windows 7 and later are supported (version 6.0+)
479
+ major_version = int(platform_version.split(".")[0])
480
+ if major_version < 6:
481
+ return ContextValidationResult(
482
+ success=False,
483
+ error="Windows 7 or later is required",
484
+ input_type="compatibility",
485
+ compatible=False,
486
+ )
487
+ else:
488
+ return ContextValidationResult(
489
+ success=False,
490
+ error="Cannot determine Windows version",
491
+ input_type="compatibility",
492
+ compatible=False,
493
+ )
494
+
495
+ except (ValueError, AttributeError) as e:
496
+ return ContextValidationResult(
497
+ success=False,
498
+ error=f"Cannot determine Windows version: {e!s}",
499
+ input_type="compatibility",
500
+ compatible=False,
501
+ )
502
+
503
+ # Check if registry is accessible
504
+ try:
505
+ key = winreg.OpenKey(
506
+ winreg.HKEY_CURRENT_USER, "Software\\Classes", 0, winreg.KEY_READ
507
+ )
508
+ winreg.CloseKey(key)
509
+ except Exception as e:
510
+ return ContextValidationResult(
511
+ success=False,
512
+ error=f"Cannot access Windows Registry: {e!s}",
513
+ input_type="compatibility",
514
+ compatible=False,
515
+ )
516
+
517
+ return ContextValidationResult(
518
+ success=True,
519
+ message="System is compatible with context menu operations",
520
+ input_type="compatibility",
521
+ compatible=True,
522
+ windows_version=platform_version,
523
+ )
524
+
525
+ except Exception as e:
526
+ raise ContextServiceError(
527
+ "windows_compatibility",
528
+ f"Unexpected error checking Windows compatibility: {e}",
529
+ details="Failed to validate system compatibility",
530
+ ) from e
531
+
532
+ def validate_command_parameters(
533
+ self, script_path: str, label: str, icon: str | None = None
534
+ ) -> ContextValidationResult:
535
+ """
536
+ Validate all parameters for context menu registration.
537
+
538
+ Args:
539
+ script_path: Path to the script
540
+ label: Display label
541
+ icon: Icon path (optional)
542
+
543
+ Returns:
544
+ ContextValidationResult: Comprehensive validation result
545
+
546
+ Raises:
547
+ ContextServiceError: If parameters are invalid or an unexpected
548
+ error occurs
549
+ """
550
+ try:
551
+ # Input validation
552
+ if not script_path:
553
+ raise ContextServiceError(
554
+ "command_parameters", "Script path is required"
555
+ )
556
+
557
+ if not label:
558
+ raise ContextServiceError("command_parameters", "Label is required")
559
+
560
+ if not isinstance(script_path, str):
561
+ raise ContextServiceError(
562
+ "command_parameters",
563
+ f"Script path must be a string, got {type(script_path).__name__}",
564
+ )
565
+
566
+ if not isinstance(label, str):
567
+ raise ContextServiceError(
568
+ "command_parameters",
569
+ f"Label must be a string, got {type(label).__name__}",
570
+ )
571
+
572
+ if icon is not None and not isinstance(icon, str):
573
+ raise ContextServiceError(
574
+ "command_parameters",
575
+ f"Icon must be a string, got {type(icon).__name__}",
576
+ )
577
+
578
+ errors = []
579
+ warnings = []
580
+ result = ContextValidationResult(
581
+ success=True,
582
+ message="All parameters validated successfully",
583
+ input_type="command_parameters",
584
+ script_path=script_path,
585
+ label=label,
586
+ )
587
+
588
+ # Validate script path
589
+ try:
590
+ script_validation = self.validate_script_path(script_path)
591
+ result.script_path = script_validation.script_path
592
+ result.extension = script_validation.extension
593
+ result.file_size = script_validation.file_size
594
+ if not script_validation.success:
595
+ result.success = False
596
+ errors.append(script_validation.error)
597
+ except ContextServiceError as e:
598
+ result.success = False
599
+ errors.append(str(e))
600
+
601
+ # Validate label
602
+ try:
603
+ label_validation = self.validate_label(label)
604
+ result.label = label_validation.label
605
+ if not label_validation.success:
606
+ result.success = False
607
+ errors.append(label_validation.error)
608
+ except ContextServiceError as e:
609
+ result.success = False
610
+ errors.append(str(e))
611
+
612
+ # Validate icon if provided
613
+ if icon:
614
+ try:
615
+ icon_validation = self.validate_icon_path(icon)
616
+ result.icon_path = icon_validation.icon_path
617
+ result.icon_type = icon_validation.icon_type
618
+ if not icon_validation.success:
619
+ warnings.append(f"Icon validation: {icon_validation.error}")
620
+ except ContextServiceError as e:
621
+ warnings.append(f"Icon validation: {e!s}")
622
+
623
+ # Check permissions
624
+ try:
625
+ permission_check = self.check_permissions()
626
+ result.has_permissions = permission_check.has_permissions
627
+ if not permission_check.has_permissions:
628
+ result.success = False
629
+ errors.append(permission_check.error)
630
+ except Exception as e:
631
+ warnings.append(f"Permission check failed: {e!s}")
632
+
633
+ # Check compatibility
634
+ try:
635
+ compatibility_check = self.validate_windows_compatibility()
636
+ result.compatible = compatibility_check.compatible
637
+ result.windows_version = compatibility_check.windows_version
638
+ if not compatibility_check.compatible:
639
+ result.success = False
640
+ errors.append(compatibility_check.error)
641
+ except Exception as e:
642
+ warnings.append(f"Compatibility check failed: {e!s}")
643
+
644
+ # Update message and error based on results
645
+ if errors:
646
+ result.error = "; ".join(errors)
647
+ if warnings:
648
+ result.message = (
649
+ f"Validation completed with warnings: {'; '.join(warnings)}"
650
+ )
651
+
652
+ return result
653
+
654
+ except ContextServiceError:
655
+ raise
656
+ except Exception as e:
657
+ raise ContextServiceError(
658
+ "command_parameters",
659
+ f"Unexpected error validating command parameters: {e}",
660
+ details=f"Script path: {script_path}, Label: {label}, Icon: {icon}",
661
+ ) from e
662
+
663
+ def sanitize_registry_key(self, key_name: str) -> str:
664
+ """
665
+ Sanitize a registry key name to make it valid.
666
+
667
+ Args:
668
+ key_name: Original key name
669
+
670
+ Returns:
671
+ Sanitized key name
672
+
673
+ Raises:
674
+ ValueError: If key_name is invalid
675
+ """
676
+ return sanitize_registry_key(key_name)
677
+
678
+ def sanitize_label(self, label: str) -> str:
679
+ """
680
+ Sanitize a context menu label to make it valid.
681
+
682
+ Args:
683
+ label: Original label
684
+
685
+ Returns:
686
+ Sanitized label
687
+
688
+ Raises:
689
+ ValueError: If label is invalid
690
+ """
691
+ return sanitize_label(label)