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,557 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# INTERACTIVE WIZARD - Context Menu Interactive Wizard
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Interactive wizard for context menu configuration.
|
|
9
|
+
|
|
10
|
+
This module provides an interactive step-by-step wizard for configuring
|
|
11
|
+
context menu entries, making it easy for users to set up their scripts
|
|
12
|
+
without needing to know all the technical details.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
# ///////////////////////////////////////////////////////////////
|
|
18
|
+
# IMPORTS
|
|
19
|
+
# ///////////////////////////////////////////////////////////////
|
|
20
|
+
# Standard library imports
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
try:
|
|
24
|
+
from InquirerPy import inquirer
|
|
25
|
+
from InquirerPy.validator import PathValidator
|
|
26
|
+
|
|
27
|
+
INQUIRERPY_AVAILABLE = True
|
|
28
|
+
except ImportError:
|
|
29
|
+
INQUIRERPY_AVAILABLE = False
|
|
30
|
+
|
|
31
|
+
# Local imports
|
|
32
|
+
from ...services.context import ContextParameters, ContextType
|
|
33
|
+
from ..common.interactive_menu import InteractiveMenu
|
|
34
|
+
from ..common.logging import ezconsole, ezprinter
|
|
35
|
+
|
|
36
|
+
# ///////////////////////////////////////////////////////////////
|
|
37
|
+
# CLASSES
|
|
38
|
+
# ///////////////////////////////////////////////////////////////
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class ContextMenuWizard:
|
|
42
|
+
"""Interactive wizard for context menu configuration."""
|
|
43
|
+
|
|
44
|
+
@staticmethod
|
|
45
|
+
def run_setup() -> tuple[
|
|
46
|
+
str | None, str | None, str | None, ContextParameters | None
|
|
47
|
+
]:
|
|
48
|
+
"""
|
|
49
|
+
Run the complete interactive setup wizard.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
Tuple of (script_path, label, icon, context_params) or (None, None, None, None) if cancelled
|
|
53
|
+
"""
|
|
54
|
+
ezprinter.info("🎯 Interactive Context Menu Setup")
|
|
55
|
+
ezprinter.info("=" * 50)
|
|
56
|
+
|
|
57
|
+
# Step 1: Select script file
|
|
58
|
+
ezconsole.print("", style="dim")
|
|
59
|
+
ezconsole.print("📁 Step 1: Select script file", style="bold blue")
|
|
60
|
+
script_path = ContextMenuWizard._select_script()
|
|
61
|
+
if not script_path:
|
|
62
|
+
return None, None, None, None
|
|
63
|
+
|
|
64
|
+
# Step 2: Enter label
|
|
65
|
+
ezconsole.print("\n" + (":" * 80) + "\n", style="dim")
|
|
66
|
+
ezconsole.print("🏷️ Step 2: Enter display label", style="bold blue")
|
|
67
|
+
label = ContextMenuWizard._get_label()
|
|
68
|
+
if not label:
|
|
69
|
+
return None, None, None, None
|
|
70
|
+
|
|
71
|
+
# Step 3: Select icon
|
|
72
|
+
ezconsole.print("\n" + (":" * 80) + "\n", style="dim")
|
|
73
|
+
ezconsole.print("🎨 Step 3: Select icon", style="bold blue")
|
|
74
|
+
icon = ContextMenuWizard._select_icon(script_path)
|
|
75
|
+
|
|
76
|
+
# Step 4: Select context type
|
|
77
|
+
ezconsole.print("\n" + (":" * 80) + "\n", style="dim")
|
|
78
|
+
ezconsole.print("🎯 Step 4: Select context type", style="bold blue")
|
|
79
|
+
context_params = ContextMenuWizard._select_context()
|
|
80
|
+
|
|
81
|
+
return script_path, label, icon, context_params
|
|
82
|
+
|
|
83
|
+
@staticmethod
|
|
84
|
+
def _select_script() -> str | None:
|
|
85
|
+
"""Interactive script file selection."""
|
|
86
|
+
if INQUIRERPY_AVAILABLE:
|
|
87
|
+
# Use InquirerPy for better file selection
|
|
88
|
+
return ContextMenuWizard._select_script_with_inquirer()
|
|
89
|
+
else:
|
|
90
|
+
# Fallback to custom menu
|
|
91
|
+
return ContextMenuWizard._select_script_fallback()
|
|
92
|
+
|
|
93
|
+
@staticmethod
|
|
94
|
+
def _select_script_with_inquirer() -> str | None:
|
|
95
|
+
"""Select script using InquirerPy file browser."""
|
|
96
|
+
try:
|
|
97
|
+
# Create a custom validator for script files
|
|
98
|
+
class ScriptFileValidator(PathValidator):
|
|
99
|
+
def __init__(self):
|
|
100
|
+
super().__init__()
|
|
101
|
+
self.script_extensions = {".py", ".bat", ".ps1", ".exe", ".cmd"}
|
|
102
|
+
|
|
103
|
+
def validate(self, document):
|
|
104
|
+
result = super().validate(document)
|
|
105
|
+
# FIXME: dead branch. PathValidator.validate() returns None and
|
|
106
|
+
# raises on failure, so this never runs: the extension check below
|
|
107
|
+
# is never applied. Fixing it changes validation behaviour.
|
|
108
|
+
if result: # ty: ignore[redundant-condition]
|
|
109
|
+
path = Path(document.text)
|
|
110
|
+
if (
|
|
111
|
+
path.is_file()
|
|
112
|
+
and path.suffix.lower() in self.script_extensions
|
|
113
|
+
):
|
|
114
|
+
return True
|
|
115
|
+
else:
|
|
116
|
+
raise ValueError(
|
|
117
|
+
f"File must be a script ({', '.join(self.script_extensions)})"
|
|
118
|
+
)
|
|
119
|
+
return result
|
|
120
|
+
|
|
121
|
+
# Use InquirerPy file browser
|
|
122
|
+
script_path = inquirer.filepath( # pyright: ignore[reportPrivateImportUsage]
|
|
123
|
+
message="Select script file:",
|
|
124
|
+
default=str(Path.cwd()),
|
|
125
|
+
validate=ScriptFileValidator(),
|
|
126
|
+
only_files=True,
|
|
127
|
+
only_directories=False,
|
|
128
|
+
transformer=lambda result: str(Path(result).resolve()),
|
|
129
|
+
filter=lambda result: str(Path(result).resolve()),
|
|
130
|
+
).execute()
|
|
131
|
+
|
|
132
|
+
if script_path:
|
|
133
|
+
return script_path
|
|
134
|
+
else:
|
|
135
|
+
ezprinter.info("File selection cancelled")
|
|
136
|
+
return None
|
|
137
|
+
|
|
138
|
+
except Exception as e:
|
|
139
|
+
ezprinter.error(f"Error with file browser: {e}")
|
|
140
|
+
ezprinter.info("Falling back to manual input...")
|
|
141
|
+
return ContextMenuWizard._select_script_fallback()
|
|
142
|
+
|
|
143
|
+
@staticmethod
|
|
144
|
+
def _select_script_fallback() -> str | None:
|
|
145
|
+
"""Fallback script selection using custom menu."""
|
|
146
|
+
menu = InteractiveMenu(
|
|
147
|
+
title="Select Script File",
|
|
148
|
+
instruction="Choose how to specify the script file",
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
items = [
|
|
152
|
+
{"label": "Browse current directory", "value": "browse"},
|
|
153
|
+
{"label": "Enter path manually", "value": "manual"},
|
|
154
|
+
{"label": "Cancel", "value": "cancel"},
|
|
155
|
+
]
|
|
156
|
+
|
|
157
|
+
selected = menu.select_from_list(items, display_func=lambda item: item["label"])
|
|
158
|
+
if not selected:
|
|
159
|
+
return None
|
|
160
|
+
|
|
161
|
+
if selected["value"] == "browse":
|
|
162
|
+
return ContextMenuWizard._browse_for_script()
|
|
163
|
+
elif selected["value"] == "manual":
|
|
164
|
+
ezprinter.info("Enter the full path to your script:")
|
|
165
|
+
path = input("> ").strip()
|
|
166
|
+
if path and Path(path).exists():
|
|
167
|
+
return path
|
|
168
|
+
else:
|
|
169
|
+
ezprinter.error("Invalid path or file not found")
|
|
170
|
+
return None
|
|
171
|
+
else: # Cancel
|
|
172
|
+
return None
|
|
173
|
+
|
|
174
|
+
@staticmethod
|
|
175
|
+
def _browse_for_script() -> str | None:
|
|
176
|
+
"""Browse for script files in current directory."""
|
|
177
|
+
current_dir = Path.cwd()
|
|
178
|
+
|
|
179
|
+
# Supported script extensions
|
|
180
|
+
script_extensions = {".py", ".bat", ".ps1", ".exe", ".cmd"}
|
|
181
|
+
|
|
182
|
+
# Find script files in current directory
|
|
183
|
+
script_files = [
|
|
184
|
+
file
|
|
185
|
+
for file in current_dir.iterdir()
|
|
186
|
+
if file.is_file() and file.suffix.lower() in script_extensions
|
|
187
|
+
]
|
|
188
|
+
|
|
189
|
+
if not script_files:
|
|
190
|
+
ezprinter.error("No script files found in current directory")
|
|
191
|
+
ezprinter.info(f"Current directory: {current_dir}")
|
|
192
|
+
ezprinter.info(f"Supported extensions: {', '.join(script_extensions)}")
|
|
193
|
+
return None
|
|
194
|
+
|
|
195
|
+
# Sort files by name
|
|
196
|
+
script_files.sort(key=lambda x: x.name.lower())
|
|
197
|
+
|
|
198
|
+
# Create selection menu
|
|
199
|
+
menu = InteractiveMenu(
|
|
200
|
+
title="Select Script File",
|
|
201
|
+
instruction=f"Found {len(script_files)} script files in {current_dir.name}",
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
items = []
|
|
205
|
+
for file in script_files:
|
|
206
|
+
file_info = f"{file.name} ({file.suffix.upper()})"
|
|
207
|
+
items.append({"label": file_info, "type": "file", "path": file})
|
|
208
|
+
|
|
209
|
+
items.append(
|
|
210
|
+
{
|
|
211
|
+
"label": "📁 Browse parent directory",
|
|
212
|
+
"type": "parent",
|
|
213
|
+
"path": current_dir.parent,
|
|
214
|
+
}
|
|
215
|
+
)
|
|
216
|
+
items.append({"label": "❌ Cancel", "type": "cancel", "path": None})
|
|
217
|
+
|
|
218
|
+
selected = menu.select_from_list(items, display_func=lambda item: item["label"])
|
|
219
|
+
if not selected or selected["type"] == "cancel":
|
|
220
|
+
return None
|
|
221
|
+
|
|
222
|
+
if selected["type"] == "file":
|
|
223
|
+
return str(selected["path"].resolve())
|
|
224
|
+
if selected["type"] == "parent":
|
|
225
|
+
parent_dir = selected["path"]
|
|
226
|
+
if parent_dir != current_dir: # Not at root
|
|
227
|
+
return ContextMenuWizard._browse_directory(parent_dir)
|
|
228
|
+
ezprinter.error("Already at root directory")
|
|
229
|
+
return None
|
|
230
|
+
return None
|
|
231
|
+
|
|
232
|
+
@staticmethod
|
|
233
|
+
def _browse_directory(directory: Path) -> str | None:
|
|
234
|
+
"""Browse a specific directory for script files."""
|
|
235
|
+
if not directory.exists() or not directory.is_dir():
|
|
236
|
+
ezprinter.error(f"Invalid directory: {directory}")
|
|
237
|
+
return None
|
|
238
|
+
|
|
239
|
+
# Supported script extensions
|
|
240
|
+
script_extensions = {".py", ".bat", ".ps1", ".exe", ".cmd"}
|
|
241
|
+
|
|
242
|
+
# Get subdirectories and script files
|
|
243
|
+
subdirs = []
|
|
244
|
+
script_files = []
|
|
245
|
+
|
|
246
|
+
try:
|
|
247
|
+
for item in directory.iterdir():
|
|
248
|
+
if item.is_dir():
|
|
249
|
+
subdirs.append(item)
|
|
250
|
+
elif item.is_file() and item.suffix.lower() in script_extensions:
|
|
251
|
+
script_files.append(item)
|
|
252
|
+
except PermissionError:
|
|
253
|
+
ezprinter.error(f"Permission denied accessing directory: {directory}")
|
|
254
|
+
return None
|
|
255
|
+
|
|
256
|
+
# Sort items
|
|
257
|
+
subdirs.sort(key=lambda x: x.name.lower())
|
|
258
|
+
script_files.sort(key=lambda x: x.name.lower())
|
|
259
|
+
|
|
260
|
+
# Create options list
|
|
261
|
+
items = []
|
|
262
|
+
|
|
263
|
+
# Add parent directory option (if not at root)
|
|
264
|
+
if directory.parent != directory:
|
|
265
|
+
items.append(
|
|
266
|
+
{
|
|
267
|
+
"label": "📁 .. (Parent directory)",
|
|
268
|
+
"type": "parent",
|
|
269
|
+
"path": directory.parent,
|
|
270
|
+
}
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
# Add subdirectories
|
|
274
|
+
for subdir in subdirs:
|
|
275
|
+
items.append({"label": f"📁 {subdir.name}/", "type": "dir", "path": subdir})
|
|
276
|
+
|
|
277
|
+
# Add script files
|
|
278
|
+
for file in script_files:
|
|
279
|
+
items.append(
|
|
280
|
+
{
|
|
281
|
+
"label": f"📄 {file.name} ({file.suffix.upper()})",
|
|
282
|
+
"type": "file",
|
|
283
|
+
"path": file,
|
|
284
|
+
}
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
# Add cancel option
|
|
288
|
+
items.append({"label": "❌ Cancel", "type": "cancel", "path": None})
|
|
289
|
+
|
|
290
|
+
if not script_files and not subdirs:
|
|
291
|
+
ezprinter.error(f"No script files or subdirectories found in {directory}")
|
|
292
|
+
return None
|
|
293
|
+
|
|
294
|
+
# Show selection menu
|
|
295
|
+
menu = InteractiveMenu(
|
|
296
|
+
title="Browse Directory",
|
|
297
|
+
instruction=f"Current: {directory} | Files: {len(script_files)} | Dirs: {len(subdirs)}",
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
selected = menu.select_from_list(items, display_func=lambda item: item["label"])
|
|
301
|
+
if not selected or selected["type"] == "cancel":
|
|
302
|
+
return None
|
|
303
|
+
|
|
304
|
+
if selected["type"] == "file":
|
|
305
|
+
return str(selected["path"].resolve())
|
|
306
|
+
if selected["type"] in {"dir", "parent"}:
|
|
307
|
+
return ContextMenuWizard._browse_directory(selected["path"])
|
|
308
|
+
return None
|
|
309
|
+
|
|
310
|
+
@staticmethod
|
|
311
|
+
def _get_label() -> str | None:
|
|
312
|
+
"""Interactive label input."""
|
|
313
|
+
if INQUIRERPY_AVAILABLE:
|
|
314
|
+
return ContextMenuWizard._get_label_with_inquirer()
|
|
315
|
+
else:
|
|
316
|
+
return ContextMenuWizard._get_label_fallback()
|
|
317
|
+
|
|
318
|
+
@staticmethod
|
|
319
|
+
def _get_label_with_inquirer() -> str | None:
|
|
320
|
+
"""Get label using InquirerPy."""
|
|
321
|
+
try:
|
|
322
|
+
label = inquirer.text( # pyright: ignore[reportPrivateImportUsage]
|
|
323
|
+
message="Enter the label to display in the context menu:",
|
|
324
|
+
validate=lambda result: len(result.strip()) > 0 if result else False,
|
|
325
|
+
invalid_message="Label cannot be empty",
|
|
326
|
+
filter=lambda result: result.strip(),
|
|
327
|
+
).execute()
|
|
328
|
+
|
|
329
|
+
return label if label else None
|
|
330
|
+
|
|
331
|
+
except Exception as e:
|
|
332
|
+
ezprinter.error(f"Error with label input: {e}")
|
|
333
|
+
ezprinter.info("Falling back to manual input...")
|
|
334
|
+
return ContextMenuWizard._get_label_fallback()
|
|
335
|
+
|
|
336
|
+
@staticmethod
|
|
337
|
+
def _get_label_fallback() -> str | None:
|
|
338
|
+
"""Fallback label input."""
|
|
339
|
+
ezprinter.info("Enter the label to display in the context menu:")
|
|
340
|
+
label = input("> ").strip()
|
|
341
|
+
if not label:
|
|
342
|
+
ezprinter.error("Label cannot be empty")
|
|
343
|
+
return None
|
|
344
|
+
return label
|
|
345
|
+
|
|
346
|
+
@staticmethod
|
|
347
|
+
def _select_icon(_script_path: str) -> str | None:
|
|
348
|
+
"""Interactive icon selection."""
|
|
349
|
+
# Note: script_path is kept for future use when auto-detecting script icons
|
|
350
|
+
if INQUIRERPY_AVAILABLE:
|
|
351
|
+
return ContextMenuWizard._select_icon_with_inquirer()
|
|
352
|
+
else:
|
|
353
|
+
return ContextMenuWizard._select_icon_fallback()
|
|
354
|
+
|
|
355
|
+
@staticmethod
|
|
356
|
+
def _select_icon_with_inquirer() -> str | None:
|
|
357
|
+
"""Select icon using InquirerPy."""
|
|
358
|
+
try:
|
|
359
|
+
# First, ask for icon type
|
|
360
|
+
icon_type = inquirer.select( # pyright: ignore[reportPrivateImportUsage]
|
|
361
|
+
message="Choose icon type:",
|
|
362
|
+
choices=[
|
|
363
|
+
{"name": "Auto-detect (recommended)", "value": "auto"},
|
|
364
|
+
{"name": "Use script's own icon", "value": "script"},
|
|
365
|
+
{"name": "Browse for icon file", "value": "browse"},
|
|
366
|
+
{"name": "Enter custom path", "value": "manual"},
|
|
367
|
+
{"name": "No icon", "value": "none"},
|
|
368
|
+
],
|
|
369
|
+
default="auto",
|
|
370
|
+
).execute()
|
|
371
|
+
|
|
372
|
+
if icon_type == "auto":
|
|
373
|
+
return "auto"
|
|
374
|
+
elif icon_type == "script":
|
|
375
|
+
return "script"
|
|
376
|
+
elif icon_type == "none":
|
|
377
|
+
return None
|
|
378
|
+
elif icon_type == "browse":
|
|
379
|
+
# Use InquirerPy file browser for icon files
|
|
380
|
+
class IconFileValidator(PathValidator):
|
|
381
|
+
def __init__(self):
|
|
382
|
+
super().__init__()
|
|
383
|
+
self.icon_extensions = {
|
|
384
|
+
".ico",
|
|
385
|
+
".exe",
|
|
386
|
+
".dll",
|
|
387
|
+
".png",
|
|
388
|
+
".jpg",
|
|
389
|
+
".jpeg",
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
def validate(self, document):
|
|
393
|
+
result = super().validate(document)
|
|
394
|
+
# FIXME: dead branch. PathValidator.validate() returns None and
|
|
395
|
+
# raises on failure, so this never runs: the extension check below
|
|
396
|
+
# is never applied. Fixing it changes validation behaviour.
|
|
397
|
+
if result: # ty: ignore[redundant-condition]
|
|
398
|
+
path = Path(document.text)
|
|
399
|
+
if (
|
|
400
|
+
path.is_file()
|
|
401
|
+
and path.suffix.lower() in self.icon_extensions
|
|
402
|
+
):
|
|
403
|
+
return True
|
|
404
|
+
else:
|
|
405
|
+
raise ValueError(
|
|
406
|
+
f"File must be an icon ({', '.join(self.icon_extensions)})"
|
|
407
|
+
)
|
|
408
|
+
return result
|
|
409
|
+
|
|
410
|
+
icon_path = inquirer.filepath( # pyright: ignore[reportPrivateImportUsage]
|
|
411
|
+
message="Select icon file:",
|
|
412
|
+
default=str(Path.cwd()),
|
|
413
|
+
validate=IconFileValidator(),
|
|
414
|
+
only_files=True,
|
|
415
|
+
only_directories=False,
|
|
416
|
+
transformer=lambda result: str(Path(result).resolve()),
|
|
417
|
+
filter=lambda result: str(Path(result).resolve()),
|
|
418
|
+
).execute()
|
|
419
|
+
|
|
420
|
+
return icon_path if icon_path else "auto"
|
|
421
|
+
else: # manual
|
|
422
|
+
icon_path = inquirer.text( # pyright: ignore[reportPrivateImportUsage]
|
|
423
|
+
message="Enter icon file path:",
|
|
424
|
+
validate=lambda result: Path(result).exists() if result else True,
|
|
425
|
+
).execute()
|
|
426
|
+
|
|
427
|
+
return icon_path if icon_path else "auto"
|
|
428
|
+
|
|
429
|
+
except Exception as e:
|
|
430
|
+
ezprinter.error(f"Error with icon selection: {e}")
|
|
431
|
+
ezprinter.info("Falling back to manual input...")
|
|
432
|
+
return ContextMenuWizard._select_icon_fallback()
|
|
433
|
+
|
|
434
|
+
@staticmethod
|
|
435
|
+
def _select_icon_fallback() -> str | None:
|
|
436
|
+
"""Fallback icon selection using custom menu."""
|
|
437
|
+
menu = InteractiveMenu(
|
|
438
|
+
title="Select Icon", instruction="Choose icon for the context menu entry"
|
|
439
|
+
)
|
|
440
|
+
|
|
441
|
+
items = [
|
|
442
|
+
{"label": "Auto-detect (recommended)", "value": "auto"},
|
|
443
|
+
{"label": "Use script's own icon", "value": "script"},
|
|
444
|
+
{"label": "Enter custom icon path", "value": "manual"},
|
|
445
|
+
{"label": "No icon", "value": "none"},
|
|
446
|
+
]
|
|
447
|
+
|
|
448
|
+
selected = menu.select_from_list(items, display_func=lambda item: item["label"])
|
|
449
|
+
if not selected:
|
|
450
|
+
return None
|
|
451
|
+
|
|
452
|
+
if selected["value"] == "auto":
|
|
453
|
+
return "auto"
|
|
454
|
+
elif selected["value"] == "script":
|
|
455
|
+
return "script"
|
|
456
|
+
elif selected["value"] == "manual":
|
|
457
|
+
ezprinter.info("Enter the path to your icon file (.ico, .exe, etc.):")
|
|
458
|
+
icon_path = input("> ").strip()
|
|
459
|
+
return icon_path if icon_path else "auto"
|
|
460
|
+
else:
|
|
461
|
+
return None
|
|
462
|
+
|
|
463
|
+
@staticmethod
|
|
464
|
+
def _select_context() -> ContextParameters:
|
|
465
|
+
"""Interactive context type selection."""
|
|
466
|
+
menu = InteractiveMenu(
|
|
467
|
+
title="Select Context Type",
|
|
468
|
+
instruction="Choose where this script should appear",
|
|
469
|
+
)
|
|
470
|
+
|
|
471
|
+
context_options = [
|
|
472
|
+
{"label": "Directory + Background (default)", "value": 0},
|
|
473
|
+
{"label": "Files only", "value": 1},
|
|
474
|
+
{"label": "Directories only", "value": 2},
|
|
475
|
+
{"label": "Background only", "value": 3},
|
|
476
|
+
{"label": "Root directories (drives)", "value": 4},
|
|
477
|
+
{"label": "Custom file types", "value": 5},
|
|
478
|
+
]
|
|
479
|
+
|
|
480
|
+
selected = menu.select_from_list(
|
|
481
|
+
context_options, display_func=lambda item: item["label"]
|
|
482
|
+
)
|
|
483
|
+
|
|
484
|
+
context_params = ContextParameters()
|
|
485
|
+
|
|
486
|
+
if not selected:
|
|
487
|
+
return context_params
|
|
488
|
+
|
|
489
|
+
choice = selected["value"]
|
|
490
|
+
|
|
491
|
+
if choice == 0: # Default
|
|
492
|
+
context_params.add_context_type(ContextType.DIRECTORY)
|
|
493
|
+
context_params.add_context_type(ContextType.BACKGROUND)
|
|
494
|
+
elif choice == 1: # Files
|
|
495
|
+
context_params.add_context_type(ContextType.FILE)
|
|
496
|
+
elif choice == 2: # Directories
|
|
497
|
+
context_params.add_context_type(ContextType.DIRECTORY)
|
|
498
|
+
elif choice == 3: # Background
|
|
499
|
+
context_params.add_context_type(ContextType.BACKGROUND)
|
|
500
|
+
elif choice == 4: # Root
|
|
501
|
+
context_params.add_context_type(ContextType.ROOT)
|
|
502
|
+
elif choice == 5: # Custom file types
|
|
503
|
+
context_params.add_context_type(ContextType.FILE)
|
|
504
|
+
ContextMenuWizard._select_file_types(context_params)
|
|
505
|
+
|
|
506
|
+
return context_params
|
|
507
|
+
|
|
508
|
+
@staticmethod
|
|
509
|
+
def _select_file_types(context_params: ContextParameters) -> None:
|
|
510
|
+
"""Interactive file type selection."""
|
|
511
|
+
menu = InteractiveMenu(
|
|
512
|
+
title="Select File Types", instruction="Choose which file types to support"
|
|
513
|
+
)
|
|
514
|
+
|
|
515
|
+
file_type_options = [
|
|
516
|
+
{"label": "Images (.jpg, .png, .gif, etc.)", "value": "image"},
|
|
517
|
+
{"label": "Text files (.txt, .md, .py, etc.)", "value": "text"},
|
|
518
|
+
{"label": "Archives (.zip, .rar, .7z, etc.)", "value": "archive"},
|
|
519
|
+
{"label": "Documents (.pdf, .doc, .xls, etc.)", "value": "document"},
|
|
520
|
+
{"label": "Media files (.mp3, .mp4, .avi, etc.)", "value": "media"},
|
|
521
|
+
{"label": "Code files (.py, .js, .java, etc.)", "value": "code"},
|
|
522
|
+
{"label": "Custom extensions", "value": "custom"},
|
|
523
|
+
]
|
|
524
|
+
|
|
525
|
+
selected = menu.select_from_list(
|
|
526
|
+
file_type_options, display_func=lambda item: item["label"]
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
if not selected:
|
|
530
|
+
return
|
|
531
|
+
|
|
532
|
+
choice = selected["value"]
|
|
533
|
+
|
|
534
|
+
if choice == "image":
|
|
535
|
+
context_params.add_file_type("image")
|
|
536
|
+
elif choice == "text":
|
|
537
|
+
context_params.add_file_type("text")
|
|
538
|
+
elif choice == "archive":
|
|
539
|
+
context_params.add_file_type("archive")
|
|
540
|
+
elif choice == "document":
|
|
541
|
+
context_params.add_file_type("document")
|
|
542
|
+
elif choice == "media":
|
|
543
|
+
context_params.add_file_type("media")
|
|
544
|
+
elif choice == "code":
|
|
545
|
+
context_params.add_file_type("code")
|
|
546
|
+
elif choice == "custom":
|
|
547
|
+
ezprinter.info("Enter custom extensions (e.g., .py .js .txt):")
|
|
548
|
+
extensions = input("> ").strip().split()
|
|
549
|
+
for ext in extensions:
|
|
550
|
+
context_params.add_file_type(ext)
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
# ///////////////////////////////////////////////////////////////
|
|
554
|
+
# PUBLIC API
|
|
555
|
+
# ///////////////////////////////////////////////////////////////
|
|
556
|
+
|
|
557
|
+
__all__ = ["ContextMenuWizard"]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# UI PROJECT - Project UI Components
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Project UI components package.
|
|
9
|
+
|
|
10
|
+
This package provides UI components for project creation and management,
|
|
11
|
+
following the established patterns in the WOMM codebase.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
# ///////////////////////////////////////////////////////////////
|
|
17
|
+
# IMPORTS
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# Local imports
|
|
20
|
+
from .create.create_completion_summaries import render_project_creation_result
|
|
21
|
+
from .project_wizard import ProjectWizard
|
|
22
|
+
from .setup.setup_completion_summaries import (
|
|
23
|
+
print_project_setup_result,
|
|
24
|
+
print_setup_completion_summary,
|
|
25
|
+
)
|
|
26
|
+
from .templates.template_store_display import (
|
|
27
|
+
render_template_list,
|
|
28
|
+
render_template_result,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
# ///////////////////////////////////////////////////////////////
|
|
32
|
+
# PUBLIC API
|
|
33
|
+
# ///////////////////////////////////////////////////////////////
|
|
34
|
+
|
|
35
|
+
__all__ = [
|
|
36
|
+
"ProjectWizard",
|
|
37
|
+
"print_project_setup_result",
|
|
38
|
+
"print_setup_completion_summary",
|
|
39
|
+
"render_project_creation_result",
|
|
40
|
+
"render_template_list",
|
|
41
|
+
"render_template_result",
|
|
42
|
+
]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# COMPLETION SUMMARIES - Project Creation Completion Summaries
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Completion summaries for new project creation.
|
|
9
|
+
|
|
10
|
+
This module renders the outcome of ``ProjectCreateInterface.create_project``
|
|
11
|
+
for the CLI, following the established rendering pattern used by ``path``,
|
|
12
|
+
``context``, ``deps`` and ``doctor``.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
# ///////////////////////////////////////////////////////////////
|
|
18
|
+
# IMPORTS
|
|
19
|
+
# ///////////////////////////////////////////////////////////////
|
|
20
|
+
# Local imports
|
|
21
|
+
from ....shared.results import ProjectCreationResult
|
|
22
|
+
from ...common.logging import ezprinter
|
|
23
|
+
|
|
24
|
+
# ///////////////////////////////////////////////////////////////
|
|
25
|
+
# FUNCTIONS
|
|
26
|
+
# ///////////////////////////////////////////////////////////////
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def render_project_creation_result(
|
|
30
|
+
result: ProjectCreationResult, *, verbose: bool = False
|
|
31
|
+
) -> None:
|
|
32
|
+
"""Render the outcome of a template-driven project creation.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
result: Outcome returned by ``ProjectCreateInterface.create_project``.
|
|
36
|
+
verbose: Whether to also print the project template identifier.
|
|
37
|
+
"""
|
|
38
|
+
if not result.success:
|
|
39
|
+
ezprinter.error(result.error or "Project creation failed")
|
|
40
|
+
return
|
|
41
|
+
|
|
42
|
+
ezprinter.success(result.message or "Project created successfully")
|
|
43
|
+
if result.project_path is not None:
|
|
44
|
+
ezprinter.info(f"Project path: {result.project_path}")
|
|
45
|
+
if verbose and result.project_type:
|
|
46
|
+
ezprinter.info(f"Template: {result.project_type}")
|
|
47
|
+
for warning in result.warnings or []:
|
|
48
|
+
ezprinter.warning(warning)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# ///////////////////////////////////////////////////////////////
|
|
52
|
+
# PUBLIC API
|
|
53
|
+
# ///////////////////////////////////////////////////////////////
|
|
54
|
+
|
|
55
|
+
__all__ = ["render_project_creation_result"]
|