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,494 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# SYSTEM ENVIRONMENT SERVICE - System Environment Service (Singleton)
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
SystemEnvironmentService - Service for environment refresh and management.
|
|
9
|
+
|
|
10
|
+
Provides cross-platform environment refresh capabilities, including:
|
|
11
|
+
- Windows registry-based refresh
|
|
12
|
+
- Unix shell configuration reload
|
|
13
|
+
- Environment verification
|
|
14
|
+
- Environment information retrieval
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
# ///////////////////////////////////////////////////////////////
|
|
20
|
+
# IMPORTS
|
|
21
|
+
# ///////////////////////////////////////////////////////////////
|
|
22
|
+
# Standard library imports
|
|
23
|
+
import contextlib
|
|
24
|
+
import logging
|
|
25
|
+
import os
|
|
26
|
+
import platform
|
|
27
|
+
import tempfile
|
|
28
|
+
import time
|
|
29
|
+
from pathlib import Path
|
|
30
|
+
from threading import Lock
|
|
31
|
+
from typing import ClassVar
|
|
32
|
+
|
|
33
|
+
# Local imports
|
|
34
|
+
from ...exceptions.system import SystemServiceError
|
|
35
|
+
from ...shared.configs.system import SystemEnvironmentConfig
|
|
36
|
+
from ...shared.results.system_results import (
|
|
37
|
+
EnvironmentRefreshResult,
|
|
38
|
+
EnvironmentVerificationResult,
|
|
39
|
+
)
|
|
40
|
+
from ...utils.common import get_bin_module_path
|
|
41
|
+
from ...utils.system import (
|
|
42
|
+
combine_paths,
|
|
43
|
+
get_environment_info,
|
|
44
|
+
get_shell_config_files,
|
|
45
|
+
read_windows_registry_path,
|
|
46
|
+
)
|
|
47
|
+
from ..common.command_runner_service import CommandRunnerService
|
|
48
|
+
|
|
49
|
+
# ///////////////////////////////////////////////////////////////
|
|
50
|
+
# LOGGER SETUP
|
|
51
|
+
# ///////////////////////////////////////////////////////////////
|
|
52
|
+
|
|
53
|
+
logger = logging.getLogger(__name__)
|
|
54
|
+
_command_runner = CommandRunnerService()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# ///////////////////////////////////////////////////////////////
|
|
58
|
+
# SYSTEM ENVIRONMENT SERVICE CLASS
|
|
59
|
+
# ///////////////////////////////////////////////////////////////
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class SystemEnvironmentService:
|
|
63
|
+
"""Cross-platform environment refresh service (singleton)."""
|
|
64
|
+
|
|
65
|
+
_instance: ClassVar[SystemEnvironmentService | None] = None
|
|
66
|
+
_initialized: ClassVar[bool] = False
|
|
67
|
+
_lock: ClassVar[Lock] = Lock()
|
|
68
|
+
|
|
69
|
+
def __new__(cls) -> SystemEnvironmentService:
|
|
70
|
+
with cls._lock:
|
|
71
|
+
if cls._instance is None:
|
|
72
|
+
cls._instance = super().__new__(cls)
|
|
73
|
+
return cls._instance
|
|
74
|
+
|
|
75
|
+
def __init__(self) -> None:
|
|
76
|
+
"""Initialize the system environment service once."""
|
|
77
|
+
if SystemEnvironmentService._initialized:
|
|
78
|
+
return
|
|
79
|
+
SystemEnvironmentService._initialized = True
|
|
80
|
+
self.platform = platform.system().lower()
|
|
81
|
+
|
|
82
|
+
# ///////////////////////////////////////////////////////////////
|
|
83
|
+
# PUBLIC METHODS
|
|
84
|
+
# ///////////////////////////////////////////////////////////////
|
|
85
|
+
|
|
86
|
+
def refresh_environment(self) -> EnvironmentRefreshResult:
|
|
87
|
+
"""
|
|
88
|
+
Refresh environment variables from registry/system.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
EnvironmentRefreshResult: Result of the refresh operation
|
|
92
|
+
|
|
93
|
+
Raises:
|
|
94
|
+
EnvironmentRefreshError: If environment refresh fails
|
|
95
|
+
"""
|
|
96
|
+
start_time = time.time()
|
|
97
|
+
try:
|
|
98
|
+
if self.platform == "windows":
|
|
99
|
+
return self._refresh_windows_environment(start_time)
|
|
100
|
+
else:
|
|
101
|
+
return self._refresh_unix_environment(start_time)
|
|
102
|
+
except SystemServiceError:
|
|
103
|
+
raise
|
|
104
|
+
except Exception as e:
|
|
105
|
+
raise SystemServiceError(
|
|
106
|
+
operation="refresh_environment",
|
|
107
|
+
reason=f"Unexpected error during environment refresh: {e}",
|
|
108
|
+
details=f"Exception type: {type(e).__name__}",
|
|
109
|
+
) from e
|
|
110
|
+
|
|
111
|
+
def verify_environment_refresh(
|
|
112
|
+
self, command: str | None = None
|
|
113
|
+
) -> EnvironmentVerificationResult:
|
|
114
|
+
"""
|
|
115
|
+
Verify that environment refresh was successful by testing command accessibility.
|
|
116
|
+
|
|
117
|
+
On Windows, this executes RefreshEnv.cmd in a new cmd.exe session and tests
|
|
118
|
+
the command in that same session to ensure the PATH is updated.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
command: Command to test (default: SystemEnvironmentConfig.DEFAULT_VERIFICATION_COMMAND)
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
EnvironmentVerificationResult: Result of the verification operation
|
|
125
|
+
|
|
126
|
+
Raises:
|
|
127
|
+
EnvironmentRefreshError: If verification fails critically
|
|
128
|
+
"""
|
|
129
|
+
start_time = time.time()
|
|
130
|
+
if command is None:
|
|
131
|
+
command = SystemEnvironmentConfig.DEFAULT_VERIFICATION_COMMAND
|
|
132
|
+
|
|
133
|
+
try:
|
|
134
|
+
if self.platform == "windows":
|
|
135
|
+
return self._verify_windows_environment(command, start_time)
|
|
136
|
+
else:
|
|
137
|
+
return self._verify_unix_environment(command, start_time)
|
|
138
|
+
except SystemServiceError:
|
|
139
|
+
raise
|
|
140
|
+
except Exception as e:
|
|
141
|
+
logger.warning(f"Could not verify environment refresh: {e}")
|
|
142
|
+
return EnvironmentVerificationResult(
|
|
143
|
+
success=False,
|
|
144
|
+
message=f"Verification failed: {e}",
|
|
145
|
+
error=str(e),
|
|
146
|
+
command=command,
|
|
147
|
+
command_accessible=False,
|
|
148
|
+
verification_method="unknown",
|
|
149
|
+
verification_time=time.time() - start_time,
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
def get_environment_info(self) -> dict[str, str]:
|
|
153
|
+
"""
|
|
154
|
+
Get current environment information.
|
|
155
|
+
|
|
156
|
+
Returns:
|
|
157
|
+
Dict[str, str]: Dictionary of environment information
|
|
158
|
+
"""
|
|
159
|
+
return get_environment_info()
|
|
160
|
+
|
|
161
|
+
# ///////////////////////////////////////////////////////////////
|
|
162
|
+
# PRIVATE METHODS - WINDOWS
|
|
163
|
+
# ///////////////////////////////////////////////////////////////
|
|
164
|
+
|
|
165
|
+
def _refresh_windows_environment(
|
|
166
|
+
self, start_time: float
|
|
167
|
+
) -> EnvironmentRefreshResult:
|
|
168
|
+
"""
|
|
169
|
+
Refresh Windows environment variables from registry.
|
|
170
|
+
|
|
171
|
+
Args:
|
|
172
|
+
start_time: Start time of the refresh operation
|
|
173
|
+
|
|
174
|
+
Returns:
|
|
175
|
+
EnvironmentRefreshResult: Result of the refresh operation
|
|
176
|
+
|
|
177
|
+
Raises:
|
|
178
|
+
EnvironmentRefreshError: If registry access fails critically
|
|
179
|
+
"""
|
|
180
|
+
try:
|
|
181
|
+
hklm_path, hkcu_path = read_windows_registry_path()
|
|
182
|
+
combined_path = combine_paths(hklm_path, hkcu_path)
|
|
183
|
+
|
|
184
|
+
# Business logic: PATH empty - return result with success=False
|
|
185
|
+
if not combined_path:
|
|
186
|
+
return EnvironmentRefreshResult(
|
|
187
|
+
success=False,
|
|
188
|
+
message="Could not read PATH from registry",
|
|
189
|
+
error="Both HKLM and HKCU PATH values were empty or None",
|
|
190
|
+
platform=self.platform,
|
|
191
|
+
refresh_method="registry",
|
|
192
|
+
path_refreshed=False,
|
|
193
|
+
environment_info=get_environment_info(),
|
|
194
|
+
refresh_time=time.time() - start_time,
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
# Update current process environment
|
|
198
|
+
os.environ["PATH"] = combined_path
|
|
199
|
+
|
|
200
|
+
logger.info("Environment variables refreshed from registry")
|
|
201
|
+
return EnvironmentRefreshResult(
|
|
202
|
+
success=True,
|
|
203
|
+
message="Environment variables refreshed from registry",
|
|
204
|
+
platform=self.platform,
|
|
205
|
+
refresh_method="registry",
|
|
206
|
+
path_refreshed=True,
|
|
207
|
+
environment_info=get_environment_info(),
|
|
208
|
+
refresh_time=time.time() - start_time,
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
except OSError as e:
|
|
212
|
+
# Critical system errors - raise exception
|
|
213
|
+
raise SystemServiceError(
|
|
214
|
+
operation="refresh_windows_environment",
|
|
215
|
+
reason=f"Windows environment refresh failed: {e}",
|
|
216
|
+
details=f"Exception type: {type(e).__name__}",
|
|
217
|
+
) from e
|
|
218
|
+
except Exception as e:
|
|
219
|
+
# Wrap unexpected external exceptions - critical error
|
|
220
|
+
raise SystemServiceError(
|
|
221
|
+
operation="refresh_windows_environment",
|
|
222
|
+
reason=f"Windows environment refresh failed: {e}",
|
|
223
|
+
details=f"Exception type: {type(e).__name__}",
|
|
224
|
+
) from e
|
|
225
|
+
|
|
226
|
+
def _verify_windows_environment(
|
|
227
|
+
self, command: str, start_time: float
|
|
228
|
+
) -> EnvironmentVerificationResult:
|
|
229
|
+
"""
|
|
230
|
+
Verify Windows environment refresh using RefreshEnv.cmd.
|
|
231
|
+
|
|
232
|
+
Args:
|
|
233
|
+
command: Command to test
|
|
234
|
+
start_time: Start time of the verification operation
|
|
235
|
+
|
|
236
|
+
Returns:
|
|
237
|
+
EnvironmentVerificationResult: Result of the verification operation
|
|
238
|
+
"""
|
|
239
|
+
try:
|
|
240
|
+
refresh_env_cmd = (
|
|
241
|
+
get_bin_module_path() / SystemEnvironmentConfig.REFRESH_ENV_SCRIPT_NAME
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
if not refresh_env_cmd.exists() or not refresh_env_cmd.is_file():
|
|
245
|
+
logger.warning(
|
|
246
|
+
f"RefreshEnv.cmd not found at {refresh_env_cmd}, falling back to direct test"
|
|
247
|
+
)
|
|
248
|
+
return self._verify_direct_command(command, start_time)
|
|
249
|
+
|
|
250
|
+
# Resolve path for security
|
|
251
|
+
refresh_env_cmd = refresh_env_cmd.resolve()
|
|
252
|
+
|
|
253
|
+
# Create a temporary batch script that:
|
|
254
|
+
# 1. Calls RefreshEnv.cmd to refresh environment
|
|
255
|
+
# 2. Tests command --version in the same session
|
|
256
|
+
with tempfile.NamedTemporaryFile(
|
|
257
|
+
mode="w",
|
|
258
|
+
suffix=".bat",
|
|
259
|
+
delete=False,
|
|
260
|
+
encoding="utf-8",
|
|
261
|
+
) as temp_script:
|
|
262
|
+
temp_script_path = Path(temp_script.name).resolve()
|
|
263
|
+
# Write script that calls RefreshEnv then tests command
|
|
264
|
+
temp_script.write("@echo off\n")
|
|
265
|
+
temp_script.write(f'call "{refresh_env_cmd}"\n')
|
|
266
|
+
temp_script.write(
|
|
267
|
+
f"{command} {' '.join(SystemEnvironmentConfig.VERIFICATION_COMMAND_ARGS)}\n"
|
|
268
|
+
)
|
|
269
|
+
temp_script.write("if errorlevel 1 exit /b 1\n")
|
|
270
|
+
temp_script.write("exit /b 0\n")
|
|
271
|
+
|
|
272
|
+
try:
|
|
273
|
+
# Execute in a new cmd.exe session
|
|
274
|
+
cmd_exe = Path(
|
|
275
|
+
os.environ.get("COMSPEC", "C:\\Windows\\System32\\cmd.exe")
|
|
276
|
+
)
|
|
277
|
+
if not cmd_exe.is_file():
|
|
278
|
+
logger.warning(f"cmd.exe not found: {cmd_exe}")
|
|
279
|
+
return EnvironmentVerificationResult(
|
|
280
|
+
success=False,
|
|
281
|
+
message=f"cmd.exe not found: {cmd_exe}",
|
|
282
|
+
error="cmd.exe not found",
|
|
283
|
+
command=command,
|
|
284
|
+
command_accessible=False,
|
|
285
|
+
verification_method="refresh_env_cmd",
|
|
286
|
+
verification_time=time.time() - start_time,
|
|
287
|
+
temp_script_path=str(temp_script_path),
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
result = _command_runner.run_silent(
|
|
291
|
+
[str(cmd_exe), "/c", str(temp_script_path)],
|
|
292
|
+
timeout=SystemEnvironmentConfig.VERIFICATION_TIMEOUT,
|
|
293
|
+
encoding="utf-8",
|
|
294
|
+
errors="replace",
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
if result.returncode == 0:
|
|
298
|
+
logger.info(
|
|
299
|
+
f"Environment refresh verification successful - {command} is accessible"
|
|
300
|
+
)
|
|
301
|
+
return EnvironmentVerificationResult(
|
|
302
|
+
success=True,
|
|
303
|
+
message=f"Environment refresh verification successful - {command} is accessible",
|
|
304
|
+
command=command,
|
|
305
|
+
command_accessible=True,
|
|
306
|
+
verification_method="refresh_env_cmd",
|
|
307
|
+
verification_time=time.time() - start_time,
|
|
308
|
+
temp_script_path=str(temp_script_path),
|
|
309
|
+
)
|
|
310
|
+
else:
|
|
311
|
+
logger.warning(
|
|
312
|
+
f"Environment refresh completed but {command} verification failed"
|
|
313
|
+
)
|
|
314
|
+
return EnvironmentVerificationResult(
|
|
315
|
+
success=False,
|
|
316
|
+
message=f"Environment refresh completed but {command} verification failed",
|
|
317
|
+
error=f"Command returned exit code {result.returncode}",
|
|
318
|
+
command=command,
|
|
319
|
+
command_accessible=False,
|
|
320
|
+
verification_method="refresh_env_cmd",
|
|
321
|
+
verification_time=time.time() - start_time,
|
|
322
|
+
temp_script_path=str(temp_script_path),
|
|
323
|
+
)
|
|
324
|
+
finally:
|
|
325
|
+
# Clean up temp script
|
|
326
|
+
with contextlib.suppress(Exception):
|
|
327
|
+
temp_script_path.unlink()
|
|
328
|
+
|
|
329
|
+
except Exception as e:
|
|
330
|
+
logger.warning(
|
|
331
|
+
f"Could not verify environment refresh with RefreshEnv.cmd: {e}"
|
|
332
|
+
)
|
|
333
|
+
# Fallback to direct test
|
|
334
|
+
return self._verify_direct_command(command, start_time)
|
|
335
|
+
|
|
336
|
+
# ///////////////////////////////////////////////////////////////
|
|
337
|
+
# PRIVATE METHODS - UNIX
|
|
338
|
+
# ///////////////////////////////////////////////////////////////
|
|
339
|
+
|
|
340
|
+
def _refresh_unix_environment(self, start_time: float) -> EnvironmentRefreshResult:
|
|
341
|
+
"""
|
|
342
|
+
Refresh Unix environment variables.
|
|
343
|
+
|
|
344
|
+
Args:
|
|
345
|
+
start_time: Start time of the refresh operation
|
|
346
|
+
|
|
347
|
+
Returns:
|
|
348
|
+
EnvironmentRefreshResult: Result of the refresh operation
|
|
349
|
+
|
|
350
|
+
Raises:
|
|
351
|
+
EnvironmentRefreshError: If shell configuration reload fails
|
|
352
|
+
"""
|
|
353
|
+
try:
|
|
354
|
+
# On Unix systems, environment refresh is typically handled by the shell
|
|
355
|
+
# We can try to reload shell configuration files
|
|
356
|
+
shell_configs = get_shell_config_files()
|
|
357
|
+
|
|
358
|
+
if not shell_configs:
|
|
359
|
+
logger.info(
|
|
360
|
+
"No shell configuration files found, environment refresh skipped"
|
|
361
|
+
)
|
|
362
|
+
return EnvironmentRefreshResult(
|
|
363
|
+
success=True,
|
|
364
|
+
message="No shell configuration files found, environment refresh skipped",
|
|
365
|
+
platform=self.platform,
|
|
366
|
+
refresh_method="none",
|
|
367
|
+
path_refreshed=False,
|
|
368
|
+
environment_info=get_environment_info(),
|
|
369
|
+
refresh_time=time.time() - start_time,
|
|
370
|
+
)
|
|
371
|
+
|
|
372
|
+
# Try to reload shell configuration using bash
|
|
373
|
+
import shutil
|
|
374
|
+
|
|
375
|
+
bash_path = shutil.which("bash")
|
|
376
|
+
if not bash_path:
|
|
377
|
+
logger.info("bash not available, environment refresh skipped")
|
|
378
|
+
return EnvironmentRefreshResult(
|
|
379
|
+
success=True,
|
|
380
|
+
message="bash not available, environment refresh skipped",
|
|
381
|
+
platform=self.platform,
|
|
382
|
+
refresh_method="none",
|
|
383
|
+
path_refreshed=False,
|
|
384
|
+
environment_info=get_environment_info(),
|
|
385
|
+
refresh_time=time.time() - start_time,
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
# Try to source each config file
|
|
389
|
+
for config_file in shell_configs:
|
|
390
|
+
try:
|
|
391
|
+
result = _command_runner.run_silent(
|
|
392
|
+
[bash_path, "-c", f"source {config_file}"]
|
|
393
|
+
)
|
|
394
|
+
if result.returncode == 0:
|
|
395
|
+
logger.info(f"Reloaded shell configuration: {config_file}")
|
|
396
|
+
return EnvironmentRefreshResult(
|
|
397
|
+
success=True,
|
|
398
|
+
message=f"Reloaded shell configuration: {config_file}",
|
|
399
|
+
platform=self.platform,
|
|
400
|
+
refresh_method="shell_config",
|
|
401
|
+
path_refreshed=True,
|
|
402
|
+
environment_info=get_environment_info(),
|
|
403
|
+
refresh_time=time.time() - start_time,
|
|
404
|
+
)
|
|
405
|
+
except Exception as e:
|
|
406
|
+
logger.debug(f"Could not reload {config_file}: {e}")
|
|
407
|
+
continue
|
|
408
|
+
|
|
409
|
+
logger.info("Unix environment refresh completed (no configs reloaded)")
|
|
410
|
+
return EnvironmentRefreshResult(
|
|
411
|
+
success=True,
|
|
412
|
+
message="Unix environment refresh completed",
|
|
413
|
+
platform=self.platform,
|
|
414
|
+
refresh_method="shell_config",
|
|
415
|
+
path_refreshed=False,
|
|
416
|
+
environment_info=get_environment_info(),
|
|
417
|
+
refresh_time=time.time() - start_time,
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
except Exception as e:
|
|
421
|
+
raise SystemServiceError(
|
|
422
|
+
operation="refresh_unix_environment",
|
|
423
|
+
reason=f"Unix environment refresh failed: {e}",
|
|
424
|
+
details=f"Exception type: {type(e).__name__}",
|
|
425
|
+
) from e
|
|
426
|
+
|
|
427
|
+
def _verify_unix_environment(
|
|
428
|
+
self, command: str, start_time: float
|
|
429
|
+
) -> EnvironmentVerificationResult:
|
|
430
|
+
"""
|
|
431
|
+
Verify Unix environment refresh using direct command test.
|
|
432
|
+
|
|
433
|
+
Args:
|
|
434
|
+
command: Command to test
|
|
435
|
+
start_time: Start time of the verification operation
|
|
436
|
+
|
|
437
|
+
Returns:
|
|
438
|
+
EnvironmentVerificationResult: Result of the verification operation
|
|
439
|
+
"""
|
|
440
|
+
return self._verify_direct_command(command, start_time)
|
|
441
|
+
|
|
442
|
+
def _verify_direct_command(
|
|
443
|
+
self, command: str, start_time: float
|
|
444
|
+
) -> EnvironmentVerificationResult:
|
|
445
|
+
"""
|
|
446
|
+
Verify command accessibility using direct test.
|
|
447
|
+
|
|
448
|
+
Args:
|
|
449
|
+
command: Command to test
|
|
450
|
+
start_time: Start time of the verification operation
|
|
451
|
+
|
|
452
|
+
Returns:
|
|
453
|
+
EnvironmentVerificationResult: Result of the verification operation
|
|
454
|
+
"""
|
|
455
|
+
try:
|
|
456
|
+
result = _command_runner.run_silent(
|
|
457
|
+
[command, *SystemEnvironmentConfig.VERIFICATION_COMMAND_ARGS]
|
|
458
|
+
)
|
|
459
|
+
if result.returncode == 0:
|
|
460
|
+
logger.info(
|
|
461
|
+
f"Environment refresh verification successful - {command} is accessible"
|
|
462
|
+
)
|
|
463
|
+
return EnvironmentVerificationResult(
|
|
464
|
+
success=True,
|
|
465
|
+
message=f"Environment refresh verification successful - {command} is accessible",
|
|
466
|
+
command=command,
|
|
467
|
+
command_accessible=True,
|
|
468
|
+
verification_method="direct_test",
|
|
469
|
+
verification_time=time.time() - start_time,
|
|
470
|
+
)
|
|
471
|
+
else:
|
|
472
|
+
logger.warning(
|
|
473
|
+
f"Environment refresh completed but {command} not yet accessible in current session"
|
|
474
|
+
)
|
|
475
|
+
return EnvironmentVerificationResult(
|
|
476
|
+
success=False,
|
|
477
|
+
message=f"Environment refresh completed but {command} not yet accessible in current session",
|
|
478
|
+
error=f"Command returned exit code {result.returncode}",
|
|
479
|
+
command=command,
|
|
480
|
+
command_accessible=False,
|
|
481
|
+
verification_method="direct_test",
|
|
482
|
+
verification_time=time.time() - start_time,
|
|
483
|
+
)
|
|
484
|
+
except Exception as e:
|
|
485
|
+
logger.warning(f"Could not verify command {command}: {e}")
|
|
486
|
+
return EnvironmentVerificationResult(
|
|
487
|
+
success=False,
|
|
488
|
+
message=f"Could not verify command {command}: {e}",
|
|
489
|
+
error=str(e),
|
|
490
|
+
command=command,
|
|
491
|
+
command_accessible=False,
|
|
492
|
+
verification_method="direct_test",
|
|
493
|
+
verification_time=time.time() - start_time,
|
|
494
|
+
)
|