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,515 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# CONTEXT PARAMETERS - Context Menu Parameters
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Context Parameters - Parameters selected for a context menu registration.
|
|
9
|
+
|
|
10
|
+
This module provides functionality to handle intelligent context parameters
|
|
11
|
+
like --root, --file, --files, --background and automatically generate
|
|
12
|
+
appropriate command parameters and registry paths.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
# ///////////////////////////////////////////////////////////////
|
|
18
|
+
# IMPORTS
|
|
19
|
+
# ///////////////////////////////////////////////////////////////
|
|
20
|
+
# Standard library imports
|
|
21
|
+
import logging
|
|
22
|
+
from enum import Enum
|
|
23
|
+
|
|
24
|
+
# Local imports
|
|
25
|
+
from ...exceptions.context import ContextServiceError
|
|
26
|
+
from ...shared.configs.context import ContextConfig
|
|
27
|
+
from ...utils.context import (
|
|
28
|
+
build_command_with_parameter,
|
|
29
|
+
get_available_file_types,
|
|
30
|
+
get_context_type_help,
|
|
31
|
+
get_file_type_help,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
# ///////////////////////////////////////////////////////////////
|
|
35
|
+
# LOGGER SETUP
|
|
36
|
+
# ///////////////////////////////////////////////////////////////
|
|
37
|
+
|
|
38
|
+
logger = logging.getLogger(__name__)
|
|
39
|
+
|
|
40
|
+
# ///////////////////////////////////////////////////////////////
|
|
41
|
+
# ENUMS
|
|
42
|
+
# ///////////////////////////////////////////////////////////////
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class ContextType(Enum):
|
|
46
|
+
"""Types of context menu entries."""
|
|
47
|
+
|
|
48
|
+
DIRECTORY = "directory"
|
|
49
|
+
BACKGROUND = "background"
|
|
50
|
+
FILE = "file"
|
|
51
|
+
FILES = "files"
|
|
52
|
+
ROOT = "root"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# ///////////////////////////////////////////////////////////////
|
|
56
|
+
# CONTEXT PARAMETERS CLASS
|
|
57
|
+
# ///////////////////////////////////////////////////////////////
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class ContextParameters:
|
|
61
|
+
"""Context parameters selected for one context menu registration.
|
|
62
|
+
|
|
63
|
+
Each instance owns its own selection. The class is deliberately not a
|
|
64
|
+
singleton: two successive registrations in the same process must not
|
|
65
|
+
accumulate each other's flags.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
def __init__(self) -> None:
|
|
69
|
+
"""Initialize an empty set of context parameters."""
|
|
70
|
+
self.logger = logging.getLogger(__name__)
|
|
71
|
+
self.context_types: set[ContextType] = set()
|
|
72
|
+
self.file_types: set[str] = set()
|
|
73
|
+
self.custom_extensions: set[str] = set()
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def REGISTRY_PATHS(self) -> dict[ContextType, str]:
|
|
77
|
+
"""Get registry paths for different context types."""
|
|
78
|
+
return {
|
|
79
|
+
ContextType.DIRECTORY: ContextConfig.REGISTRY_PATHS_BY_TYPE["directory"],
|
|
80
|
+
ContextType.BACKGROUND: ContextConfig.REGISTRY_PATHS_BY_TYPE["background"],
|
|
81
|
+
ContextType.FILE: ContextConfig.REGISTRY_PATHS_BY_TYPE["file"],
|
|
82
|
+
ContextType.FILES: ContextConfig.REGISTRY_PATHS_BY_TYPE["files"],
|
|
83
|
+
ContextType.ROOT: ContextConfig.REGISTRY_PATHS_BY_TYPE["root"],
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@property
|
|
87
|
+
def COMMAND_PARAMETERS(self) -> dict[ContextType, str]:
|
|
88
|
+
"""Get command parameters for different context types."""
|
|
89
|
+
return {
|
|
90
|
+
ContextType.DIRECTORY: ContextConfig.COMMAND_PARAMETERS["directory"],
|
|
91
|
+
ContextType.BACKGROUND: ContextConfig.COMMAND_PARAMETERS["background"],
|
|
92
|
+
ContextType.FILE: ContextConfig.COMMAND_PARAMETERS["file"],
|
|
93
|
+
ContextType.FILES: ContextConfig.COMMAND_PARAMETERS["files"],
|
|
94
|
+
ContextType.ROOT: ContextConfig.COMMAND_PARAMETERS["root"],
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def FILE_TYPE_EXTENSIONS(self) -> dict[str, set[str]]:
|
|
99
|
+
"""Get file type extensions for different contexts."""
|
|
100
|
+
return ContextConfig.FILE_TYPE_EXTENSIONS
|
|
101
|
+
|
|
102
|
+
def add_context_type(self, context_type: ContextType) -> None:
|
|
103
|
+
"""
|
|
104
|
+
Add a context type to the parameters.
|
|
105
|
+
|
|
106
|
+
Args:
|
|
107
|
+
context_type: The context type to add
|
|
108
|
+
|
|
109
|
+
Raises:
|
|
110
|
+
ContextServiceError: If context_type is invalid or an unexpected
|
|
111
|
+
error occurs
|
|
112
|
+
"""
|
|
113
|
+
try:
|
|
114
|
+
# Input validation
|
|
115
|
+
if not isinstance(context_type, ContextType):
|
|
116
|
+
raise ContextServiceError(
|
|
117
|
+
"context_type",
|
|
118
|
+
f"Context type must be a ContextType enum, got {type(context_type).__name__}",
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
self.context_types.add(context_type)
|
|
122
|
+
|
|
123
|
+
except ContextServiceError:
|
|
124
|
+
raise
|
|
125
|
+
except Exception as e:
|
|
126
|
+
raise ContextServiceError(
|
|
127
|
+
"context_type",
|
|
128
|
+
f"Unexpected error adding context type: {e}",
|
|
129
|
+
details=f"Context type: {context_type}",
|
|
130
|
+
) from e
|
|
131
|
+
|
|
132
|
+
def add_file_type(self, file_type: str) -> None:
|
|
133
|
+
"""
|
|
134
|
+
Add a file type to the parameters.
|
|
135
|
+
|
|
136
|
+
Args:
|
|
137
|
+
file_type: The file type to add (e.g., 'image', 'text', 'archive')
|
|
138
|
+
|
|
139
|
+
Raises:
|
|
140
|
+
ContextServiceError: If file_type is invalid or an unexpected
|
|
141
|
+
error occurs
|
|
142
|
+
"""
|
|
143
|
+
try:
|
|
144
|
+
# Input validation
|
|
145
|
+
if not file_type:
|
|
146
|
+
raise ContextServiceError(
|
|
147
|
+
"file_type", "File type cannot be None or empty"
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
if not isinstance(file_type, str):
|
|
151
|
+
raise ContextServiceError(
|
|
152
|
+
"file_type",
|
|
153
|
+
f"File type must be a string, got {type(file_type).__name__}",
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
file_type = file_type.strip()
|
|
157
|
+
if not file_type:
|
|
158
|
+
raise ContextServiceError(
|
|
159
|
+
"file_type", "File type cannot be empty after stripping"
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
if file_type in self.FILE_TYPE_EXTENSIONS:
|
|
163
|
+
self.file_types.add(file_type)
|
|
164
|
+
# Treat as custom extension
|
|
165
|
+
elif file_type.startswith("."):
|
|
166
|
+
self.custom_extensions.add(file_type.lower())
|
|
167
|
+
else:
|
|
168
|
+
self.custom_extensions.add(f".{file_type.lower()}")
|
|
169
|
+
|
|
170
|
+
except ContextServiceError:
|
|
171
|
+
raise
|
|
172
|
+
except Exception as e:
|
|
173
|
+
raise ContextServiceError(
|
|
174
|
+
"file_type",
|
|
175
|
+
f"Unexpected error adding file type: {e}",
|
|
176
|
+
details=f"File type: {file_type}",
|
|
177
|
+
) from e
|
|
178
|
+
|
|
179
|
+
def get_registry_paths(self) -> list[str]:
|
|
180
|
+
"""
|
|
181
|
+
Get registry paths for all configured context types.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
List of registry paths
|
|
185
|
+
|
|
186
|
+
Raises:
|
|
187
|
+
ContextServiceError: For unexpected errors
|
|
188
|
+
"""
|
|
189
|
+
try:
|
|
190
|
+
return [
|
|
191
|
+
self.REGISTRY_PATHS[context_type]
|
|
192
|
+
for context_type in self.context_types
|
|
193
|
+
if context_type in self.REGISTRY_PATHS
|
|
194
|
+
]
|
|
195
|
+
|
|
196
|
+
except Exception as e:
|
|
197
|
+
raise ContextServiceError(
|
|
198
|
+
"registry_paths",
|
|
199
|
+
f"Unexpected error getting registry paths: {e}",
|
|
200
|
+
details=f"Context types: {[ct.value for ct in self.context_types]}",
|
|
201
|
+
) from e
|
|
202
|
+
|
|
203
|
+
def get_command_parameter(self, context_type: ContextType) -> str:
|
|
204
|
+
"""
|
|
205
|
+
Get the appropriate command parameter for a context type.
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
context_type: The context type
|
|
209
|
+
|
|
210
|
+
Returns:
|
|
211
|
+
Command parameter string
|
|
212
|
+
|
|
213
|
+
Raises:
|
|
214
|
+
ContextServiceError: If context_type is invalid or an unexpected
|
|
215
|
+
error occurs
|
|
216
|
+
"""
|
|
217
|
+
try:
|
|
218
|
+
# Input validation
|
|
219
|
+
if not isinstance(context_type, ContextType):
|
|
220
|
+
raise ContextServiceError(
|
|
221
|
+
"command_parameter",
|
|
222
|
+
f"Context type must be a ContextType enum, got {type(context_type).__name__}",
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
return self.COMMAND_PARAMETERS.get(context_type, "%V")
|
|
226
|
+
|
|
227
|
+
except ContextServiceError:
|
|
228
|
+
raise
|
|
229
|
+
except Exception as e:
|
|
230
|
+
raise ContextServiceError(
|
|
231
|
+
"command_parameter",
|
|
232
|
+
f"Unexpected error getting command parameter: {e}",
|
|
233
|
+
details=f"Context type: {context_type}",
|
|
234
|
+
) from e
|
|
235
|
+
|
|
236
|
+
def get_file_extensions(self) -> set[str]:
|
|
237
|
+
"""
|
|
238
|
+
Get all file extensions for configured file types.
|
|
239
|
+
|
|
240
|
+
Returns:
|
|
241
|
+
Set of file extensions
|
|
242
|
+
|
|
243
|
+
Raises:
|
|
244
|
+
ContextServiceError: For unexpected errors
|
|
245
|
+
"""
|
|
246
|
+
try:
|
|
247
|
+
extensions = set()
|
|
248
|
+
|
|
249
|
+
# Add extensions from file types
|
|
250
|
+
for file_type in self.file_types:
|
|
251
|
+
if file_type in self.FILE_TYPE_EXTENSIONS:
|
|
252
|
+
extensions.update(self.FILE_TYPE_EXTENSIONS[file_type])
|
|
253
|
+
|
|
254
|
+
# Add custom extensions
|
|
255
|
+
extensions.update(self.custom_extensions)
|
|
256
|
+
|
|
257
|
+
return extensions
|
|
258
|
+
|
|
259
|
+
except Exception as e:
|
|
260
|
+
raise ContextServiceError(
|
|
261
|
+
"file_extensions",
|
|
262
|
+
f"Unexpected error getting file extensions: {e}",
|
|
263
|
+
details=f"File types: {list(self.file_types)}, Custom extensions: {list(self.custom_extensions)}",
|
|
264
|
+
) from e
|
|
265
|
+
|
|
266
|
+
def build_command(self, base_command: str, context_type: ContextType) -> str:
|
|
267
|
+
"""
|
|
268
|
+
Build the final command with appropriate parameters.
|
|
269
|
+
|
|
270
|
+
Args:
|
|
271
|
+
base_command: Base command without parameters
|
|
272
|
+
context_type: Context type for parameter selection
|
|
273
|
+
|
|
274
|
+
Returns:
|
|
275
|
+
Complete command with parameters
|
|
276
|
+
|
|
277
|
+
Raises:
|
|
278
|
+
ContextServiceError: If parameters are invalid or an unexpected
|
|
279
|
+
error occurs
|
|
280
|
+
"""
|
|
281
|
+
try:
|
|
282
|
+
# Input validation
|
|
283
|
+
if not base_command:
|
|
284
|
+
raise ContextServiceError(
|
|
285
|
+
"command_building", "Base command cannot be None or empty"
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
if not isinstance(base_command, str):
|
|
289
|
+
raise ContextServiceError(
|
|
290
|
+
"command_building",
|
|
291
|
+
f"Base command must be a string, got {type(base_command).__name__}",
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
if not isinstance(context_type, ContextType):
|
|
295
|
+
raise ContextServiceError(
|
|
296
|
+
"command_building",
|
|
297
|
+
f"Context type must be a ContextType enum, got {type(context_type).__name__}",
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
parameter = self.get_command_parameter(context_type)
|
|
301
|
+
return build_command_with_parameter(base_command, parameter)
|
|
302
|
+
|
|
303
|
+
except ContextServiceError:
|
|
304
|
+
raise
|
|
305
|
+
except Exception as e:
|
|
306
|
+
raise ContextServiceError(
|
|
307
|
+
"command_building",
|
|
308
|
+
f"Unexpected error building command: {e}",
|
|
309
|
+
details=f"Base command: {base_command}, Context type: {context_type}",
|
|
310
|
+
) from e
|
|
311
|
+
|
|
312
|
+
def validate_parameters(self) -> dict[str, str | bool | list]:
|
|
313
|
+
"""
|
|
314
|
+
Validate the current parameter configuration.
|
|
315
|
+
|
|
316
|
+
Returns:
|
|
317
|
+
Validation result dictionary
|
|
318
|
+
|
|
319
|
+
Raises:
|
|
320
|
+
ContextServiceError: For unexpected errors
|
|
321
|
+
"""
|
|
322
|
+
try:
|
|
323
|
+
errors = []
|
|
324
|
+
warnings = []
|
|
325
|
+
|
|
326
|
+
# Check if context types are specified
|
|
327
|
+
if not self.context_types:
|
|
328
|
+
errors.append("No context types specified")
|
|
329
|
+
|
|
330
|
+
# Check for conflicting context types
|
|
331
|
+
if (
|
|
332
|
+
ContextType.FILE in self.context_types
|
|
333
|
+
and ContextType.FILES in self.context_types
|
|
334
|
+
):
|
|
335
|
+
warnings.append(
|
|
336
|
+
"Both --file and --files specified, --files will take precedence"
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
# Check file types
|
|
340
|
+
if self.file_types:
|
|
341
|
+
invalid_types = self.file_types - set(self.FILE_TYPE_EXTENSIONS.keys())
|
|
342
|
+
if invalid_types:
|
|
343
|
+
warnings.append(f"Unknown file types: {', '.join(invalid_types)}")
|
|
344
|
+
|
|
345
|
+
# Check custom extensions
|
|
346
|
+
errors.extend(
|
|
347
|
+
f"Custom extension must start with '.': {ext}"
|
|
348
|
+
for ext in self.custom_extensions
|
|
349
|
+
if not ext.startswith(".")
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
return {
|
|
353
|
+
"valid": len(errors) == 0,
|
|
354
|
+
"errors": errors,
|
|
355
|
+
"warnings": warnings,
|
|
356
|
+
"context_types": [ct.value for ct in self.context_types],
|
|
357
|
+
"file_types": list(self.file_types),
|
|
358
|
+
"custom_extensions": list(self.custom_extensions),
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
except Exception as e:
|
|
362
|
+
raise ContextServiceError(
|
|
363
|
+
"validate_parameters",
|
|
364
|
+
f"Unexpected error validating parameters: {e}",
|
|
365
|
+
details="Failed to validate context parameters",
|
|
366
|
+
) from e
|
|
367
|
+
|
|
368
|
+
def get_description(self) -> str:
|
|
369
|
+
"""
|
|
370
|
+
Get a human-readable description of the current configuration.
|
|
371
|
+
|
|
372
|
+
Returns:
|
|
373
|
+
Description string
|
|
374
|
+
|
|
375
|
+
Raises:
|
|
376
|
+
ContextServiceError: For unexpected errors
|
|
377
|
+
"""
|
|
378
|
+
try:
|
|
379
|
+
parts = []
|
|
380
|
+
|
|
381
|
+
# Context types
|
|
382
|
+
if self.context_types:
|
|
383
|
+
context_names = [ct.value for ct in self.context_types]
|
|
384
|
+
parts.append(f"Context: {', '.join(context_names)}")
|
|
385
|
+
|
|
386
|
+
# File types
|
|
387
|
+
if self.file_types:
|
|
388
|
+
parts.append(f"File types: {', '.join(self.file_types)}")
|
|
389
|
+
|
|
390
|
+
# Custom extensions
|
|
391
|
+
if self.custom_extensions:
|
|
392
|
+
parts.append(f"Extensions: {', '.join(sorted(self.custom_extensions))}")
|
|
393
|
+
|
|
394
|
+
return (
|
|
395
|
+
" | ".join(parts)
|
|
396
|
+
if parts
|
|
397
|
+
else "Default context (directory + background)"
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
except Exception as e:
|
|
401
|
+
raise ContextServiceError(
|
|
402
|
+
"get_description",
|
|
403
|
+
f"Unexpected error getting description: {e}",
|
|
404
|
+
details="Failed to generate context description",
|
|
405
|
+
) from e
|
|
406
|
+
|
|
407
|
+
@classmethod
|
|
408
|
+
def from_flags(
|
|
409
|
+
cls,
|
|
410
|
+
root: bool = False,
|
|
411
|
+
file: bool = False,
|
|
412
|
+
files: bool = False,
|
|
413
|
+
background: bool = False,
|
|
414
|
+
file_types: list[str] | None = None,
|
|
415
|
+
extensions: list[str] | None = None,
|
|
416
|
+
) -> ContextParameters:
|
|
417
|
+
"""
|
|
418
|
+
Create ContextParameters from command line flags.
|
|
419
|
+
|
|
420
|
+
Args:
|
|
421
|
+
root: --root flag
|
|
422
|
+
file: --file flag
|
|
423
|
+
files: --files flag
|
|
424
|
+
background: --background flag
|
|
425
|
+
file_types: List of file types
|
|
426
|
+
extensions: List of custom extensions
|
|
427
|
+
|
|
428
|
+
Returns:
|
|
429
|
+
Configured ContextParameters instance
|
|
430
|
+
|
|
431
|
+
Raises:
|
|
432
|
+
ContextServiceError: If parameters are invalid or an unexpected
|
|
433
|
+
error occurs
|
|
434
|
+
"""
|
|
435
|
+
try:
|
|
436
|
+
# Input validation
|
|
437
|
+
if file_types is not None and not isinstance(file_types, list):
|
|
438
|
+
raise ContextServiceError(
|
|
439
|
+
"from_flags",
|
|
440
|
+
f"File types must be a list, got {type(file_types).__name__}",
|
|
441
|
+
)
|
|
442
|
+
|
|
443
|
+
if extensions is not None and not isinstance(extensions, list):
|
|
444
|
+
raise ContextServiceError(
|
|
445
|
+
"from_flags",
|
|
446
|
+
f"Extensions must be a list, got {type(extensions).__name__}",
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
params = cls()
|
|
450
|
+
|
|
451
|
+
# Add context types based on flags
|
|
452
|
+
if root:
|
|
453
|
+
params.add_context_type(ContextType.ROOT)
|
|
454
|
+
if file:
|
|
455
|
+
params.add_context_type(ContextType.FILE)
|
|
456
|
+
if files:
|
|
457
|
+
params.add_context_type(ContextType.FILES)
|
|
458
|
+
if background:
|
|
459
|
+
params.add_context_type(ContextType.BACKGROUND)
|
|
460
|
+
|
|
461
|
+
# If no specific context types specified, use defaults
|
|
462
|
+
if not any([root, file, files, background]):
|
|
463
|
+
params.add_context_type(ContextType.DIRECTORY)
|
|
464
|
+
params.add_context_type(ContextType.BACKGROUND)
|
|
465
|
+
|
|
466
|
+
# Add file types
|
|
467
|
+
if file_types:
|
|
468
|
+
for file_type in file_types:
|
|
469
|
+
params.add_file_type(file_type)
|
|
470
|
+
|
|
471
|
+
# Add custom extensions
|
|
472
|
+
if extensions:
|
|
473
|
+
for ext in extensions:
|
|
474
|
+
params.add_file_type(ext)
|
|
475
|
+
|
|
476
|
+
return params
|
|
477
|
+
|
|
478
|
+
except ContextServiceError:
|
|
479
|
+
raise
|
|
480
|
+
except Exception as e:
|
|
481
|
+
raise ContextServiceError(
|
|
482
|
+
"from_flags",
|
|
483
|
+
f"Unexpected error creating ContextParameters from flags: {e}",
|
|
484
|
+
details=f"Root: {root}, File: {file}, Files: {files}, Background: {background}",
|
|
485
|
+
) from e
|
|
486
|
+
|
|
487
|
+
@classmethod
|
|
488
|
+
def get_available_file_types(cls) -> dict[str, set[str]]:
|
|
489
|
+
"""
|
|
490
|
+
Get all available file types and their extensions.
|
|
491
|
+
|
|
492
|
+
Returns:
|
|
493
|
+
Dictionary of file types and their extensions
|
|
494
|
+
"""
|
|
495
|
+
return get_available_file_types()
|
|
496
|
+
|
|
497
|
+
@classmethod
|
|
498
|
+
def get_context_type_help(cls) -> str:
|
|
499
|
+
"""
|
|
500
|
+
Get help text for context types.
|
|
501
|
+
|
|
502
|
+
Returns:
|
|
503
|
+
Help text string
|
|
504
|
+
"""
|
|
505
|
+
return get_context_type_help()
|
|
506
|
+
|
|
507
|
+
@classmethod
|
|
508
|
+
def get_file_type_help(cls) -> str:
|
|
509
|
+
"""
|
|
510
|
+
Get help text for file types.
|
|
511
|
+
|
|
512
|
+
Returns:
|
|
513
|
+
Help text string
|
|
514
|
+
"""
|
|
515
|
+
return get_file_type_help()
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# CONTEXT REGISTRY PATHS - Registry path to context type mapping
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Registry path interpretation for context menu entries.
|
|
9
|
+
|
|
10
|
+
Pure mapping helpers: they read a registry path and tell which context type it
|
|
11
|
+
belongs to. No registry access, no side effects.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
# ///////////////////////////////////////////////////////////////
|
|
17
|
+
# IMPORTS
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# Local imports
|
|
20
|
+
from ...shared.configs.context import ContextTypesConfig
|
|
21
|
+
from .parameters import ContextType
|
|
22
|
+
|
|
23
|
+
# ///////////////////////////////////////////////////////////////
|
|
24
|
+
# FUNCTIONS
|
|
25
|
+
# ///////////////////////////////////////////////////////////////
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def context_type_from_registry_path(registry_path: str) -> ContextType:
|
|
29
|
+
"""
|
|
30
|
+
Determine the context type a registry path belongs to.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
registry_path: Registry path to interpret
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
ContextType: matching type, defaulting to ``DIRECTORY``.
|
|
37
|
+
"""
|
|
38
|
+
if (
|
|
39
|
+
ContextTypesConfig.REGISTRY_PATTERN_DIRECTORY_SHELL in registry_path
|
|
40
|
+
and "background" not in registry_path
|
|
41
|
+
):
|
|
42
|
+
return ContextType.DIRECTORY
|
|
43
|
+
if ContextTypesConfig.REGISTRY_PATTERN_DIRECTORY_BACKGROUND in registry_path:
|
|
44
|
+
return ContextType.BACKGROUND
|
|
45
|
+
if ContextTypesConfig.REGISTRY_PATTERN_DRIVE_SHELL in registry_path:
|
|
46
|
+
return ContextType.ROOT
|
|
47
|
+
if ContextTypesConfig.REGISTRY_PATTERN_FILE_SHELL in registry_path:
|
|
48
|
+
return ContextType.FILE
|
|
49
|
+
return ContextType.DIRECTORY
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# ///////////////////////////////////////////////////////////////
|
|
53
|
+
# PUBLIC API
|
|
54
|
+
# ///////////////////////////////////////////////////////////////
|
|
55
|
+
|
|
56
|
+
__all__ = ["context_type_from_registry_path"]
|