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,686 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# CONTEXT MENU MANAGER - Windows Context Menu Management
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Context menu manager.
|
|
9
|
+
|
|
10
|
+
This module orchestrates context menu operations using the modular architecture.
|
|
11
|
+
It coordinates ScriptDetector, IconManager, and ContextRegistryService to provide
|
|
12
|
+
a unified interface for context menu management.
|
|
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
|
+
|
|
24
|
+
# Local imports
|
|
25
|
+
from ...exceptions.context import ContextServiceError
|
|
26
|
+
from ...services import (
|
|
27
|
+
ContextParameters,
|
|
28
|
+
ContextRegistryService,
|
|
29
|
+
ContextValidationService,
|
|
30
|
+
)
|
|
31
|
+
from ...services.context.backup_entries import ContextBackupEntriesReader
|
|
32
|
+
from ...shared.configs.context import ContextTypesConfig
|
|
33
|
+
from ...shared.results import (
|
|
34
|
+
BackupDataResult,
|
|
35
|
+
BackupFileListResult,
|
|
36
|
+
ContextBackupResult,
|
|
37
|
+
ContextEntriesResult,
|
|
38
|
+
ContextRestoreResult,
|
|
39
|
+
ContextSetupResult,
|
|
40
|
+
ContextValidationResult,
|
|
41
|
+
ScriptInfoResult,
|
|
42
|
+
ScriptRegistrationResult,
|
|
43
|
+
ScriptUnregistrationResult,
|
|
44
|
+
ScriptValidationResult,
|
|
45
|
+
)
|
|
46
|
+
from ...shared.runtime import get_womm_executable
|
|
47
|
+
from ...utils.context import ContextIconResolver
|
|
48
|
+
from ...utils.security import resolve_backup_name
|
|
49
|
+
from .registry_interface import ContextRegistryInterface
|
|
50
|
+
from .script_detector_interface import ContextScriptDetectorInterface, ScriptType
|
|
51
|
+
from .script_registrar import ContextScriptRegistrar
|
|
52
|
+
|
|
53
|
+
# ///////////////////////////////////////////////////////////////
|
|
54
|
+
# MAIN CLASS
|
|
55
|
+
# ///////////////////////////////////////////////////////////////
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class ContextMenuInterface:
|
|
59
|
+
"""Context menu manager - orchestrates all context menu operations."""
|
|
60
|
+
|
|
61
|
+
def __init__(self):
|
|
62
|
+
"""Initialize the context menu manager with all required components."""
|
|
63
|
+
self.logger = logging.getLogger(__name__)
|
|
64
|
+
self._script_detector: ContextScriptDetectorInterface | None = None
|
|
65
|
+
self._icon_manager: ContextIconResolver | None = None
|
|
66
|
+
self._registry_service: ContextRegistryService | None = None
|
|
67
|
+
self._backup_manager: ContextRegistryInterface | None = None
|
|
68
|
+
self._validation_service: ContextValidationService | None = None
|
|
69
|
+
self._entries_reader: ContextBackupEntriesReader | None = None
|
|
70
|
+
|
|
71
|
+
# ///////////////////////////////////////////////////////////////
|
|
72
|
+
# SERVICE PROPERTIES (LAZY INITIALIZATION)
|
|
73
|
+
# ///////////////////////////////////////////////////////////////
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def script_detector(self) -> ContextScriptDetectorInterface:
|
|
77
|
+
"""Lazy load ContextScriptDetectorInterface when needed."""
|
|
78
|
+
if self._script_detector is None:
|
|
79
|
+
self._script_detector = ContextScriptDetectorInterface()
|
|
80
|
+
return self._script_detector
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def icon_manager(self) -> ContextIconResolver:
|
|
84
|
+
"""Lazy load ContextIconResolver when needed."""
|
|
85
|
+
if self._icon_manager is None:
|
|
86
|
+
self._icon_manager = ContextIconResolver()
|
|
87
|
+
return self._icon_manager
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def registry_service(self) -> ContextRegistryService:
|
|
91
|
+
"""Lazy load ContextRegistryService when needed."""
|
|
92
|
+
if self._registry_service is None:
|
|
93
|
+
self._registry_service = ContextRegistryService()
|
|
94
|
+
return self._registry_service
|
|
95
|
+
|
|
96
|
+
@property
|
|
97
|
+
def backup_manager(self) -> ContextRegistryInterface:
|
|
98
|
+
"""Lazy load ContextRegistryInterface when needed."""
|
|
99
|
+
if self._backup_manager is None:
|
|
100
|
+
self._backup_manager = ContextRegistryInterface()
|
|
101
|
+
return self._backup_manager
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def validation_service(self) -> ContextValidationService:
|
|
105
|
+
"""Lazy load ContextValidationService when needed."""
|
|
106
|
+
if self._validation_service is None:
|
|
107
|
+
self._validation_service = ContextValidationService()
|
|
108
|
+
return self._validation_service
|
|
109
|
+
|
|
110
|
+
@property
|
|
111
|
+
def _backup_entries_reader(self) -> ContextBackupEntriesReader:
|
|
112
|
+
"""Lazy load the backup entries reader when needed."""
|
|
113
|
+
if self._entries_reader is None:
|
|
114
|
+
self._entries_reader = ContextBackupEntriesReader(self.logger)
|
|
115
|
+
return self._entries_reader
|
|
116
|
+
|
|
117
|
+
# ///////////////////////////////////////////////////////////////
|
|
118
|
+
# PUBLIC METHODS
|
|
119
|
+
# ///////////////////////////////////////////////////////////////
|
|
120
|
+
|
|
121
|
+
def register_script(
|
|
122
|
+
self,
|
|
123
|
+
script_path: str,
|
|
124
|
+
label: str,
|
|
125
|
+
icon: str | None = None,
|
|
126
|
+
dry_run: bool = False,
|
|
127
|
+
context_params: ContextParameters | None = None,
|
|
128
|
+
) -> ScriptRegistrationResult:
|
|
129
|
+
"""
|
|
130
|
+
Register a script in the Windows context menu.
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
script_path: Path to the script or executable
|
|
134
|
+
label: Display name in context menu
|
|
135
|
+
icon: Icon path or 'auto' for auto-detection
|
|
136
|
+
dry_run: If True, show what would be done without making changes
|
|
137
|
+
context_params: Context parameters for registration
|
|
138
|
+
|
|
139
|
+
Returns:
|
|
140
|
+
ScriptRegistrationResult: Result of the registration attempt
|
|
141
|
+
"""
|
|
142
|
+
return self._registrar().register(
|
|
143
|
+
script_path, label, icon, dry_run, context_params
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
# ///////////////////////////////////////////////////////////////
|
|
147
|
+
# PRIVATE METHODS
|
|
148
|
+
# ///////////////////////////////////////////////////////////////
|
|
149
|
+
|
|
150
|
+
def _registrar(self) -> ContextScriptRegistrar:
|
|
151
|
+
"""Build a registrar bound to this interface's current collaborators."""
|
|
152
|
+
return ContextScriptRegistrar(
|
|
153
|
+
validation_service=self.validation_service,
|
|
154
|
+
icon_manager=self.icon_manager,
|
|
155
|
+
registry_service=self.registry_service,
|
|
156
|
+
logger=self.logger,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
def unregister_script(
|
|
160
|
+
self, key_name: str, dry_run: bool = False
|
|
161
|
+
) -> ScriptUnregistrationResult:
|
|
162
|
+
"""
|
|
163
|
+
Unregister a script from the Windows context menu.
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
key_name: Registry key name to remove
|
|
167
|
+
dry_run: If True, show what would be done without making changes
|
|
168
|
+
|
|
169
|
+
Returns:
|
|
170
|
+
ScriptUnregistrationResult: Result of the unregistration attempt
|
|
171
|
+
"""
|
|
172
|
+
if not key_name:
|
|
173
|
+
return ScriptUnregistrationResult(
|
|
174
|
+
success=False, error="Registry key name cannot be None or empty"
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
if dry_run:
|
|
178
|
+
return ScriptUnregistrationResult(
|
|
179
|
+
success=True,
|
|
180
|
+
dry_run=True,
|
|
181
|
+
key_name=key_name,
|
|
182
|
+
message="Dry run - no changes made",
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
# Try to remove from both context types
|
|
186
|
+
success = False
|
|
187
|
+
permission_errors: list[str] = []
|
|
188
|
+
not_found_count = 0
|
|
189
|
+
total_types = len(ContextTypesConfig.ALL_TYPES)
|
|
190
|
+
|
|
191
|
+
for context_type in ContextTypesConfig.ALL_TYPES:
|
|
192
|
+
try:
|
|
193
|
+
registry_path = self.registry_service.get_context_path(context_type)
|
|
194
|
+
if registry_path:
|
|
195
|
+
full_path = f"{registry_path}\\{key_name}"
|
|
196
|
+
result = self.registry_service.remove_context_menu_entry(full_path)
|
|
197
|
+
if result.success:
|
|
198
|
+
success = True
|
|
199
|
+
else:
|
|
200
|
+
# Entry not found in this context type
|
|
201
|
+
not_found_count += 1
|
|
202
|
+
self.logger.debug(
|
|
203
|
+
f"Entry not found in {context_type}: {result.error}"
|
|
204
|
+
)
|
|
205
|
+
except ContextServiceError as e:
|
|
206
|
+
error_str = str(e)
|
|
207
|
+
if (
|
|
208
|
+
"Accès refusé" in error_str
|
|
209
|
+
or "Access denied" in error_str
|
|
210
|
+
or "[WinError 5]" in error_str
|
|
211
|
+
):
|
|
212
|
+
permission_errors.append(f"{context_type}: {error_str}")
|
|
213
|
+
self.logger.warning(f"Failed to remove from {context_type}: {e}")
|
|
214
|
+
else:
|
|
215
|
+
self.logger.warning(f"Registry error for {context_type}: {e}")
|
|
216
|
+
except Exception as e:
|
|
217
|
+
self.logger.warning(f"Failed to remove from {context_type}: {e}")
|
|
218
|
+
|
|
219
|
+
if success:
|
|
220
|
+
return ScriptUnregistrationResult(
|
|
221
|
+
success=True,
|
|
222
|
+
key_name=key_name,
|
|
223
|
+
success_count=1,
|
|
224
|
+
total_types=total_types,
|
|
225
|
+
permission_errors=permission_errors,
|
|
226
|
+
not_found_count=not_found_count,
|
|
227
|
+
)
|
|
228
|
+
if permission_errors:
|
|
229
|
+
error_msg = "; ".join(permission_errors)
|
|
230
|
+
return ScriptUnregistrationResult(
|
|
231
|
+
success=False,
|
|
232
|
+
error=f"Permission denied: {error_msg}. Try running as administrator.",
|
|
233
|
+
key_name=key_name,
|
|
234
|
+
total_types=total_types,
|
|
235
|
+
permission_errors=permission_errors,
|
|
236
|
+
not_found_count=not_found_count,
|
|
237
|
+
)
|
|
238
|
+
return ScriptUnregistrationResult(
|
|
239
|
+
success=False,
|
|
240
|
+
error="Entry not found in any context type",
|
|
241
|
+
key_name=key_name,
|
|
242
|
+
total_types=total_types,
|
|
243
|
+
not_found_count=not_found_count,
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
def list_entries(self) -> ContextEntriesResult:
|
|
247
|
+
"""
|
|
248
|
+
List all registered context menu entries.
|
|
249
|
+
|
|
250
|
+
Returns:
|
|
251
|
+
ContextEntriesResult: All entries organized by context type
|
|
252
|
+
"""
|
|
253
|
+
all_entries: dict[str, list[dict[str, str | None]]] = {}
|
|
254
|
+
|
|
255
|
+
for context_type in ContextTypesConfig.ALL_TYPES:
|
|
256
|
+
try:
|
|
257
|
+
result = self.registry_service.list_context_menu_entries(context_type)
|
|
258
|
+
all_entries[context_type] = (
|
|
259
|
+
result.entries or [] if result.success else []
|
|
260
|
+
)
|
|
261
|
+
except Exception as e:
|
|
262
|
+
self.logger.warning(f"Failed to list entries for {context_type}: {e}")
|
|
263
|
+
all_entries[context_type] = []
|
|
264
|
+
|
|
265
|
+
return ContextEntriesResult(success=True, entries=all_entries)
|
|
266
|
+
|
|
267
|
+
def quick_setup_tools(self, verbose: bool = False) -> ContextSetupResult:
|
|
268
|
+
"""
|
|
269
|
+
Register common WOMM tools in the context menu.
|
|
270
|
+
|
|
271
|
+
Args:
|
|
272
|
+
verbose: Whether to log per-tool progress
|
|
273
|
+
|
|
274
|
+
Returns:
|
|
275
|
+
ContextSetupResult: Aggregate registration outcome
|
|
276
|
+
"""
|
|
277
|
+
try:
|
|
278
|
+
womm_executable = get_womm_executable()
|
|
279
|
+
if not womm_executable.is_file():
|
|
280
|
+
return ContextSetupResult(
|
|
281
|
+
success=False,
|
|
282
|
+
error=f"Could not find WOMM executable at {womm_executable}",
|
|
283
|
+
)
|
|
284
|
+
executable_path = str(womm_executable.resolve())
|
|
285
|
+
except OSError as e:
|
|
286
|
+
return ContextSetupResult(
|
|
287
|
+
success=False, error=f"Failed to locate WOMM executable: {e}"
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
tools = [
|
|
291
|
+
{
|
|
292
|
+
"target": executable_path,
|
|
293
|
+
"label": "WOMM CLI",
|
|
294
|
+
"description": "Main WOMM command-line interface",
|
|
295
|
+
},
|
|
296
|
+
]
|
|
297
|
+
|
|
298
|
+
context_params = ContextParameters.from_flags(
|
|
299
|
+
root=False,
|
|
300
|
+
file=False,
|
|
301
|
+
files=False,
|
|
302
|
+
background=True,
|
|
303
|
+
file_types=None,
|
|
304
|
+
extensions=None,
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
tools_registered: list[str] = []
|
|
308
|
+
for tool in tools:
|
|
309
|
+
if verbose:
|
|
310
|
+
self.logger.info(f"Registering: {tool['description']}")
|
|
311
|
+
|
|
312
|
+
result = self.register_script(
|
|
313
|
+
tool["target"], tool["label"], "auto", False, context_params
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
if result.success:
|
|
317
|
+
tools_registered.append(tool["label"])
|
|
318
|
+
elif verbose:
|
|
319
|
+
self.logger.warning(
|
|
320
|
+
f"Failed to register: {tool['label']} - {result.error}"
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
return ContextSetupResult(
|
|
324
|
+
success=len(tools_registered) == len(tools),
|
|
325
|
+
success_count=len(tools_registered),
|
|
326
|
+
total_tools=len(tools),
|
|
327
|
+
tools_registered=tools_registered,
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
def backup_entries(self, backup_file: str) -> ContextBackupResult:
|
|
331
|
+
"""
|
|
332
|
+
Backup current context menu entries.
|
|
333
|
+
|
|
334
|
+
Args:
|
|
335
|
+
backup_file: Path to save the backup file
|
|
336
|
+
|
|
337
|
+
Returns:
|
|
338
|
+
ContextBackupResult: Result of the backup attempt
|
|
339
|
+
"""
|
|
340
|
+
if not backup_file:
|
|
341
|
+
return ContextBackupResult(
|
|
342
|
+
success=False, error="Backup file path cannot be None or empty"
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
entries_result = self.list_entries()
|
|
346
|
+
if not entries_result.success:
|
|
347
|
+
return ContextBackupResult(
|
|
348
|
+
success=False,
|
|
349
|
+
error=f"Failed to get current entries: {entries_result.error}",
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
written = self.backup_manager.create_backup_file(
|
|
353
|
+
entries_result.entries or {},
|
|
354
|
+
custom_filename=Path(backup_file).stem,
|
|
355
|
+
add_timestamp=False,
|
|
356
|
+
)
|
|
357
|
+
if not written.success:
|
|
358
|
+
return ContextBackupResult(
|
|
359
|
+
success=False, error=f"Failed to create backup: {written.error}"
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
return ContextBackupResult(
|
|
363
|
+
success=True,
|
|
364
|
+
backup_file=written.filepath,
|
|
365
|
+
entry_count=(written.metadata or {}).get("total_entries", 0),
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
def restore_entries(self, backup_file: str) -> ContextRestoreResult:
|
|
369
|
+
"""
|
|
370
|
+
Restore context menu entries from backup.
|
|
371
|
+
|
|
372
|
+
Args:
|
|
373
|
+
backup_file: Path to the backup file
|
|
374
|
+
|
|
375
|
+
Returns:
|
|
376
|
+
ContextRestoreResult: Result of the restore attempt
|
|
377
|
+
"""
|
|
378
|
+
if not backup_file:
|
|
379
|
+
return ContextRestoreResult(
|
|
380
|
+
success=False, error="Backup file path cannot be None or empty"
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
loaded = self.backup_manager.load_backup_file(backup_file)
|
|
384
|
+
if not loaded.success:
|
|
385
|
+
return ContextRestoreResult(
|
|
386
|
+
success=False, error=f"Backup loading failed: {loaded.error}"
|
|
387
|
+
)
|
|
388
|
+
data = loaded.data or {}
|
|
389
|
+
|
|
390
|
+
try:
|
|
391
|
+
result = self.registry_service.restore_registry_entries(data)
|
|
392
|
+
except ContextServiceError as e:
|
|
393
|
+
return ContextRestoreResult(
|
|
394
|
+
success=False, error=f"Failed to restore registry entries: {e}"
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
if not result.success:
|
|
398
|
+
return ContextRestoreResult(
|
|
399
|
+
success=False, error="Registry restoration failed"
|
|
400
|
+
)
|
|
401
|
+
|
|
402
|
+
return ContextRestoreResult(
|
|
403
|
+
success=True,
|
|
404
|
+
backup_file=backup_file,
|
|
405
|
+
entry_count=data.get("metadata", {}).get("total_entries", 0),
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
# ///////////////////////////////////////////////////////////
|
|
409
|
+
# BACKUP READING
|
|
410
|
+
# ///////////////////////////////////////////////////////////
|
|
411
|
+
|
|
412
|
+
def list_backups(self) -> BackupFileListResult:
|
|
413
|
+
"""
|
|
414
|
+
List the available context menu backup files.
|
|
415
|
+
|
|
416
|
+
Returns:
|
|
417
|
+
BackupFileListResult: the discovered backups, newest first.
|
|
418
|
+
"""
|
|
419
|
+
return self.backup_manager.list_backup_files()
|
|
420
|
+
|
|
421
|
+
def resolve_backup_path(self, name: str) -> Path | None:
|
|
422
|
+
"""
|
|
423
|
+
Resolve a backup name inside the backup directory.
|
|
424
|
+
|
|
425
|
+
Args:
|
|
426
|
+
name: Bare backup file name, as listed by ``list_backups()``.
|
|
427
|
+
Path separators, parent references and absolute paths are
|
|
428
|
+
rejected.
|
|
429
|
+
|
|
430
|
+
Returns:
|
|
431
|
+
The resolved path, or None when the name is unsafe, absent, or
|
|
432
|
+
not a regular file. Callers must not disclose the resolved path.
|
|
433
|
+
"""
|
|
434
|
+
return resolve_backup_name(self.get_backup_directory(), name)
|
|
435
|
+
|
|
436
|
+
def read_backup(self, name: str) -> BackupDataResult:
|
|
437
|
+
"""
|
|
438
|
+
Read the content of a single context menu backup file.
|
|
439
|
+
|
|
440
|
+
Args:
|
|
441
|
+
name: Bare backup file name, as listed by ``list_backups()``.
|
|
442
|
+
|
|
443
|
+
Returns:
|
|
444
|
+
BackupDataResult: the backup's data, metadata and per-type entry
|
|
445
|
+
statistics, or a failure carrying the reason.
|
|
446
|
+
"""
|
|
447
|
+
backup_file = self.resolve_backup_path(name)
|
|
448
|
+
if backup_file is None:
|
|
449
|
+
return BackupDataResult(
|
|
450
|
+
success=False,
|
|
451
|
+
error=f"No readable backup named {name!r}",
|
|
452
|
+
)
|
|
453
|
+
|
|
454
|
+
return self.backup_manager.get_backup_info(str(backup_file))
|
|
455
|
+
|
|
456
|
+
def get_script_info(self, script_path: str) -> ScriptInfoResult:
|
|
457
|
+
"""
|
|
458
|
+
Get comprehensive information about a script.
|
|
459
|
+
|
|
460
|
+
Enriches the detector's result with the resolved icon and the registry
|
|
461
|
+
key name. Neither enrichment can fail the call: both degrade to ``None``
|
|
462
|
+
and are logged.
|
|
463
|
+
|
|
464
|
+
Args:
|
|
465
|
+
script_path: Path to the script
|
|
466
|
+
|
|
467
|
+
Returns:
|
|
468
|
+
ScriptInfoResult: script details; failure carries the error.
|
|
469
|
+
"""
|
|
470
|
+
if not script_path:
|
|
471
|
+
return ScriptInfoResult(
|
|
472
|
+
success=False, error="Script path cannot be None or empty"
|
|
473
|
+
)
|
|
474
|
+
|
|
475
|
+
script_info = ContextScriptDetectorInterface.get_script_info(script_path)
|
|
476
|
+
if not script_info.success:
|
|
477
|
+
return script_info
|
|
478
|
+
|
|
479
|
+
try:
|
|
480
|
+
script_info.resolved_icon = self.icon_manager.resolve_icon(
|
|
481
|
+
"auto", script_path
|
|
482
|
+
)
|
|
483
|
+
except (ValueError, OSError) as e:
|
|
484
|
+
self.logger.warning(f"Failed to resolve icon for {script_path}: {e}")
|
|
485
|
+
script_info.resolved_icon = None
|
|
486
|
+
|
|
487
|
+
try:
|
|
488
|
+
script_info.registry_key = self.registry_service.generate_registry_key_name(
|
|
489
|
+
script_path
|
|
490
|
+
)
|
|
491
|
+
except (ContextServiceError, ValueError) as e:
|
|
492
|
+
self.logger.warning(
|
|
493
|
+
f"Failed to generate registry key for {script_path}: {e}"
|
|
494
|
+
)
|
|
495
|
+
script_info.registry_key = None
|
|
496
|
+
|
|
497
|
+
return script_info
|
|
498
|
+
|
|
499
|
+
def validate_script(self, script_path: str) -> ScriptValidationResult:
|
|
500
|
+
"""
|
|
501
|
+
Validate if a script can be registered in context menu.
|
|
502
|
+
|
|
503
|
+
Args:
|
|
504
|
+
script_path: Path to the script
|
|
505
|
+
|
|
506
|
+
Returns:
|
|
507
|
+
ScriptValidationResult: validity plus the permission and
|
|
508
|
+
compatibility findings; failure carries the error.
|
|
509
|
+
"""
|
|
510
|
+
if not script_path:
|
|
511
|
+
return ScriptValidationResult(
|
|
512
|
+
success=False, error="Script path cannot be None or empty"
|
|
513
|
+
)
|
|
514
|
+
|
|
515
|
+
# Use ContextValidationService for comprehensive validation
|
|
516
|
+
try:
|
|
517
|
+
validation_result = self.validation_service.validate_script_path(
|
|
518
|
+
script_path
|
|
519
|
+
)
|
|
520
|
+
except (ContextServiceError, ValueError, OSError) as e:
|
|
521
|
+
return ScriptValidationResult(
|
|
522
|
+
success=False,
|
|
523
|
+
script_path=script_path,
|
|
524
|
+
error=f"Validation process failed: {e}",
|
|
525
|
+
)
|
|
526
|
+
|
|
527
|
+
if not validation_result.success:
|
|
528
|
+
return ScriptValidationResult(
|
|
529
|
+
success=False,
|
|
530
|
+
script_path=script_path,
|
|
531
|
+
error=validation_result.error or "Validation failed",
|
|
532
|
+
)
|
|
533
|
+
|
|
534
|
+
script_info = ContextScriptDetectorInterface.get_script_info(script_path)
|
|
535
|
+
if not script_info.success:
|
|
536
|
+
return ScriptValidationResult(
|
|
537
|
+
success=False,
|
|
538
|
+
script_path=script_path,
|
|
539
|
+
error=f"Failed to get script info during validation: {script_info.error}",
|
|
540
|
+
)
|
|
541
|
+
|
|
542
|
+
if script_info.script_type == ScriptType.UNKNOWN:
|
|
543
|
+
return ScriptValidationResult(
|
|
544
|
+
success=False,
|
|
545
|
+
script_path=script_path,
|
|
546
|
+
script_type=script_info.script_type,
|
|
547
|
+
error=f"Unsupported script type: {Path(script_path).suffix}",
|
|
548
|
+
)
|
|
549
|
+
|
|
550
|
+
if not script_info.command:
|
|
551
|
+
return ScriptValidationResult(
|
|
552
|
+
success=False,
|
|
553
|
+
script_path=script_path,
|
|
554
|
+
script_type=script_info.script_type,
|
|
555
|
+
error="Could not build execution command",
|
|
556
|
+
)
|
|
557
|
+
|
|
558
|
+
# Permission and compatibility findings are reported, not fatal
|
|
559
|
+
try:
|
|
560
|
+
permission_check = self.validation_service.check_permissions()
|
|
561
|
+
compatibility_check = (
|
|
562
|
+
self.validation_service.validate_windows_compatibility()
|
|
563
|
+
)
|
|
564
|
+
except (ContextServiceError, ValueError, OSError) as e:
|
|
565
|
+
self.logger.warning(f"Failed to check permissions/compatibility: {e}")
|
|
566
|
+
permission_check = ContextValidationResult(success=False, error=str(e))
|
|
567
|
+
compatibility_check = ContextValidationResult(success=False, error=str(e))
|
|
568
|
+
|
|
569
|
+
return ScriptValidationResult(
|
|
570
|
+
success=True,
|
|
571
|
+
message=f"{script_info.script_type} script can be registered",
|
|
572
|
+
script_path=script_path,
|
|
573
|
+
script_type=script_info.script_type,
|
|
574
|
+
command=script_info.command,
|
|
575
|
+
permissions_ok=permission_check.success,
|
|
576
|
+
permissions_error=permission_check.error or "",
|
|
577
|
+
compatibility_ok=compatibility_check.success,
|
|
578
|
+
compatibility_error=compatibility_check.error or "",
|
|
579
|
+
)
|
|
580
|
+
|
|
581
|
+
# ///////////////////////////////////////////////////////////////
|
|
582
|
+
# PLATFORM AND UTILITY METHODS
|
|
583
|
+
# ///////////////////////////////////////////////////////////////
|
|
584
|
+
|
|
585
|
+
def is_windows(self) -> bool:
|
|
586
|
+
"""Check if running on Windows platform."""
|
|
587
|
+
import platform
|
|
588
|
+
|
|
589
|
+
return platform.system().lower() == "windows"
|
|
590
|
+
|
|
591
|
+
def get_backup_directory(self) -> Path:
|
|
592
|
+
"""Get the backup directory path, creating it if needed."""
|
|
593
|
+
return self.backup_manager.get_backup_directory()
|
|
594
|
+
|
|
595
|
+
def collect_entries_from_backups(self) -> list[dict]:
|
|
596
|
+
"""
|
|
597
|
+
Collect all unique context menu entries from backup files.
|
|
598
|
+
|
|
599
|
+
Returns:
|
|
600
|
+
List of unique entries with metadata
|
|
601
|
+
"""
|
|
602
|
+
return self._backup_entries_reader.collect_entries(self.get_backup_directory())
|
|
603
|
+
|
|
604
|
+
def get_current_entry_keys(self) -> set[str]:
|
|
605
|
+
"""
|
|
606
|
+
Get set of currently installed context menu entry keys.
|
|
607
|
+
|
|
608
|
+
Returns:
|
|
609
|
+
Set of key names currently installed
|
|
610
|
+
"""
|
|
611
|
+
entries_result = self.list_entries()
|
|
612
|
+
if not entries_result.success:
|
|
613
|
+
return set()
|
|
614
|
+
|
|
615
|
+
entries = entries_result.entries or {}
|
|
616
|
+
current_keys: set[str] = set()
|
|
617
|
+
for context_type in ["directory", "background"]:
|
|
618
|
+
for entry in entries.get(context_type, []):
|
|
619
|
+
key_name = entry.get("key_name")
|
|
620
|
+
if key_name:
|
|
621
|
+
current_keys.add(key_name)
|
|
622
|
+
return current_keys
|
|
623
|
+
|
|
624
|
+
def filter_available_entries(
|
|
625
|
+
self, all_entries: list[dict], current_keys: set[str]
|
|
626
|
+
) -> list[dict]:
|
|
627
|
+
"""
|
|
628
|
+
Filter out entries that are already installed.
|
|
629
|
+
|
|
630
|
+
Args:
|
|
631
|
+
all_entries: All entries from backups
|
|
632
|
+
current_keys: Set of currently installed entry keys
|
|
633
|
+
|
|
634
|
+
Returns:
|
|
635
|
+
List of entries not yet installed
|
|
636
|
+
"""
|
|
637
|
+
return self._backup_entries_reader.filter_available(all_entries, current_keys)
|
|
638
|
+
|
|
639
|
+
def apply_cherry_picked_entries(
|
|
640
|
+
self, selected_entries: list[dict]
|
|
641
|
+
) -> dict[str, bool]:
|
|
642
|
+
"""
|
|
643
|
+
Apply selected context menu entries.
|
|
644
|
+
|
|
645
|
+
Args:
|
|
646
|
+
selected_entries: List of entries to apply
|
|
647
|
+
|
|
648
|
+
Returns:
|
|
649
|
+
Dict mapping key names to success status
|
|
650
|
+
"""
|
|
651
|
+
results: dict[str, bool] = {}
|
|
652
|
+
|
|
653
|
+
for entry in selected_entries:
|
|
654
|
+
key_name = entry.get("key_name")
|
|
655
|
+
if not isinstance(key_name, str) or not key_name:
|
|
656
|
+
self.logger.warning("Skipping entry with missing key_name")
|
|
657
|
+
continue
|
|
658
|
+
|
|
659
|
+
properties = entry.get("properties", {})
|
|
660
|
+
command = properties.get("Command", "")
|
|
661
|
+
muiverb = properties.get("MUIVerb")
|
|
662
|
+
icon = properties.get("Icon")
|
|
663
|
+
|
|
664
|
+
if not command:
|
|
665
|
+
self.logger.warning(f"Skipping {key_name}: no command found")
|
|
666
|
+
results[key_name] = False
|
|
667
|
+
continue
|
|
668
|
+
|
|
669
|
+
script_path = self._backup_entries_reader.extract_script_path(command)
|
|
670
|
+
|
|
671
|
+
if not script_path:
|
|
672
|
+
self.logger.warning(
|
|
673
|
+
f"Skipping {key_name}: could not extract script path"
|
|
674
|
+
)
|
|
675
|
+
results[key_name] = False
|
|
676
|
+
continue
|
|
677
|
+
|
|
678
|
+
# Execute registration
|
|
679
|
+
muiverb_value = (
|
|
680
|
+
muiverb if isinstance(muiverb, str) and muiverb else key_name
|
|
681
|
+
)
|
|
682
|
+
icon_value = icon if isinstance(icon, str) and icon else "auto"
|
|
683
|
+
result = self.register_script(script_path, muiverb_value, icon_value)
|
|
684
|
+
results[key_name] = result.success
|
|
685
|
+
|
|
686
|
+
return results
|