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,573 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# CONTEXT REGISTRY SERVICE - Context Menu Registry Service
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Context Registry Service - Singleton service for context menu registry operations.
|
|
9
|
+
|
|
10
|
+
This module provides low-level registry operations for managing
|
|
11
|
+
Windows context menu entries.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
# ///////////////////////////////////////////////////////////////
|
|
17
|
+
# IMPORTS
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# Standard library imports
|
|
20
|
+
import logging
|
|
21
|
+
from threading import Lock
|
|
22
|
+
from typing import ClassVar
|
|
23
|
+
|
|
24
|
+
# Local imports
|
|
25
|
+
from ...exceptions.context import ContextServiceError
|
|
26
|
+
from ...shared.configs.context import ContextConfig
|
|
27
|
+
from ...shared.results import ContextRegistryResult
|
|
28
|
+
from ...utils.context import generate_registry_key_name, get_registry_entry_info
|
|
29
|
+
|
|
30
|
+
# ///////////////////////////////////////////////////////////////
|
|
31
|
+
# LOGGER SETUP
|
|
32
|
+
# ///////////////////////////////////////////////////////////////
|
|
33
|
+
|
|
34
|
+
logger = logging.getLogger(__name__)
|
|
35
|
+
|
|
36
|
+
# ///////////////////////////////////////////////////////////////
|
|
37
|
+
# CONTEXT REGISTRY SERVICE CLASS
|
|
38
|
+
# ///////////////////////////////////////////////////////////////
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class ContextRegistryService:
|
|
42
|
+
"""Singleton service for context menu registry operations."""
|
|
43
|
+
|
|
44
|
+
_instance: ClassVar[ContextRegistryService | None] = None
|
|
45
|
+
_initialized: ClassVar[bool] = False
|
|
46
|
+
_lock: ClassVar[Lock] = Lock()
|
|
47
|
+
|
|
48
|
+
def __new__(cls) -> ContextRegistryService:
|
|
49
|
+
"""Create or return the singleton instance.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
ContextRegistryService: The singleton instance
|
|
53
|
+
"""
|
|
54
|
+
with cls._lock:
|
|
55
|
+
if cls._instance is None:
|
|
56
|
+
cls._instance = super().__new__(cls)
|
|
57
|
+
return cls._instance
|
|
58
|
+
|
|
59
|
+
def __init__(self) -> None:
|
|
60
|
+
"""Initialize context registry service (only once)."""
|
|
61
|
+
if ContextRegistryService._initialized:
|
|
62
|
+
return
|
|
63
|
+
|
|
64
|
+
self.logger = logging.getLogger(__name__)
|
|
65
|
+
ContextRegistryService._initialized = True
|
|
66
|
+
|
|
67
|
+
# ///////////////////////////////////////////////////////////////
|
|
68
|
+
# PUBLIC METHODS
|
|
69
|
+
# ///////////////////////////////////////////////////////////////
|
|
70
|
+
|
|
71
|
+
def generate_registry_key_name(self, file_path: str) -> str:
|
|
72
|
+
"""
|
|
73
|
+
Generate registry key name from file path.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
file_path: Path to the file
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
Generated registry key name
|
|
80
|
+
|
|
81
|
+
Raises:
|
|
82
|
+
ValueError: If file_path is invalid
|
|
83
|
+
"""
|
|
84
|
+
return generate_registry_key_name(file_path)
|
|
85
|
+
|
|
86
|
+
def add_context_menu_entry(
|
|
87
|
+
self,
|
|
88
|
+
registry_path: str,
|
|
89
|
+
command: str,
|
|
90
|
+
mui_verb: str,
|
|
91
|
+
icon_path: str | None = None,
|
|
92
|
+
) -> ContextRegistryResult:
|
|
93
|
+
"""
|
|
94
|
+
Add context menu entry to registry.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
registry_path: Registry path for the entry
|
|
98
|
+
command: Command to execute
|
|
99
|
+
mui_verb: Display name for the menu item
|
|
100
|
+
icon_path: Optional icon path
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
ContextRegistryResult: Result of the operation
|
|
104
|
+
|
|
105
|
+
Raises:
|
|
106
|
+
ContextServiceError: If parameters are invalid, the registry
|
|
107
|
+
operation fails, or an unexpected error occurs
|
|
108
|
+
"""
|
|
109
|
+
try:
|
|
110
|
+
# Input validation
|
|
111
|
+
if not registry_path:
|
|
112
|
+
raise ContextServiceError(
|
|
113
|
+
"registry_entry", "Registry path cannot be None or empty"
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
if not command:
|
|
117
|
+
raise ContextServiceError(
|
|
118
|
+
"registry_entry", "Command cannot be None or empty"
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
if not mui_verb:
|
|
122
|
+
raise ContextServiceError(
|
|
123
|
+
"registry_entry", "Display name cannot be None or empty"
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
if not isinstance(registry_path, str):
|
|
127
|
+
raise ContextServiceError(
|
|
128
|
+
"registry_entry",
|
|
129
|
+
f"Registry path must be a string, got {type(registry_path).__name__}",
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
if not isinstance(command, str):
|
|
133
|
+
raise ContextServiceError(
|
|
134
|
+
"registry_entry",
|
|
135
|
+
f"Command must be a string, got {type(command).__name__}",
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
if not isinstance(mui_verb, str):
|
|
139
|
+
raise ContextServiceError(
|
|
140
|
+
"registry_entry",
|
|
141
|
+
f"Display name must be a string, got {type(mui_verb).__name__}",
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
if icon_path is not None and not isinstance(icon_path, str):
|
|
145
|
+
raise ContextServiceError(
|
|
146
|
+
"registry_entry",
|
|
147
|
+
f"Icon path must be a string, got {type(icon_path).__name__}",
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
import winreg
|
|
151
|
+
|
|
152
|
+
# Create the registry key
|
|
153
|
+
try:
|
|
154
|
+
with winreg.CreateKey(winreg.HKEY_CURRENT_USER, registry_path) as key:
|
|
155
|
+
# Set the display name
|
|
156
|
+
winreg.SetValueEx(key, "MUIVerb", 0, winreg.REG_SZ, mui_verb)
|
|
157
|
+
|
|
158
|
+
# Set the command
|
|
159
|
+
with winreg.CreateKey(key, "command") as cmd_key:
|
|
160
|
+
winreg.SetValueEx(cmd_key, "", 0, winreg.REG_SZ, command)
|
|
161
|
+
|
|
162
|
+
# Set icon if provided
|
|
163
|
+
if icon_path:
|
|
164
|
+
winreg.SetValueEx(key, "Icon", 0, winreg.REG_SZ, icon_path)
|
|
165
|
+
|
|
166
|
+
return ContextRegistryResult(
|
|
167
|
+
success=True,
|
|
168
|
+
message=f"Context menu entry added successfully: {mui_verb}",
|
|
169
|
+
registry_path=registry_path,
|
|
170
|
+
command=command,
|
|
171
|
+
display_name=mui_verb,
|
|
172
|
+
icon_path=icon_path,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
except (OSError, PermissionError) as e:
|
|
176
|
+
raise ContextServiceError(
|
|
177
|
+
"registry_entry", f"Failed to create registry entry: {e}"
|
|
178
|
+
) from e
|
|
179
|
+
|
|
180
|
+
except ContextServiceError:
|
|
181
|
+
raise
|
|
182
|
+
except Exception as e:
|
|
183
|
+
raise ContextServiceError(
|
|
184
|
+
"registry_entry",
|
|
185
|
+
f"Unexpected error adding registry entry: {e}",
|
|
186
|
+
details=f"Registry path: {registry_path}, Command: {command}",
|
|
187
|
+
) from e
|
|
188
|
+
|
|
189
|
+
def remove_context_menu_entry(self, registry_path: str) -> ContextRegistryResult:
|
|
190
|
+
"""
|
|
191
|
+
Remove context menu entry from registry.
|
|
192
|
+
|
|
193
|
+
Args:
|
|
194
|
+
registry_path: Registry path to remove
|
|
195
|
+
|
|
196
|
+
Returns:
|
|
197
|
+
ContextRegistryResult: Result of the operation
|
|
198
|
+
|
|
199
|
+
Raises:
|
|
200
|
+
ContextServiceError: If registry_path is invalid, the registry
|
|
201
|
+
operation fails, or an unexpected error occurs
|
|
202
|
+
"""
|
|
203
|
+
try:
|
|
204
|
+
# Input validation
|
|
205
|
+
if not registry_path:
|
|
206
|
+
raise ContextServiceError(
|
|
207
|
+
"registry_removal", "Registry path cannot be None or empty"
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
if not isinstance(registry_path, str):
|
|
211
|
+
raise ContextServiceError(
|
|
212
|
+
"registry_removal",
|
|
213
|
+
f"Registry path must be a string, got {type(registry_path).__name__}",
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
import winreg
|
|
217
|
+
|
|
218
|
+
try:
|
|
219
|
+
# First, try to delete all subkeys (like "command")
|
|
220
|
+
# Windows requires deleting subkeys before deleting the parent key
|
|
221
|
+
try:
|
|
222
|
+
with winreg.OpenKey(
|
|
223
|
+
winreg.HKEY_CURRENT_USER, registry_path, 0, winreg.KEY_READ
|
|
224
|
+
) as parent_key:
|
|
225
|
+
# Get all subkeys
|
|
226
|
+
subkeys = []
|
|
227
|
+
i = 0
|
|
228
|
+
while True:
|
|
229
|
+
try:
|
|
230
|
+
subkey_name = winreg.EnumKey(parent_key, i)
|
|
231
|
+
subkeys.append(subkey_name)
|
|
232
|
+
i += 1
|
|
233
|
+
except OSError:
|
|
234
|
+
break
|
|
235
|
+
|
|
236
|
+
# Delete all subkeys first
|
|
237
|
+
for subkey_name in subkeys:
|
|
238
|
+
subkey_path = f"{registry_path}\\{subkey_name}"
|
|
239
|
+
try:
|
|
240
|
+
winreg.DeleteKey(winreg.HKEY_CURRENT_USER, subkey_path)
|
|
241
|
+
self.logger.debug(f"Deleted subkey: {subkey_path}")
|
|
242
|
+
except Exception as subkey_error:
|
|
243
|
+
self.logger.warning(
|
|
244
|
+
f"Failed to delete subkey {subkey_path}: {subkey_error}"
|
|
245
|
+
)
|
|
246
|
+
# Continue with other subkeys even if one fails
|
|
247
|
+
except FileNotFoundError:
|
|
248
|
+
# Parent key doesn't exist, which is fine
|
|
249
|
+
pass
|
|
250
|
+
except OSError as e:
|
|
251
|
+
# If we can't open the key, it might not exist or we don't have access
|
|
252
|
+
if hasattr(e, "winerror") and e.winerror == 2:
|
|
253
|
+
# Key doesn't exist
|
|
254
|
+
return ContextRegistryResult(
|
|
255
|
+
success=False,
|
|
256
|
+
message=f"Context menu entry not found: {registry_path}",
|
|
257
|
+
registry_path=registry_path,
|
|
258
|
+
error=f"Entry not found: {e}",
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
# Now delete the main key
|
|
262
|
+
winreg.DeleteKey(winreg.HKEY_CURRENT_USER, registry_path)
|
|
263
|
+
return ContextRegistryResult(
|
|
264
|
+
success=True,
|
|
265
|
+
message=f"Context menu entry removed successfully: {registry_path}",
|
|
266
|
+
registry_path=registry_path,
|
|
267
|
+
)
|
|
268
|
+
except PermissionError as e:
|
|
269
|
+
raise ContextServiceError(
|
|
270
|
+
"registry_removal", f"Failed to remove registry entry: {e}"
|
|
271
|
+
) from e
|
|
272
|
+
except FileNotFoundError as e:
|
|
273
|
+
# Entry doesn't exist - return result with success=False
|
|
274
|
+
return ContextRegistryResult(
|
|
275
|
+
success=False,
|
|
276
|
+
message=f"Context menu entry not found: {registry_path}",
|
|
277
|
+
registry_path=registry_path,
|
|
278
|
+
error=f"Entry not found: {e}",
|
|
279
|
+
)
|
|
280
|
+
except OSError as e:
|
|
281
|
+
# Check if it's a permission error (WinError 5)
|
|
282
|
+
if hasattr(e, "winerror") and e.winerror == 5:
|
|
283
|
+
raise ContextServiceError(
|
|
284
|
+
"registry_removal", f"Failed to remove registry entry: {e}"
|
|
285
|
+
) from e
|
|
286
|
+
# Check if it's a "file not found" error (WinError 2)
|
|
287
|
+
elif hasattr(e, "winerror") and e.winerror == 2:
|
|
288
|
+
return ContextRegistryResult(
|
|
289
|
+
success=False,
|
|
290
|
+
message=f"Context menu entry not found: {registry_path}",
|
|
291
|
+
registry_path=registry_path,
|
|
292
|
+
error=f"Entry not found: {e}",
|
|
293
|
+
)
|
|
294
|
+
else:
|
|
295
|
+
raise ContextServiceError(
|
|
296
|
+
"registry_removal", f"Failed to remove registry entry: {e}"
|
|
297
|
+
) from e
|
|
298
|
+
|
|
299
|
+
except ContextServiceError:
|
|
300
|
+
raise
|
|
301
|
+
except Exception as e:
|
|
302
|
+
raise ContextServiceError(
|
|
303
|
+
"registry_removal",
|
|
304
|
+
f"Unexpected error removing registry entry: {e}",
|
|
305
|
+
details=f"Registry path: {registry_path}",
|
|
306
|
+
) from e
|
|
307
|
+
|
|
308
|
+
def list_context_menu_entries(
|
|
309
|
+
self, context_type: str = "directory"
|
|
310
|
+
) -> ContextRegistryResult:
|
|
311
|
+
"""
|
|
312
|
+
List context menu entries for given type.
|
|
313
|
+
|
|
314
|
+
Args:
|
|
315
|
+
context_type: Type of context to list
|
|
316
|
+
|
|
317
|
+
Returns:
|
|
318
|
+
ContextRegistryResult: Result with list of entries
|
|
319
|
+
|
|
320
|
+
Raises:
|
|
321
|
+
ContextServiceError: If context_type is invalid, the registry
|
|
322
|
+
operation fails, or an unexpected error occurs
|
|
323
|
+
"""
|
|
324
|
+
try:
|
|
325
|
+
# Input validation
|
|
326
|
+
if not context_type:
|
|
327
|
+
raise ContextServiceError(
|
|
328
|
+
"registry_listing", "Context type cannot be None or empty"
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
if not isinstance(context_type, str):
|
|
332
|
+
raise ContextServiceError(
|
|
333
|
+
"registry_listing",
|
|
334
|
+
f"Context type must be a string, got {type(context_type).__name__}",
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
entries = []
|
|
338
|
+
registry_path = ContextConfig.CONTEXT_PATHS.get(context_type)
|
|
339
|
+
|
|
340
|
+
if not registry_path:
|
|
341
|
+
return ContextRegistryResult(
|
|
342
|
+
success=True,
|
|
343
|
+
message=f"No entries found for context type: {context_type}",
|
|
344
|
+
registry_path="",
|
|
345
|
+
entries=[],
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
import winreg
|
|
349
|
+
|
|
350
|
+
try:
|
|
351
|
+
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, registry_path) as key:
|
|
352
|
+
i = 0
|
|
353
|
+
while True:
|
|
354
|
+
try:
|
|
355
|
+
subkey_name = winreg.EnumKey(key, i)
|
|
356
|
+
except OSError:
|
|
357
|
+
# No more subkeys to enumerate.
|
|
358
|
+
break
|
|
359
|
+
entry_info = get_registry_entry_info(registry_path, subkey_name)
|
|
360
|
+
if entry_info:
|
|
361
|
+
entries.append(entry_info)
|
|
362
|
+
i += 1
|
|
363
|
+
|
|
364
|
+
except (OSError, PermissionError) as e:
|
|
365
|
+
raise ContextServiceError(
|
|
366
|
+
"registry_listing", f"Failed to list registry entries: {e}"
|
|
367
|
+
) from e
|
|
368
|
+
|
|
369
|
+
return ContextRegistryResult(
|
|
370
|
+
success=True,
|
|
371
|
+
message=f"Found {len(entries)} entries for context type: {context_type}",
|
|
372
|
+
registry_path=registry_path,
|
|
373
|
+
entries=entries,
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
except ContextServiceError:
|
|
377
|
+
raise
|
|
378
|
+
except Exception as e:
|
|
379
|
+
raise ContextServiceError(
|
|
380
|
+
"registry_listing",
|
|
381
|
+
f"Unexpected error listing registry entries: {e}",
|
|
382
|
+
details=f"Context type: {context_type}",
|
|
383
|
+
) from e
|
|
384
|
+
|
|
385
|
+
def backup_registry_entries(
|
|
386
|
+
self, context_types: list[str] | None = None
|
|
387
|
+
) -> ContextRegistryResult:
|
|
388
|
+
"""
|
|
389
|
+
Backup context menu entries to dictionary.
|
|
390
|
+
|
|
391
|
+
Args:
|
|
392
|
+
context_types: List of context types to backup
|
|
393
|
+
|
|
394
|
+
Returns:
|
|
395
|
+
ContextRegistryResult: Result with backup data
|
|
396
|
+
|
|
397
|
+
Raises:
|
|
398
|
+
ContextServiceError: If context_types is invalid or an
|
|
399
|
+
unexpected error occurs
|
|
400
|
+
"""
|
|
401
|
+
try:
|
|
402
|
+
# Input validation
|
|
403
|
+
if context_types is not None and not isinstance(context_types, list):
|
|
404
|
+
raise ContextServiceError(
|
|
405
|
+
"registry_backup",
|
|
406
|
+
f"Context types must be a list, got {type(context_types).__name__}",
|
|
407
|
+
)
|
|
408
|
+
|
|
409
|
+
if context_types is None:
|
|
410
|
+
context_types = ["directory", "background"]
|
|
411
|
+
|
|
412
|
+
context_types_data: dict[str, list[dict[str, str | None]]] = {}
|
|
413
|
+
backup_data = {
|
|
414
|
+
"timestamp": None,
|
|
415
|
+
"context_types": context_types_data,
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
for context_type in context_types:
|
|
419
|
+
try:
|
|
420
|
+
entries_result = self.list_context_menu_entries(context_type)
|
|
421
|
+
if entries_result.success and entries_result.entries:
|
|
422
|
+
if isinstance(entries_result.entries, list):
|
|
423
|
+
context_types_data[context_type] = entries_result.entries
|
|
424
|
+
else:
|
|
425
|
+
context_types_data[context_type] = []
|
|
426
|
+
else:
|
|
427
|
+
context_types_data[context_type] = []
|
|
428
|
+
except Exception as e:
|
|
429
|
+
# Log warning but continue with other context types
|
|
430
|
+
logging.getLogger(__name__).warning(
|
|
431
|
+
f"Failed to backup context type {context_type}: {e}"
|
|
432
|
+
)
|
|
433
|
+
context_types_data[context_type] = []
|
|
434
|
+
|
|
435
|
+
return ContextRegistryResult(
|
|
436
|
+
success=True,
|
|
437
|
+
message=f"Backup completed for {len(context_types)} context types",
|
|
438
|
+
backup_data=backup_data,
|
|
439
|
+
)
|
|
440
|
+
|
|
441
|
+
except ContextServiceError:
|
|
442
|
+
raise
|
|
443
|
+
except Exception as e:
|
|
444
|
+
raise ContextServiceError(
|
|
445
|
+
"registry_backup",
|
|
446
|
+
f"Unexpected error backing up registry entries: {e}",
|
|
447
|
+
details=f"Context types: {context_types}",
|
|
448
|
+
) from e
|
|
449
|
+
|
|
450
|
+
def restore_registry_entries(
|
|
451
|
+
self, backup_data: dict[str, str | None | dict[str, list]]
|
|
452
|
+
) -> ContextRegistryResult:
|
|
453
|
+
"""
|
|
454
|
+
Restore context menu entries from backup data.
|
|
455
|
+
|
|
456
|
+
Args:
|
|
457
|
+
backup_data: Backup data dictionary
|
|
458
|
+
|
|
459
|
+
Returns:
|
|
460
|
+
ContextRegistryResult: Result of the operation
|
|
461
|
+
|
|
462
|
+
Raises:
|
|
463
|
+
ContextServiceError: If backup_data is invalid, the registry
|
|
464
|
+
operation fails, or an unexpected error occurs
|
|
465
|
+
"""
|
|
466
|
+
try:
|
|
467
|
+
# Input validation
|
|
468
|
+
if not backup_data:
|
|
469
|
+
raise ContextServiceError(
|
|
470
|
+
"registry_restore", "Backup data cannot be None or empty"
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
if not isinstance(backup_data, dict):
|
|
474
|
+
raise ContextServiceError(
|
|
475
|
+
"registry_restore",
|
|
476
|
+
f"Backup data must be a dictionary, got {type(backup_data).__name__}",
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
restored_count = 0
|
|
480
|
+
try:
|
|
481
|
+
context_types_data = backup_data.get("context_types")
|
|
482
|
+
if not isinstance(context_types_data, dict):
|
|
483
|
+
context_types_data = {}
|
|
484
|
+
for _context_type, entries in context_types_data.items():
|
|
485
|
+
for entry in entries:
|
|
486
|
+
registry_path = entry.get("registry_path")
|
|
487
|
+
command = entry.get("command")
|
|
488
|
+
display_name = entry.get("display_name")
|
|
489
|
+
icon = entry.get("icon")
|
|
490
|
+
|
|
491
|
+
if registry_path and command and display_name:
|
|
492
|
+
result = self.add_context_menu_entry(
|
|
493
|
+
registry_path, command, display_name, icon
|
|
494
|
+
)
|
|
495
|
+
if result.success:
|
|
496
|
+
restored_count += 1
|
|
497
|
+
|
|
498
|
+
return ContextRegistryResult(
|
|
499
|
+
success=True,
|
|
500
|
+
message=f"Restored {restored_count} registry entries",
|
|
501
|
+
backup_data=backup_data,
|
|
502
|
+
)
|
|
503
|
+
|
|
504
|
+
except (OSError, PermissionError) as e:
|
|
505
|
+
raise ContextServiceError(
|
|
506
|
+
"registry_restore", f"Failed to restore registry entries: {e}"
|
|
507
|
+
) from e
|
|
508
|
+
|
|
509
|
+
except ContextServiceError:
|
|
510
|
+
raise
|
|
511
|
+
except Exception as e:
|
|
512
|
+
raise ContextServiceError(
|
|
513
|
+
"registry_restore",
|
|
514
|
+
f"Unexpected error restoring registry entries: {e}",
|
|
515
|
+
details="Failed to restore from backup data",
|
|
516
|
+
) from e
|
|
517
|
+
|
|
518
|
+
def get_context_path(self, context_type: str) -> str | None:
|
|
519
|
+
"""
|
|
520
|
+
Get registry path for context type.
|
|
521
|
+
|
|
522
|
+
Args:
|
|
523
|
+
context_type: Type of context
|
|
524
|
+
|
|
525
|
+
Returns:
|
|
526
|
+
Registry path or None if not found
|
|
527
|
+
|
|
528
|
+
Raises:
|
|
529
|
+
ContextServiceError: If context_type is invalid or an unexpected
|
|
530
|
+
error occurs
|
|
531
|
+
"""
|
|
532
|
+
try:
|
|
533
|
+
# Input validation
|
|
534
|
+
if not context_type:
|
|
535
|
+
raise ContextServiceError(
|
|
536
|
+
"context_path", "Context type cannot be None or empty"
|
|
537
|
+
)
|
|
538
|
+
|
|
539
|
+
if not isinstance(context_type, str):
|
|
540
|
+
raise ContextServiceError(
|
|
541
|
+
"context_path",
|
|
542
|
+
f"Context type must be a string, got {type(context_type).__name__}",
|
|
543
|
+
)
|
|
544
|
+
|
|
545
|
+
return ContextConfig.CONTEXT_PATHS.get(context_type)
|
|
546
|
+
|
|
547
|
+
except ContextServiceError:
|
|
548
|
+
raise
|
|
549
|
+
except Exception as e:
|
|
550
|
+
raise ContextServiceError(
|
|
551
|
+
"context_path",
|
|
552
|
+
f"Unexpected error getting context path: {e}",
|
|
553
|
+
details=f"Context type: {context_type}",
|
|
554
|
+
) from e
|
|
555
|
+
|
|
556
|
+
def get_supported_context_types(self) -> list[str]:
|
|
557
|
+
"""
|
|
558
|
+
Get list of supported context types.
|
|
559
|
+
|
|
560
|
+
Returns:
|
|
561
|
+
List of supported context types
|
|
562
|
+
|
|
563
|
+
Raises:
|
|
564
|
+
ContextServiceError: For unexpected errors
|
|
565
|
+
"""
|
|
566
|
+
try:
|
|
567
|
+
return list(ContextConfig.CONTEXT_PATHS.keys())
|
|
568
|
+
except Exception as e:
|
|
569
|
+
raise ContextServiceError(
|
|
570
|
+
"supported_context_types",
|
|
571
|
+
f"Unexpected error getting supported context types: {e}",
|
|
572
|
+
details="Failed to get context paths keys",
|
|
573
|
+
) from e
|