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.
- womm/__init__.py +53 -0
- womm/__main__.py +48 -0
- womm/_version.py +10 -0
- womm/assets/copier/meta/copier.yml +15 -0
- womm/assets/copier/meta/template/README.md.jinja +32 -0
- womm/assets/copier/meta/template/copier.yml.jinja +13 -0
- womm/assets/copier/meta/template/template/.gitkeep +0 -0
- womm/assets/copier/official/javascript/copier.yml +104 -0
- womm/assets/copier/official/javascript/template/.gitignore.jinja +35 -0
- womm/assets/copier/official/javascript/template/.nvmrc.jinja +1 -0
- womm/assets/copier/official/javascript/template/.prettierignore.jinja +10 -0
- womm/assets/copier/official/javascript/template/README.md.jinja +81 -0
- womm/assets/copier/official/javascript/template/biome.json.jinja +54 -0
- womm/assets/copier/official/javascript/template/eslint.config.mjs.jinja +51 -0
- womm/assets/copier/official/javascript/template/index.html.jinja +12 -0
- womm/assets/copier/official/javascript/template/package.json.jinja +88 -0
- womm/assets/copier/official/javascript/template/prettier.config.mjs.jinja +8 -0
- womm/assets/copier/official/javascript/template/src/App.jsx.jinja +10 -0
- womm/assets/copier/official/javascript/template/src/App.tsx.jinja +10 -0
- womm/assets/copier/official/javascript/template/src/App.vue.jinja +18 -0
- womm/assets/copier/official/javascript/template/src/index.jsx.jinja +10 -0
- womm/assets/copier/official/javascript/template/src/index.tsx.jinja +11 -0
- womm/assets/copier/official/javascript/template/src/main.js.jinja +21 -0
- womm/assets/copier/official/javascript/template/src/main.ts.jinja +21 -0
- womm/assets/copier/official/javascript/template/tsconfig.json.jinja +35 -0
- womm/assets/copier/official/javascript/template/vite.config.mjs.jinja +10 -0
- womm/assets/copier/official/javascript/template/{% if with_ci %}.github{% endif %}/workflows/ci.yml.jinja +63 -0
- womm/assets/copier/official/javascript/template/{% if with_tests %}tests{% endif %}/smoke.test.js.jinja +12 -0
- womm/assets/copier/official/javascript/template/{% if with_tests %}tests{% endif %}/smoke.test.ts.jinja +12 -0
- womm/assets/copier/official/javascript/template/{% if with_vscode %}.vscode{% endif %}/extensions.json.jinja +4 -0
- womm/assets/copier/official/javascript/template/{% if with_vscode %}.vscode{% endif %}/settings.json.jinja +27 -0
- womm/assets/copier/official/python/copier.yml +107 -0
- womm/assets/copier/official/python/template/.gitignore.jinja +40 -0
- womm/assets/copier/official/python/template/.pre-commit-config.yaml.jinja +19 -0
- womm/assets/copier/official/python/template/.python-version.jinja +1 -0
- womm/assets/copier/official/python/template/README.md.jinja +83 -0
- womm/assets/copier/official/python/template/pyproject.toml.jinja +114 -0
- womm/assets/copier/official/python/template/{% if framework == 'django' %}manage.py{% endif %}.jinja +23 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/__init__.py.jinja +3 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/asgi.py.jinja +9 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/__init__.py.jinja +0 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/apps.py.jinja +10 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/models.py.jinja +1 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/views.py.jinja +8 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/py.typed +0 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/settings.py.jinja +81 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/urls.py.jinja +11 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/wsgi.py.jinja +9 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/__init__.py.jinja +3 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/asgi.py.jinja +9 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/__init__.py.jinja +0 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/apps.py.jinja +10 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/models.py.jinja +1 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/views.py.jinja +8 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/py.typed +0 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/settings.py.jinja +81 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/urls.py.jinja +11 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/wsgi.py.jinja +9 -0
- womm/assets/copier/official/python/template/{% if with_ci %}.github{% endif %}/workflows/ci.yml.jinja +78 -0
- womm/assets/copier/official/python/template/{% if with_tests %}tests{% endif %}/test_smoke.py.jinja +16 -0
- womm/assets/copier/official/python/template/{% if with_vscode %}.vscode{% endif %}/extensions.json.jinja +8 -0
- womm/assets/copier/official/python/template/{% if with_vscode %}.vscode{% endif %}/settings.json.jinja +28 -0
- womm/bin/refresh_env.cmd +130 -0
- womm/cli.py +111 -0
- womm/commands/__init__.py +30 -0
- womm/commands/core/__init__.py +29 -0
- womm/commands/core/doctor.py +52 -0
- womm/commands/core/path.py +337 -0
- womm/commands/project/__init__.py +31 -0
- womm/commands/project/create.py +128 -0
- womm/commands/project/setup.py +438 -0
- womm/commands/project/template.py +160 -0
- womm/commands/system/__init__.py +31 -0
- womm/commands/system/context/__init__.py +82 -0
- womm/commands/system/context/backup.py +344 -0
- womm/commands/system/context/inventory.py +111 -0
- womm/commands/system/context/registration.py +290 -0
- womm/commands/system/deps.py +165 -0
- womm/commands/system/system.py +130 -0
- womm/exceptions/__init__.py +69 -0
- womm/exceptions/common/__init__.py +55 -0
- womm/exceptions/common/command_service.py +91 -0
- womm/exceptions/common/file_service.py +60 -0
- womm/exceptions/common/security_service.py +44 -0
- womm/exceptions/common/validation_service.py +70 -0
- womm/exceptions/context/__init__.py +27 -0
- womm/exceptions/context/context_service.py +55 -0
- womm/exceptions/project/__init__.py +29 -0
- womm/exceptions/project/project_service.py +59 -0
- womm/exceptions/system/__init__.py +25 -0
- womm/exceptions/system/system_service.py +53 -0
- womm/interfaces/__init__.py +71 -0
- womm/interfaces/context/__init__.py +34 -0
- womm/interfaces/context/menu_interface.py +686 -0
- womm/interfaces/context/registry_interface.py +562 -0
- womm/interfaces/context/script_detector_interface.py +208 -0
- womm/interfaces/context/script_registrar.py +264 -0
- womm/interfaces/core/__init__.py +26 -0
- womm/interfaces/core/doctor_interface.py +102 -0
- womm/interfaces/dependencies/__init__.py +28 -0
- womm/interfaces/dependencies/deps_interface.py +160 -0
- womm/interfaces/project/__init__.py +36 -0
- womm/interfaces/project/create_interface.py +162 -0
- womm/interfaces/project/detection_interface.py +181 -0
- womm/interfaces/project/manager_interface.py +99 -0
- womm/interfaces/project/setup_interface.py +477 -0
- womm/interfaces/project/template_store_interface.py +196 -0
- womm/interfaces/system/__init__.py +32 -0
- womm/interfaces/system/detector_interface.py +84 -0
- womm/interfaces/system/environment_interface.py +110 -0
- womm/interfaces/system/path_interface.py +570 -0
- womm/services/__init__.py +70 -0
- womm/services/common/__init__.py +33 -0
- womm/services/common/base_validation_service.py +450 -0
- womm/services/common/command_runner_service.py +647 -0
- womm/services/common/file_scanner_service.py +483 -0
- womm/services/common/security_validator_service.py +348 -0
- womm/services/context/__init__.py +37 -0
- womm/services/context/backup_entries.py +148 -0
- womm/services/context/parameters.py +515 -0
- womm/services/context/registry_paths.py +56 -0
- womm/services/context/registry_service.py +573 -0
- womm/services/context/validation_service.py +691 -0
- womm/services/dependencies/__init__.py +29 -0
- womm/services/dependencies/probe.py +102 -0
- womm/services/project/__init__.py +48 -0
- womm/services/project/copier_project_creation_service.py +111 -0
- womm/services/project/destination_guard.py +96 -0
- womm/services/project/detection_service.py +354 -0
- womm/services/project/env_utils.py +333 -0
- womm/services/project/javascript_environment_service.py +348 -0
- womm/services/project/python_environment_service.py +245 -0
- womm/services/project/setup_profile_resolver.py +146 -0
- womm/services/project/template_store_service.py +344 -0
- womm/services/project/validation_service.py +418 -0
- womm/services/system/__init__.py +32 -0
- womm/services/system/detector_service.py +704 -0
- womm/services/system/environment_service.py +494 -0
- womm/services/system/path_service.py +642 -0
- womm/shared/__init__.py +30 -0
- womm/shared/configs/__init__.py +51 -0
- womm/shared/configs/context/__init__.py +43 -0
- womm/shared/configs/context/context_config.py +125 -0
- womm/shared/configs/context/context_file_types_config.py +159 -0
- womm/shared/configs/context/context_limits_config.py +187 -0
- womm/shared/configs/context/context_paths_config.py +115 -0
- womm/shared/configs/context/context_types_config.py +65 -0
- womm/shared/configs/context/script_config.py +219 -0
- womm/shared/configs/dependencies/__init__.py +32 -0
- womm/shared/configs/dependencies/runtime_config.py +46 -0
- womm/shared/configs/dependencies/runtime_package_manager_config.py +48 -0
- womm/shared/configs/logging_config.py +89 -0
- womm/shared/configs/project/__init__.py +33 -0
- womm/shared/configs/project/project_config.py +109 -0
- womm/shared/configs/project/project_structure_config.py +88 -0
- womm/shared/configs/project/python_project_config.py +165 -0
- womm/shared/configs/security/__init__.py +26 -0
- womm/shared/configs/security/security_patterns_config.py +242 -0
- womm/shared/configs/system/__init__.py +28 -0
- womm/shared/configs/system/system_detector_config.py +210 -0
- womm/shared/configs/system/system_environment_config.py +101 -0
- womm/shared/models/__init__.py +13 -0
- womm/shared/models/template_source.py +65 -0
- womm/shared/paths.py +192 -0
- womm/shared/results/__init__.py +138 -0
- womm/shared/results/base.py +85 -0
- womm/shared/results/command_results.py +61 -0
- womm/shared/results/context_results.py +345 -0
- womm/shared/results/dependency_results.py +110 -0
- womm/shared/results/doctor_results.py +41 -0
- womm/shared/results/file_results.py +97 -0
- womm/shared/results/project_results.py +163 -0
- womm/shared/results/security_results.py +128 -0
- womm/shared/results/system_results.py +268 -0
- womm/shared/results/template_results.py +43 -0
- womm/shared/runtime.py +36 -0
- womm/ui/__init__.py +31 -0
- womm/ui/common/__init__.py +39 -0
- womm/ui/common/interactive_menu.py +246 -0
- womm/ui/common/logging.py +184 -0
- womm/ui/common/prompts.py +93 -0
- womm/ui/context/__init__.py +31 -0
- womm/ui/context/display.py +485 -0
- womm/ui/context/menu_display.py +189 -0
- womm/ui/context/wizard.py +557 -0
- womm/ui/project/__init__.py +42 -0
- womm/ui/project/create/create_completion_summaries.py +55 -0
- womm/ui/project/project_wizard.py +174 -0
- womm/ui/project/setup/setup_completion_summaries.py +111 -0
- womm/ui/project/templates/template_store_display.py +128 -0
- womm/ui/system/__init__.py +60 -0
- womm/ui/system/display.py +531 -0
- womm/ui/system/path_display.py +387 -0
- womm/utils/__init__.py +23 -0
- womm/utils/common/__init__.py +49 -0
- womm/utils/common/file_scanner_utils.py +110 -0
- womm/utils/common/path_resolver_utils.py +127 -0
- womm/utils/common/safe_fs_utils.py +135 -0
- womm/utils/context/__init__.py +54 -0
- womm/utils/context/core_utils.py +345 -0
- womm/utils/context/icon_utils.py +259 -0
- womm/utils/project/__init__.py +106 -0
- womm/utils/project/asset_utils.py +154 -0
- womm/utils/project/core_utils.py +391 -0
- womm/utils/project/file_utils.py +494 -0
- womm/utils/project/platform_utils.py +170 -0
- womm/utils/project/validation_utils.py +273 -0
- womm/utils/security/__init__.py +46 -0
- womm/utils/security/security_validation_utils.py +258 -0
- womm/utils/system/__init__.py +69 -0
- womm/utils/system/detector_utils.py +299 -0
- womm/utils/system/environment_utils.py +172 -0
- womm/utils/system/path_utils.py +101 -0
- womm_cli-4.0.0.dist-info/METADATA +203 -0
- womm_cli-4.0.0.dist-info/RECORD +218 -0
- womm_cli-4.0.0.dist-info/WHEEL +4 -0
- womm_cli-4.0.0.dist-info/entry_points.txt +2 -0
- womm_cli-4.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# SCRIPT DETECTOR INTERFACE - Context Script Detection
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Script type detection and configuration for context menu entries.
|
|
9
|
+
|
|
10
|
+
This module provides automatic detection of script types and appropriate
|
|
11
|
+
configuration including icons and command building.
|
|
12
|
+
|
|
13
|
+
This interface never raises: :meth:`get_script_info` returns a typed Result.
|
|
14
|
+
The lookup helpers it composes are total functions over ``ScriptConfig``.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
# ///////////////////////////////////////////////////////////////
|
|
20
|
+
# IMPORTS
|
|
21
|
+
# ///////////////////////////////////////////////////////////////
|
|
22
|
+
# Standard library imports
|
|
23
|
+
import logging
|
|
24
|
+
import os
|
|
25
|
+
import shutil
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
from typing import ClassVar
|
|
28
|
+
|
|
29
|
+
# Local imports
|
|
30
|
+
from ...exceptions.common import CommandServiceError
|
|
31
|
+
from ...services import CommandRunnerService
|
|
32
|
+
from ...shared.configs.context import ScriptConfig
|
|
33
|
+
from ...shared.results import ScriptInfoResult
|
|
34
|
+
|
|
35
|
+
# ///////////////////////////////////////////////////////////////
|
|
36
|
+
# MAIN CLASS
|
|
37
|
+
# ///////////////////////////////////////////////////////////////
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class ScriptType:
|
|
41
|
+
"""Script type enumeration and configuration."""
|
|
42
|
+
|
|
43
|
+
PYTHON = ScriptConfig.TYPE_PYTHON
|
|
44
|
+
POWERSHELL = ScriptConfig.TYPE_POWERSHELL
|
|
45
|
+
BATCH = ScriptConfig.TYPE_BATCH
|
|
46
|
+
EXECUTABLE = ScriptConfig.TYPE_EXECUTABLE
|
|
47
|
+
UNKNOWN = ScriptConfig.TYPE_UNKNOWN
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class ContextScriptDetectorInterface:
|
|
51
|
+
"""Detect script types and provide appropriate configuration."""
|
|
52
|
+
|
|
53
|
+
# Use configuration from ScriptConfig
|
|
54
|
+
EXTENSIONS: ClassVar[dict[str, str]] = ScriptConfig.EXTENSION_TO_TYPE
|
|
55
|
+
DEFAULT_ICONS: ClassVar[dict[str, str | None]] = ScriptConfig.DEFAULT_ICONS
|
|
56
|
+
CONTEXT_PARAMS: ClassVar[dict[str, str]] = ScriptConfig.CONTEXT_PARAMETERS
|
|
57
|
+
|
|
58
|
+
# ///////////////////////////////////////////////////////////////
|
|
59
|
+
# PUBLIC METHODS
|
|
60
|
+
# ///////////////////////////////////////////////////////////////
|
|
61
|
+
|
|
62
|
+
@classmethod
|
|
63
|
+
def detect_type(cls, file_path: str) -> str:
|
|
64
|
+
"""
|
|
65
|
+
Detect script type from file extension.
|
|
66
|
+
|
|
67
|
+
Total function: an empty or unrecognized path yields ``ScriptType.UNKNOWN``.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
file_path: Path to the script file
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
Script type string
|
|
74
|
+
"""
|
|
75
|
+
if not file_path:
|
|
76
|
+
return ScriptType.UNKNOWN
|
|
77
|
+
|
|
78
|
+
ext = Path(file_path).suffix.lower()
|
|
79
|
+
return cls.EXTENSIONS.get(ext, ScriptType.UNKNOWN)
|
|
80
|
+
|
|
81
|
+
@classmethod
|
|
82
|
+
def get_default_icon(cls, script_type: str) -> str | None:
|
|
83
|
+
"""
|
|
84
|
+
Get default icon for script type.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
script_type: Type of script
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
Default icon path, or None when the type has no default
|
|
91
|
+
"""
|
|
92
|
+
return cls.DEFAULT_ICONS.get(script_type)
|
|
93
|
+
|
|
94
|
+
@classmethod
|
|
95
|
+
def get_context_params(cls, script_type: str) -> str:
|
|
96
|
+
"""
|
|
97
|
+
Get context parameters for script type.
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
script_type: Type of script
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
Context parameters string (``%V`` when the type is unknown)
|
|
104
|
+
"""
|
|
105
|
+
return cls.CONTEXT_PARAMS.get(script_type, "%V")
|
|
106
|
+
|
|
107
|
+
@classmethod
|
|
108
|
+
def get_script_info(cls, file_path: str) -> ScriptInfoResult:
|
|
109
|
+
"""
|
|
110
|
+
Get comprehensive script information.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
file_path: Path to the script file
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
ScriptInfoResult: detected type, icon, context params and the
|
|
117
|
+
execution command; failure carries the error.
|
|
118
|
+
"""
|
|
119
|
+
if not file_path:
|
|
120
|
+
return ScriptInfoResult(
|
|
121
|
+
success=False, error="File path cannot be None or empty"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
script_type = cls.detect_type(file_path)
|
|
125
|
+
context_params = cls.get_context_params(script_type)
|
|
126
|
+
|
|
127
|
+
try:
|
|
128
|
+
command = cls._build_command(script_type, file_path, context_params)
|
|
129
|
+
except OSError as e:
|
|
130
|
+
return ScriptInfoResult(
|
|
131
|
+
success=False,
|
|
132
|
+
script_path=file_path,
|
|
133
|
+
script_type=script_type,
|
|
134
|
+
error=f"Could not resolve script path: {e}",
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
return ScriptInfoResult(
|
|
138
|
+
success=True,
|
|
139
|
+
message=f"Detected {script_type} script",
|
|
140
|
+
script_path=file_path,
|
|
141
|
+
script_type=script_type,
|
|
142
|
+
extension=Path(file_path).suffix.lower(),
|
|
143
|
+
default_icon=cls.get_default_icon(script_type),
|
|
144
|
+
context_params=context_params,
|
|
145
|
+
command=command,
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
# ///////////////////////////////////////////////////////////////
|
|
149
|
+
# PRIVATE METHODS
|
|
150
|
+
# ///////////////////////////////////////////////////////////////
|
|
151
|
+
|
|
152
|
+
@classmethod
|
|
153
|
+
def _resolve_python_interpreter(cls) -> str | None:
|
|
154
|
+
"""Return the first configured interpreter meeting the minimum version."""
|
|
155
|
+
command_runner = CommandRunnerService()
|
|
156
|
+
|
|
157
|
+
for cmd in ScriptConfig.PYTHON_INTERPRETERS:
|
|
158
|
+
try:
|
|
159
|
+
if not command_runner.check_command_available(cmd).is_available:
|
|
160
|
+
continue
|
|
161
|
+
result = command_runner.run([cmd, "--version"])
|
|
162
|
+
if result.returncode != 0 or not result.stdout.strip():
|
|
163
|
+
continue
|
|
164
|
+
version = result.stdout.strip().split()[1]
|
|
165
|
+
version_parts = [int(x) for x in version.split(".")]
|
|
166
|
+
except (CommandServiceError, IndexError, ValueError) as e:
|
|
167
|
+
logging.getLogger(__name__).warning(
|
|
168
|
+
f"Failed to probe Python interpreter {cmd}: {e}"
|
|
169
|
+
)
|
|
170
|
+
continue
|
|
171
|
+
|
|
172
|
+
if version_parts >= ScriptConfig.MINIMUM_PYTHON_VERSION:
|
|
173
|
+
python_exe = shutil.which(cmd)
|
|
174
|
+
if python_exe:
|
|
175
|
+
return python_exe
|
|
176
|
+
|
|
177
|
+
return None
|
|
178
|
+
|
|
179
|
+
@classmethod
|
|
180
|
+
def _build_command(
|
|
181
|
+
cls, script_type: str, script_path: str, context_params: str
|
|
182
|
+
) -> str:
|
|
183
|
+
"""
|
|
184
|
+
Build the execution command for a script type.
|
|
185
|
+
|
|
186
|
+
Raises:
|
|
187
|
+
OSError: If the script path cannot be resolved to an absolute path.
|
|
188
|
+
"""
|
|
189
|
+
script_abs_path = os.path.abspath(script_path)
|
|
190
|
+
|
|
191
|
+
if script_type == ScriptType.PYTHON:
|
|
192
|
+
python_exe = cls._resolve_python_interpreter()
|
|
193
|
+
if python_exe:
|
|
194
|
+
return f'"{python_exe}" "{script_abs_path}" "{context_params}"'
|
|
195
|
+
# Fallback: try py launcher directly
|
|
196
|
+
return (
|
|
197
|
+
f"{ScriptConfig.PYTHON_LAUNCHER_FALLBACK} "
|
|
198
|
+
f'"{script_abs_path}" "{context_params}"'
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
if script_type == ScriptType.POWERSHELL:
|
|
202
|
+
return (
|
|
203
|
+
f"{ScriptConfig.POWERSHELL_COMMAND_TEMPLATE} "
|
|
204
|
+
f'"{script_abs_path}" "{context_params}"'
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
# Batch, executable, and unknown types are executed directly
|
|
208
|
+
return f'"{script_abs_path}" "{context_params}"'
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# CONTEXT SCRIPT REGISTRAR - Registration workflow for a single script
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Registration workflow for one script in the Windows context menu.
|
|
9
|
+
|
|
10
|
+
``ContextScriptRegistrar`` owns the sequence validate -> detect -> resolve icon
|
|
11
|
+
-> build command -> write registry entries. It receives its collaborators so it
|
|
12
|
+
stays testable, and like the rest of the interface layer it never raises: every
|
|
13
|
+
outcome is a ``ScriptRegistrationResult``.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# IMPORTS
|
|
20
|
+
# ///////////////////////////////////////////////////////////////
|
|
21
|
+
# Standard library imports
|
|
22
|
+
import logging
|
|
23
|
+
from typing import cast
|
|
24
|
+
|
|
25
|
+
# Local imports
|
|
26
|
+
from ...services.context.parameters import ContextParameters
|
|
27
|
+
from ...services.context.registry_paths import context_type_from_registry_path
|
|
28
|
+
from ...shared.results import ScriptRegistrationResult
|
|
29
|
+
from .script_detector_interface import ContextScriptDetectorInterface
|
|
30
|
+
|
|
31
|
+
# ///////////////////////////////////////////////////////////////
|
|
32
|
+
# CLASSES
|
|
33
|
+
# ///////////////////////////////////////////////////////////////
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class ContextScriptRegistrar:
|
|
37
|
+
"""Registers a single script in the Windows context menu."""
|
|
38
|
+
|
|
39
|
+
def __init__(
|
|
40
|
+
self,
|
|
41
|
+
validation_service,
|
|
42
|
+
icon_manager,
|
|
43
|
+
registry_service,
|
|
44
|
+
logger: logging.Logger | None = None,
|
|
45
|
+
):
|
|
46
|
+
"""
|
|
47
|
+
Initialize the registrar with the collaborators it drives.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
validation_service: ContextValidationService-like collaborator
|
|
51
|
+
icon_manager: ContextIconResolver-like collaborator
|
|
52
|
+
registry_service: ContextRegistryService-like collaborator
|
|
53
|
+
logger: Logger for non-fatal findings
|
|
54
|
+
"""
|
|
55
|
+
self.validation_service = validation_service
|
|
56
|
+
self.icon_manager = icon_manager
|
|
57
|
+
self.registry_service = registry_service
|
|
58
|
+
self.logger = logger or logging.getLogger(__name__)
|
|
59
|
+
|
|
60
|
+
# ///////////////////////////////////////////////////////////////
|
|
61
|
+
# PUBLIC METHODS
|
|
62
|
+
# ///////////////////////////////////////////////////////////////
|
|
63
|
+
|
|
64
|
+
def register(
|
|
65
|
+
self,
|
|
66
|
+
script_path: str,
|
|
67
|
+
label: str,
|
|
68
|
+
icon: str | None = None,
|
|
69
|
+
dry_run: bool = False,
|
|
70
|
+
context_params: ContextParameters | None = None,
|
|
71
|
+
) -> ScriptRegistrationResult:
|
|
72
|
+
"""
|
|
73
|
+
Register a script in the Windows context menu.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
script_path: Path to the script or executable
|
|
77
|
+
label: Display name in context menu
|
|
78
|
+
icon: Icon path or 'auto' for auto-detection
|
|
79
|
+
dry_run: If True, show what would be done without making changes
|
|
80
|
+
context_params: Context parameters for registration
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
ScriptRegistrationResult: Result of the registration attempt
|
|
84
|
+
"""
|
|
85
|
+
try:
|
|
86
|
+
if not script_path:
|
|
87
|
+
raise ValueError("Script path cannot be None or empty")
|
|
88
|
+
if not label:
|
|
89
|
+
raise ValueError("Label cannot be None or empty")
|
|
90
|
+
|
|
91
|
+
self._validate_command_parameters(script_path, label, icon)
|
|
92
|
+
|
|
93
|
+
script_info = ContextScriptDetectorInterface.get_script_info(script_path)
|
|
94
|
+
if not script_info.success:
|
|
95
|
+
raise RuntimeError(f"Failed to detect script type: {script_info.error}")
|
|
96
|
+
|
|
97
|
+
icon_path = self._resolve_icon(script_path, icon, script_info.default_icon)
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
registry_key_name = self.registry_service.generate_registry_key_name(
|
|
101
|
+
script_path
|
|
102
|
+
)
|
|
103
|
+
except Exception as e:
|
|
104
|
+
raise RuntimeError(f"Failed to generate registry key name: {e}") from e
|
|
105
|
+
|
|
106
|
+
command = script_info.command
|
|
107
|
+
context_params = context_params or self._default_context_params()
|
|
108
|
+
self._validate_context_params(context_params)
|
|
109
|
+
|
|
110
|
+
# Build final command for display (use first context type for dry-run)
|
|
111
|
+
context_types = list(context_params.context_types)
|
|
112
|
+
final_command = (
|
|
113
|
+
context_params.build_command(command, context_types[0])
|
|
114
|
+
if context_types
|
|
115
|
+
else command
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
if dry_run:
|
|
119
|
+
return ScriptRegistrationResult(
|
|
120
|
+
success=True,
|
|
121
|
+
dry_run=True,
|
|
122
|
+
script_path=script_path,
|
|
123
|
+
script_type=script_info.script_type,
|
|
124
|
+
label=label,
|
|
125
|
+
icon_path=icon_path,
|
|
126
|
+
registry_key=registry_key_name,
|
|
127
|
+
command=final_command,
|
|
128
|
+
context_info=context_params.get_description(),
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
success_count, total_paths = self._write_entries(
|
|
132
|
+
context_params, registry_key_name, command, label, icon_path
|
|
133
|
+
)
|
|
134
|
+
if success_count != total_paths:
|
|
135
|
+
raise RuntimeError(
|
|
136
|
+
f"Failed to add registry entries ({success_count}/{total_paths} succeeded)"
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
return ScriptRegistrationResult(
|
|
140
|
+
success=True,
|
|
141
|
+
script_path=script_path,
|
|
142
|
+
script_type=script_info.script_type,
|
|
143
|
+
label=label,
|
|
144
|
+
icon_path=icon_path,
|
|
145
|
+
registry_key=registry_key_name,
|
|
146
|
+
command=final_command,
|
|
147
|
+
context_info=context_params.get_description(),
|
|
148
|
+
success_count=success_count,
|
|
149
|
+
total_paths=total_paths,
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
except (ValueError, RuntimeError) as e:
|
|
153
|
+
return ScriptRegistrationResult(success=False, error=str(e))
|
|
154
|
+
except Exception as e:
|
|
155
|
+
return ScriptRegistrationResult(
|
|
156
|
+
success=False,
|
|
157
|
+
error=f"Unexpected error during script registration: {e}",
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
# ///////////////////////////////////////////////////////////////
|
|
161
|
+
# PRIVATE METHODS
|
|
162
|
+
# ///////////////////////////////////////////////////////////////
|
|
163
|
+
|
|
164
|
+
def _validate_command_parameters(
|
|
165
|
+
self, script_path: str, label: str, icon: str | None
|
|
166
|
+
) -> None:
|
|
167
|
+
"""Run the comprehensive parameter validation, raising on rejection."""
|
|
168
|
+
try:
|
|
169
|
+
validation_result = self.validation_service.validate_command_parameters(
|
|
170
|
+
script_path, label, icon
|
|
171
|
+
)
|
|
172
|
+
except Exception as e:
|
|
173
|
+
raise ValueError(f"Validation process failed: {e}") from e
|
|
174
|
+
|
|
175
|
+
if not validation_result.success:
|
|
176
|
+
raise ValueError(validation_result.error or "Validation failed")
|
|
177
|
+
|
|
178
|
+
def _resolve_icon(
|
|
179
|
+
self, script_path: str, icon: str | None, default_icon: str | None
|
|
180
|
+
) -> str | None:
|
|
181
|
+
"""Resolve the icon, degrading to the type default then to ``None``."""
|
|
182
|
+
try:
|
|
183
|
+
icon_path = self.icon_manager.resolve_icon(icon or "auto", script_path)
|
|
184
|
+
except (ValueError, OSError) as e:
|
|
185
|
+
self.logger.warning(f"Failed to resolve icon for {script_path}: {e}")
|
|
186
|
+
return None
|
|
187
|
+
|
|
188
|
+
if icon_path is None and icon and icon.lower() != "auto":
|
|
189
|
+
return default_icon
|
|
190
|
+
return icon_path
|
|
191
|
+
|
|
192
|
+
@staticmethod
|
|
193
|
+
def _default_context_params() -> ContextParameters:
|
|
194
|
+
"""Default context parameters used when the caller supplies none."""
|
|
195
|
+
return ContextParameters.from_flags(
|
|
196
|
+
root=False,
|
|
197
|
+
file=False,
|
|
198
|
+
files=False,
|
|
199
|
+
background=True,
|
|
200
|
+
file_types=None,
|
|
201
|
+
extensions=None,
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
def _validate_context_params(self, context_params: ContextParameters) -> None:
|
|
205
|
+
"""Validate context parameters, raising on errors and logging warnings."""
|
|
206
|
+
try:
|
|
207
|
+
validation = context_params.validate_parameters()
|
|
208
|
+
except Exception as e:
|
|
209
|
+
raise ValueError(f"Context parameter validation process failed: {e}") from e
|
|
210
|
+
|
|
211
|
+
if not cast(bool, validation.get("valid", False)):
|
|
212
|
+
errors = cast("list[str]", validation.get("errors", []))
|
|
213
|
+
raise ValueError(
|
|
214
|
+
f"Context parameter validation failed: {'; '.join(errors)}"
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
warnings = cast("list[str]", validation.get("warnings", []))
|
|
218
|
+
if warnings:
|
|
219
|
+
self.logger.warning(f"Context parameter warnings: {'; '.join(warnings)}")
|
|
220
|
+
|
|
221
|
+
def _write_entries(
|
|
222
|
+
self,
|
|
223
|
+
context_params: ContextParameters,
|
|
224
|
+
registry_key_name: str,
|
|
225
|
+
command: str,
|
|
226
|
+
label: str,
|
|
227
|
+
icon_path: str | None,
|
|
228
|
+
) -> tuple[int, int]:
|
|
229
|
+
"""Write one registry entry per context path; return (written, total)."""
|
|
230
|
+
try:
|
|
231
|
+
registry_paths = context_params.get_registry_paths()
|
|
232
|
+
except Exception as e:
|
|
233
|
+
raise RuntimeError(f"Failed to get registry paths: {e}") from e
|
|
234
|
+
|
|
235
|
+
success_count = 0
|
|
236
|
+
for registry_path in registry_paths:
|
|
237
|
+
full_path = f"{registry_path}\\{registry_key_name}"
|
|
238
|
+
entry_command = context_params.build_command(
|
|
239
|
+
command, context_type_from_registry_path(registry_path)
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
try:
|
|
243
|
+
add_result = self.registry_service.add_context_menu_entry(
|
|
244
|
+
full_path,
|
|
245
|
+
entry_command,
|
|
246
|
+
label,
|
|
247
|
+
icon_path,
|
|
248
|
+
)
|
|
249
|
+
entry_success = add_result.success
|
|
250
|
+
except Exception as e:
|
|
251
|
+
self.logger.warning(f"Failed to add registry entry {full_path}: {e}")
|
|
252
|
+
entry_success = False
|
|
253
|
+
|
|
254
|
+
if entry_success:
|
|
255
|
+
success_count += 1
|
|
256
|
+
|
|
257
|
+
return success_count, len(registry_paths)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
# ///////////////////////////////////////////////////////////////
|
|
261
|
+
# PUBLIC API
|
|
262
|
+
# ///////////////////////////////////////////////////////////////
|
|
263
|
+
|
|
264
|
+
__all__ = ["ContextScriptRegistrar"]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# INTERFACES CORE - Core Interfaces
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Core interfaces for Works On My Machine.
|
|
9
|
+
|
|
10
|
+
This package contains cross-cutting interface modules that do not belong
|
|
11
|
+
to a single domain (e.g. the runtime diagnostic).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
# ///////////////////////////////////////////////////////////////
|
|
17
|
+
# IMPORTS
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# Local imports
|
|
20
|
+
from .doctor_interface import DoctorInterface
|
|
21
|
+
|
|
22
|
+
# ///////////////////////////////////////////////////////////////
|
|
23
|
+
# PUBLIC API
|
|
24
|
+
# ///////////////////////////////////////////////////////////////
|
|
25
|
+
|
|
26
|
+
__all__ = ["DoctorInterface"]
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# DOCTOR INTERFACE - Runtime Diagnostic Interface
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Doctor Interface for Works On My Machine.
|
|
9
|
+
|
|
10
|
+
Gathers the read-only runtime diagnostic (version, executable,
|
|
11
|
+
data directory, PATH registration, context menu status) into a
|
|
12
|
+
``DoctorResult``. This interface carries no UI: it does not print or log —
|
|
13
|
+
the command layer owns presentation. It never modifies user configuration.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# IMPORTS
|
|
20
|
+
# ///////////////////////////////////////////////////////////////
|
|
21
|
+
# Standard library imports
|
|
22
|
+
import os
|
|
23
|
+
import shutil
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
|
|
26
|
+
# Local imports
|
|
27
|
+
from ..._version import __version__
|
|
28
|
+
from ...shared.paths import womm_data_path
|
|
29
|
+
from ...shared.results import DoctorResult
|
|
30
|
+
from ...shared.runtime import get_womm_executable
|
|
31
|
+
from ..context import ContextMenuInterface
|
|
32
|
+
|
|
33
|
+
# ///////////////////////////////////////////////////////////////
|
|
34
|
+
# MAIN CLASS
|
|
35
|
+
# ///////////////////////////////////////////////////////////////
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class DoctorInterface:
|
|
39
|
+
"""Gathers the runtime diagnostic and returns a Result.
|
|
40
|
+
|
|
41
|
+
Pure orchestration: no UI, no re-raise. Every probe is best-effort —
|
|
42
|
+
an unreachable context menu registry is reported inline rather than
|
|
43
|
+
failing the whole diagnostic.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def diagnose(self) -> DoctorResult:
|
|
47
|
+
"""
|
|
48
|
+
Report the installed runtime without changing user configuration.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
DoctorResult: Always successful; individual probes degrade to
|
|
52
|
+
an inline status string rather than failing the report.
|
|
53
|
+
"""
|
|
54
|
+
data_dir = womm_data_path()
|
|
55
|
+
|
|
56
|
+
return DoctorResult(
|
|
57
|
+
success=True,
|
|
58
|
+
message="Runtime diagnostic completed successfully",
|
|
59
|
+
version=__version__,
|
|
60
|
+
executable=str(get_womm_executable()),
|
|
61
|
+
data_dir=str(data_dir),
|
|
62
|
+
data_dir_writable=self._is_writable(data_dir),
|
|
63
|
+
path_command=shutil.which("womm"),
|
|
64
|
+
context_menu_status=self._context_menu_status(),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
# ///////////////////////////////////////////////////////////////
|
|
68
|
+
# PRIVATE METHODS
|
|
69
|
+
# ///////////////////////////////////////////////////////////////
|
|
70
|
+
|
|
71
|
+
@staticmethod
|
|
72
|
+
def _is_writable(directory: Path) -> bool:
|
|
73
|
+
"""Check whether ``directory`` or its closest existing parent is writable."""
|
|
74
|
+
candidate = directory
|
|
75
|
+
while not candidate.exists() and candidate != candidate.parent:
|
|
76
|
+
candidate = candidate.parent
|
|
77
|
+
return candidate.is_dir() and os.access(candidate, os.W_OK)
|
|
78
|
+
|
|
79
|
+
@staticmethod
|
|
80
|
+
def _context_menu_status() -> str:
|
|
81
|
+
"""Return context-menu entry counts without modifying the registry."""
|
|
82
|
+
try:
|
|
83
|
+
result = ContextMenuInterface().list_entries()
|
|
84
|
+
except OSError as error:
|
|
85
|
+
return f"unavailable ({error})"
|
|
86
|
+
|
|
87
|
+
if not result.success:
|
|
88
|
+
return f"unavailable ({result.error or 'unknown error'})"
|
|
89
|
+
|
|
90
|
+
entries = result.entries_by_type or {}
|
|
91
|
+
return (
|
|
92
|
+
f"{result.total_entries} entries "
|
|
93
|
+
f"(directory: {entries.get('directory', 0)}, "
|
|
94
|
+
f"background: {entries.get('background', 0)})"
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
# ///////////////////////////////////////////////////////////////
|
|
99
|
+
# PUBLIC API
|
|
100
|
+
# ///////////////////////////////////////////////////////////////
|
|
101
|
+
|
|
102
|
+
__all__ = ["DoctorInterface"]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# INTERFACES DEPENDENCIES - Dependencies Interfaces
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Dependencies interfaces for Works On My Machine.
|
|
9
|
+
|
|
10
|
+
This package contains dependency management interfaces that orchestrate services
|
|
11
|
+
for runtimes, package managers, and development tools.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
# ///////////////////////////////////////////////////////////////
|
|
17
|
+
# IMPORTS
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# Local imports
|
|
20
|
+
from .deps_interface import DepsInterface
|
|
21
|
+
|
|
22
|
+
# ///////////////////////////////////////////////////////////////
|
|
23
|
+
# PUBLIC API
|
|
24
|
+
# ///////////////////////////////////////////////////////////////
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"DepsInterface",
|
|
28
|
+
]
|