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,387 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# PATH - PATH Inspection and Backup Commands
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
PATH display functions for Works On My Machine.
|
|
9
|
+
|
|
10
|
+
Provides display functions for PATH inspection (live entries, a single
|
|
11
|
+
backup's content) and PATH backup/restore/listing results.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
# ///////////////////////////////////////////////////////////////
|
|
17
|
+
# IMPORTS
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# Standard library imports
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
# Third-party imports
|
|
23
|
+
from rich.panel import Panel
|
|
24
|
+
|
|
25
|
+
# Local imports
|
|
26
|
+
from ...shared.results import (
|
|
27
|
+
PathBackupContentResult,
|
|
28
|
+
PathBackupListResult,
|
|
29
|
+
PathBackupResult,
|
|
30
|
+
PathOperationResult,
|
|
31
|
+
)
|
|
32
|
+
from ..common import ezconsole, ezprinter
|
|
33
|
+
|
|
34
|
+
# ///////////////////////////////////////////////////////////////
|
|
35
|
+
# PANEL HELPERS
|
|
36
|
+
# ///////////////////////////////////////////////////////////////
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _entry_exists_label(entry: str) -> str:
|
|
40
|
+
"""Return "yes"/"no" for a PATH entry, or "?" when it cannot be probed.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
entry: A single PATH entry to probe for existence.
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
``"yes"`` if the entry exists, ``"no"`` if it does not, or ``"?"``
|
|
47
|
+
when the filesystem check raises an unexpected ``OSError`` (e.g. an
|
|
48
|
+
exotic errno from an SMB or network share entry).
|
|
49
|
+
"""
|
|
50
|
+
try:
|
|
51
|
+
return "yes" if Path(entry).exists() else "no"
|
|
52
|
+
except OSError:
|
|
53
|
+
return "?"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _show_panel(content: str, title: str, border_style: str) -> None:
|
|
57
|
+
"""Print a bordered panel using the shared WOMM panel styling.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
content: Body text of the panel.
|
|
61
|
+
title: Panel title.
|
|
62
|
+
border_style: Rich colour name; also drives the ``bright_`` body style.
|
|
63
|
+
"""
|
|
64
|
+
panel = Panel(
|
|
65
|
+
content,
|
|
66
|
+
title=title,
|
|
67
|
+
border_style=border_style,
|
|
68
|
+
style=f"bright_{border_style}",
|
|
69
|
+
padding=(1, 1),
|
|
70
|
+
width=80,
|
|
71
|
+
)
|
|
72
|
+
ezconsole.print("")
|
|
73
|
+
ezconsole.print(panel)
|
|
74
|
+
ezconsole.print("")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# ///////////////////////////////////////////////////////////////
|
|
78
|
+
# DISPLAY FUNCTIONS
|
|
79
|
+
# ///////////////////////////////////////////////////////////////
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
_OPERATION_PANELS: dict[str, tuple[str, str, str]] = {
|
|
83
|
+
"restore": (
|
|
84
|
+
"""PATH restored successfully from backup.
|
|
85
|
+
|
|
86
|
+
- Restart your terminal for the changes to take effect
|
|
87
|
+
- Use womm path backup list to list available backups
|
|
88
|
+
- Use womm path backup create to snapshot the restored PATH""",
|
|
89
|
+
"""The PATH could not be restored from the selected backup.
|
|
90
|
+
|
|
91
|
+
- Check that the backup file is readable and not corrupted
|
|
92
|
+
- Check permissions on the user environment variables
|
|
93
|
+
- Use womm path backup list to pick another backup""",
|
|
94
|
+
"Restore Complete",
|
|
95
|
+
),
|
|
96
|
+
"add": (
|
|
97
|
+
"""Your PATH now contains this entry.
|
|
98
|
+
|
|
99
|
+
- Restart your terminal for the change to take effect
|
|
100
|
+
- Use womm path list to check the resulting PATH
|
|
101
|
+
- Use womm path backup restore to undo this change""",
|
|
102
|
+
"""The entry could not be added to your PATH.
|
|
103
|
+
|
|
104
|
+
- Check that the directory exists and holds an executable
|
|
105
|
+
- A tool often lives in a bin subdirectory, not in its root
|
|
106
|
+
- Check permissions on the user environment variables""",
|
|
107
|
+
"Entry Added",
|
|
108
|
+
),
|
|
109
|
+
"remove": (
|
|
110
|
+
"""Your PATH no longer contains this entry.
|
|
111
|
+
|
|
112
|
+
- Restart your terminal for the change to take effect
|
|
113
|
+
- Use womm path list to check the resulting PATH
|
|
114
|
+
- Use womm path backup restore to undo this change""",
|
|
115
|
+
"""The entry could not be removed from your PATH.
|
|
116
|
+
|
|
117
|
+
- Use womm path list to check how the entry is spelled
|
|
118
|
+
- Check permissions on the user environment variables""",
|
|
119
|
+
"Entry Removed",
|
|
120
|
+
),
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def render_path_operation_result(
|
|
125
|
+
result: PathOperationResult,
|
|
126
|
+
context: str = "operation",
|
|
127
|
+
) -> None:
|
|
128
|
+
"""
|
|
129
|
+
Render a PATH operation Result (add/remove/restore).
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
result: Outcome returned by ``SystemPathInterface.add_to_path()``,
|
|
133
|
+
``remove_from_path()``, or ``restore_backup()``.
|
|
134
|
+
context: ``"add"``, ``"remove"`` or ``"restore"`` adds the panel of
|
|
135
|
+
that operation; any other value, including the default, renders
|
|
136
|
+
lines only.
|
|
137
|
+
"""
|
|
138
|
+
panels = _OPERATION_PANELS.get(context)
|
|
139
|
+
|
|
140
|
+
if result.success:
|
|
141
|
+
if result.path_modified:
|
|
142
|
+
ezprinter.success(result.message)
|
|
143
|
+
else:
|
|
144
|
+
ezprinter.info(result.message)
|
|
145
|
+
|
|
146
|
+
if panels:
|
|
147
|
+
success_text, _, title = panels
|
|
148
|
+
_show_panel(success_text, title, "green")
|
|
149
|
+
return
|
|
150
|
+
|
|
151
|
+
ezprinter.error(result.message or "PATH operation failed")
|
|
152
|
+
if result.error:
|
|
153
|
+
ezprinter.info(result.error)
|
|
154
|
+
|
|
155
|
+
if panels:
|
|
156
|
+
_, failure_text, _ = panels
|
|
157
|
+
_show_panel(failure_text, "Troubleshooting", "yellow")
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def render_path_backup_result(result: PathBackupResult) -> None:
|
|
161
|
+
"""
|
|
162
|
+
Render a PATH backup creation Result.
|
|
163
|
+
|
|
164
|
+
Args:
|
|
165
|
+
result: Outcome returned by ``SystemPathInterface.create_backup()``.
|
|
166
|
+
"""
|
|
167
|
+
if result.success:
|
|
168
|
+
ezprinter.success("PATH backup (JSON) created successfully!")
|
|
169
|
+
ezprinter.system(f"Backup location: {result.backup_location}")
|
|
170
|
+
if result.backup_file:
|
|
171
|
+
ezprinter.system(f"Backup file: {Path(result.backup_file).name}")
|
|
172
|
+
|
|
173
|
+
file_name = Path(result.backup_file).name if result.backup_file else "unknown"
|
|
174
|
+
_show_panel(
|
|
175
|
+
f"""PATH backup created successfully.
|
|
176
|
+
|
|
177
|
+
- Location: {result.backup_location}
|
|
178
|
+
- File: {file_name}
|
|
179
|
+
- Use womm path backup restore to restore this backup later
|
|
180
|
+
- Use womm path backup list to list every available backup""",
|
|
181
|
+
"Backup Information",
|
|
182
|
+
"yellow",
|
|
183
|
+
)
|
|
184
|
+
return
|
|
185
|
+
|
|
186
|
+
ezprinter.error(result.message or "PATH backup failed")
|
|
187
|
+
if result.error:
|
|
188
|
+
ezprinter.info(result.error)
|
|
189
|
+
|
|
190
|
+
_show_panel(
|
|
191
|
+
"""The PATH backup could not be created.
|
|
192
|
+
|
|
193
|
+
- Check write permissions on the backup directory
|
|
194
|
+
- Check available disk space
|
|
195
|
+
- Use womm path backup list to inspect the backup location""",
|
|
196
|
+
"Troubleshooting",
|
|
197
|
+
"yellow",
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def render_path_backup_list_result(result: PathBackupListResult) -> None:
|
|
202
|
+
"""
|
|
203
|
+
Render a PATH backup list Result.
|
|
204
|
+
|
|
205
|
+
Args:
|
|
206
|
+
result: Outcome returned by ``SystemPathInterface.list_backups()``.
|
|
207
|
+
"""
|
|
208
|
+
if not result.success:
|
|
209
|
+
ezprinter.error(result.message or "Failed to retrieve PATH backups")
|
|
210
|
+
if result.error:
|
|
211
|
+
ezprinter.info(result.error)
|
|
212
|
+
|
|
213
|
+
_show_panel(
|
|
214
|
+
"""The PATH backup list could not be retrieved.
|
|
215
|
+
|
|
216
|
+
- Check that the backup directory exists and is readable
|
|
217
|
+
- Check permissions on the WOMM data directory
|
|
218
|
+
- Use womm path backup create to create a first backup""",
|
|
219
|
+
"Troubleshooting",
|
|
220
|
+
"yellow",
|
|
221
|
+
)
|
|
222
|
+
return
|
|
223
|
+
|
|
224
|
+
ezprinter.system(f"Backup location: {result.backup_location}")
|
|
225
|
+
ezprinter.success("PATH backup information retrieved successfully!")
|
|
226
|
+
|
|
227
|
+
if not result.backups:
|
|
228
|
+
ezprinter.console.print("")
|
|
229
|
+
ezprinter.system("No backup files found")
|
|
230
|
+
|
|
231
|
+
_show_panel(
|
|
232
|
+
"""No PATH backup has been created yet.
|
|
233
|
+
|
|
234
|
+
- Use womm path backup create to create your first backup
|
|
235
|
+
- Backups are stored in the WOMM data directory
|
|
236
|
+
- Use womm path backup restore to restore one once it exists""",
|
|
237
|
+
"Getting Started",
|
|
238
|
+
"blue",
|
|
239
|
+
)
|
|
240
|
+
return
|
|
241
|
+
|
|
242
|
+
ezprinter.console.print("")
|
|
243
|
+
backup_table = ezprinter.create_backup_table(
|
|
244
|
+
[
|
|
245
|
+
{
|
|
246
|
+
"name": backup.name,
|
|
247
|
+
"size": backup.size,
|
|
248
|
+
"modified": backup.modified,
|
|
249
|
+
"description": f"{backup.path_entries} PATH entries",
|
|
250
|
+
}
|
|
251
|
+
for backup in result.backups
|
|
252
|
+
]
|
|
253
|
+
)
|
|
254
|
+
ezprinter.console.print(backup_table)
|
|
255
|
+
|
|
256
|
+
_show_panel(
|
|
257
|
+
"""PATH management commands:
|
|
258
|
+
|
|
259
|
+
- womm path list - Show the entries of your current PATH
|
|
260
|
+
- womm path add <dir> - Add a directory to your PATH
|
|
261
|
+
- womm path remove <dir> - Remove a directory from your PATH
|
|
262
|
+
- womm path backup create - Create a new PATH backup
|
|
263
|
+
- womm path backup list - List available PATH backups
|
|
264
|
+
- womm path backup show <name> - Inspect a backup's content
|
|
265
|
+
- womm path backup restore [name] - Restore PATH from a backup""",
|
|
266
|
+
"PATH Commands",
|
|
267
|
+
"blue",
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def render_path_entries_result(result: PathOperationResult) -> None:
|
|
272
|
+
"""
|
|
273
|
+
Render the entries of the current PATH.
|
|
274
|
+
|
|
275
|
+
Args:
|
|
276
|
+
result: Outcome returned by ``SystemPathInterface.list_path_entries()``.
|
|
277
|
+
"""
|
|
278
|
+
if not result.success:
|
|
279
|
+
ezprinter.error(result.message or "Failed to read the current PATH")
|
|
280
|
+
if result.error:
|
|
281
|
+
ezprinter.info(result.error)
|
|
282
|
+
|
|
283
|
+
_show_panel(
|
|
284
|
+
"""The current PATH could not be read.
|
|
285
|
+
|
|
286
|
+
- Check permissions on the user environment variables
|
|
287
|
+
- Use womm path backup list to inspect available backups""",
|
|
288
|
+
"Troubleshooting",
|
|
289
|
+
"yellow",
|
|
290
|
+
)
|
|
291
|
+
return
|
|
292
|
+
|
|
293
|
+
entries = result.path_entries or []
|
|
294
|
+
ezprinter.success(f"{len(entries)} entries in PATH")
|
|
295
|
+
|
|
296
|
+
if not entries:
|
|
297
|
+
ezprinter.console.print("")
|
|
298
|
+
ezprinter.system("PATH is empty")
|
|
299
|
+
else:
|
|
300
|
+
table = ezprinter.create_table(
|
|
301
|
+
title="Current PATH",
|
|
302
|
+
columns=[
|
|
303
|
+
("#", "cyan", True),
|
|
304
|
+
("Entry", "green", False),
|
|
305
|
+
("Exists", "yellow", True),
|
|
306
|
+
],
|
|
307
|
+
)
|
|
308
|
+
for index, entry in enumerate(entries, 1):
|
|
309
|
+
table.add_row(str(index), entry, _entry_exists_label(entry))
|
|
310
|
+
ezprinter.console.print("")
|
|
311
|
+
ezprinter.console.print(table)
|
|
312
|
+
|
|
313
|
+
_show_panel(
|
|
314
|
+
"""PATH management commands:
|
|
315
|
+
|
|
316
|
+
- womm path backup create - Snapshot the current PATH
|
|
317
|
+
- womm path backup list - List available PATH backups
|
|
318
|
+
- womm path backup show <name> - Inspect a backup's content""",
|
|
319
|
+
"PATH Commands",
|
|
320
|
+
"blue",
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def render_path_backup_content_result(result: PathBackupContentResult) -> None:
|
|
325
|
+
"""
|
|
326
|
+
Render the content of a single PATH backup.
|
|
327
|
+
|
|
328
|
+
Args:
|
|
329
|
+
result: Outcome returned by ``SystemPathInterface.read_backup()``.
|
|
330
|
+
"""
|
|
331
|
+
if not result.success:
|
|
332
|
+
ezprinter.error(result.message or "Failed to read the backup")
|
|
333
|
+
if result.error:
|
|
334
|
+
ezprinter.info(result.error)
|
|
335
|
+
|
|
336
|
+
_show_panel(
|
|
337
|
+
"""The requested backup could not be read.
|
|
338
|
+
|
|
339
|
+
- Use womm path backup list to see the available backup names
|
|
340
|
+
- Pass the file name only, not a path
|
|
341
|
+
- The backup file may be corrupted""",
|
|
342
|
+
"Troubleshooting",
|
|
343
|
+
"yellow",
|
|
344
|
+
)
|
|
345
|
+
return
|
|
346
|
+
|
|
347
|
+
entries = result.entries or []
|
|
348
|
+
ezprinter.success(f"Backup {result.name} contains {len(entries)} entries")
|
|
349
|
+
ezprinter.system(f"Created: {result.timestamp}")
|
|
350
|
+
ezprinter.system(f"Platform: {result.platform}")
|
|
351
|
+
ezprinter.system(f"PATH length: {result.length} chars")
|
|
352
|
+
|
|
353
|
+
if entries:
|
|
354
|
+
table = ezprinter.create_table(
|
|
355
|
+
title=f"Entries in {result.name}",
|
|
356
|
+
columns=[
|
|
357
|
+
("#", "cyan", True),
|
|
358
|
+
("Entry", "green", False),
|
|
359
|
+
],
|
|
360
|
+
)
|
|
361
|
+
for index, entry in enumerate(entries, 1):
|
|
362
|
+
table.add_row(str(index), entry)
|
|
363
|
+
ezprinter.console.print("")
|
|
364
|
+
ezprinter.console.print(table)
|
|
365
|
+
|
|
366
|
+
_show_panel(
|
|
367
|
+
"""Backup inspection commands:
|
|
368
|
+
|
|
369
|
+
- womm path backup restore - Restore your PATH from a backup
|
|
370
|
+
- womm path backup list - List available PATH backups
|
|
371
|
+
- womm path list - Compare against your current PATH""",
|
|
372
|
+
"Backup Content",
|
|
373
|
+
"blue",
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
# ///////////////////////////////////////////////////////////////
|
|
378
|
+
# PUBLIC API
|
|
379
|
+
# ///////////////////////////////////////////////////////////////
|
|
380
|
+
|
|
381
|
+
__all__ = [
|
|
382
|
+
"render_path_backup_content_result",
|
|
383
|
+
"render_path_backup_list_result",
|
|
384
|
+
"render_path_backup_result",
|
|
385
|
+
"render_path_entries_result",
|
|
386
|
+
"render_path_operation_result",
|
|
387
|
+
]
|
womm/utils/__init__.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# UTILS - Pure Utility Functions
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Pure utility functions for Works On My Machine.
|
|
9
|
+
|
|
10
|
+
This package contains stateless utility functions organized by domain.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
# ///////////////////////////////////////////////////////////////
|
|
16
|
+
# IMPORTS
|
|
17
|
+
# ///////////////////////////////////////////////////////////////
|
|
18
|
+
|
|
19
|
+
# ///////////////////////////////////////////////////////////////
|
|
20
|
+
# PUBLIC API - Sub-packages only
|
|
21
|
+
# ///////////////////////////////////////////////////////////////
|
|
22
|
+
|
|
23
|
+
__all__: list[str] = []
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# UTILS COMMON - Common Utility Functions
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Common pure utility functions for Works On My Machine.
|
|
9
|
+
|
|
10
|
+
This package contains stateless utility functions shared across the codebase:
|
|
11
|
+
- File scanning utilities (Python detection, path exclusion)
|
|
12
|
+
- Path resolution utilities (project root, assets, scripts)
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
# ///////////////////////////////////////////////////////////////
|
|
18
|
+
# IMPORTS
|
|
19
|
+
# ///////////////////////////////////////////////////////////////
|
|
20
|
+
# Local imports
|
|
21
|
+
from .file_scanner_utils import (
|
|
22
|
+
contains_security_sensitive_pattern,
|
|
23
|
+
is_python_file,
|
|
24
|
+
should_exclude_path,
|
|
25
|
+
)
|
|
26
|
+
from .path_resolver_utils import (
|
|
27
|
+
get_assets_module_path,
|
|
28
|
+
get_bin_module_path,
|
|
29
|
+
get_shared_module_path,
|
|
30
|
+
resolve_script_path,
|
|
31
|
+
validate_script_exists,
|
|
32
|
+
)
|
|
33
|
+
from .safe_fs_utils import safe_rmtree
|
|
34
|
+
|
|
35
|
+
# ///////////////////////////////////////////////////////////////
|
|
36
|
+
# PUBLIC API
|
|
37
|
+
# ///////////////////////////////////////////////////////////////
|
|
38
|
+
|
|
39
|
+
__all__ = [
|
|
40
|
+
"contains_security_sensitive_pattern",
|
|
41
|
+
"get_assets_module_path",
|
|
42
|
+
"get_bin_module_path",
|
|
43
|
+
"get_shared_module_path",
|
|
44
|
+
"is_python_file",
|
|
45
|
+
"resolve_script_path",
|
|
46
|
+
"should_exclude_path",
|
|
47
|
+
"safe_rmtree",
|
|
48
|
+
"validate_script_exists",
|
|
49
|
+
]
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# FILE SCANNER UTILS - Pure File Scanner Utilities
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Pure utility functions for file scanning operations.
|
|
9
|
+
|
|
10
|
+
This module provides stateless functions for:
|
|
11
|
+
- Python file detection
|
|
12
|
+
- Path exclusion checking
|
|
13
|
+
- File extension validation
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# IMPORTS
|
|
20
|
+
# ///////////////////////////////////////////////////////////////
|
|
21
|
+
# Standard library imports
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
|
|
24
|
+
# Local imports
|
|
25
|
+
from ...shared.configs.security import FileScannerConfig
|
|
26
|
+
|
|
27
|
+
# ///////////////////////////////////////////////////////////////
|
|
28
|
+
# FILE DETECTION FUNCTIONS
|
|
29
|
+
# ///////////////////////////////////////////////////////////////
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def is_python_file(file_path: Path) -> bool:
|
|
33
|
+
"""Check if a file is a Python file.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
file_path: File path to check
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
bool: True if file is a Python file, False otherwise
|
|
40
|
+
"""
|
|
41
|
+
try:
|
|
42
|
+
if not file_path.exists():
|
|
43
|
+
return False
|
|
44
|
+
|
|
45
|
+
if not file_path.is_file():
|
|
46
|
+
return False
|
|
47
|
+
|
|
48
|
+
return file_path.suffix.lower() in FileScannerConfig.PYTHON_EXTENSIONS
|
|
49
|
+
|
|
50
|
+
except Exception:
|
|
51
|
+
# Return False on any error - this is a pure utility function
|
|
52
|
+
return False
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# ///////////////////////////////////////////////////////////////
|
|
56
|
+
# PATH EXCLUSION FUNCTIONS
|
|
57
|
+
# ///////////////////////////////////////////////////////////////
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def should_exclude_path(path: Path) -> bool:
|
|
61
|
+
"""Check if a path should be excluded from scanning.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
path: Path to check
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
bool: True if path should be excluded, False otherwise
|
|
68
|
+
"""
|
|
69
|
+
try:
|
|
70
|
+
# Check if any part of the path matches excluded patterns
|
|
71
|
+
return any(part in FileScannerConfig.EXCLUDED_DIRS for part in path.parts)
|
|
72
|
+
except Exception:
|
|
73
|
+
# Exclude on error for safety
|
|
74
|
+
return True
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# ///////////////////////////////////////////////////////////////
|
|
78
|
+
# SECURITY PATTERN FUNCTIONS
|
|
79
|
+
# ///////////////////////////////////////////////////////////////
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def contains_security_sensitive_pattern(file_path: Path | str) -> bool:
|
|
83
|
+
"""Check if a file path contains security-sensitive patterns.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
file_path: File path to check (Path or string)
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
bool: True if path contains security-sensitive patterns, False otherwise
|
|
90
|
+
"""
|
|
91
|
+
try:
|
|
92
|
+
file_str = str(file_path).lower()
|
|
93
|
+
return any(
|
|
94
|
+
pattern in file_str
|
|
95
|
+
for pattern in FileScannerConfig.SECURITY_SENSITIVE_PATTERNS
|
|
96
|
+
)
|
|
97
|
+
except Exception:
|
|
98
|
+
# Return False on error - conservative approach
|
|
99
|
+
return False
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# ///////////////////////////////////////////////////////////////
|
|
103
|
+
# PUBLIC API
|
|
104
|
+
# ///////////////////////////////////////////////////////////////
|
|
105
|
+
|
|
106
|
+
__all__ = [
|
|
107
|
+
"contains_security_sensitive_pattern",
|
|
108
|
+
"is_python_file",
|
|
109
|
+
"should_exclude_path",
|
|
110
|
+
]
|