medicafe 0.251027.2__tar.gz → 0.251029.0__tar.gz
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.
Potentially problematic release.
This version of medicafe might be problematic. Click here for more details.
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/MediBot.bat +12 -2
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/__init__.py +1 -1
- medicafe-0.251029.0/MediBot/config_editor.bat +90 -0
- medicafe-0.251029.0/MediBot/config_editor.py +430 -0
- medicafe-0.251029.0/MediBot/config_editor_helpers.py +310 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediCafe/__init__.py +1 -1
- medicafe-0.251029.0/MediCafe/error_reporter.py +603 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_Gmail.py +65 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/__init__.py +1 -1
- {medicafe-0.251027.2/medicafe.egg-info → medicafe-0.251029.0}/PKG-INFO +1 -1
- {medicafe-0.251027.2 → medicafe-0.251029.0/medicafe.egg-info}/PKG-INFO +1 -1
- {medicafe-0.251027.2 → medicafe-0.251029.0}/medicafe.egg-info/SOURCES.txt +3 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/setup.py +1 -1
- medicafe-0.251027.2/MediCafe/error_reporter.py +0 -452
- {medicafe-0.251027.2 → medicafe-0.251029.0}/LICENSE +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MANIFEST.in +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/MediBot.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/MediBot_Charges.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/MediBot_Crosswalk_Library.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/MediBot_Crosswalk_Utils.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/MediBot_Notepad_Utils.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/MediBot_Post.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/MediBot_Preprocessor.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/MediBot_Preprocessor_lib.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/MediBot_UI.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/MediBot_dataformat_library.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/MediBot_debug.bat +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/MediBot_docx_decoder.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/MediBot_smart_import.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/clear_cache.bat +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/crash_diagnostic.bat +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/f_drive_diagnostic.bat +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/full_debug_suite.bat +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/get_medicafe_version.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/process_csvs.bat +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/update_json.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediBot/update_medicafe.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediCafe/MediLink_ConfigLoader.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediCafe/__main__.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediCafe/api_core.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediCafe/api_factory.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediCafe/api_utils.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediCafe/core_utils.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediCafe/deductible_utils.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediCafe/graphql_utils.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediCafe/logging_config.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediCafe/logging_demo.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediCafe/migration_helpers.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediCafe/smart_import.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediCafe/submission_index.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/InsuranceTypeService.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_837p_cob_library.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_837p_encoder.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_837p_encoder_library.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_837p_utilities.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_API_Generator.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_Azure.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_Charges.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_ClaimStatus.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_DataMgmt.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_Decoder.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_Deductible.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_Deductible_Validator.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_Display_Utils.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_Down.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_Mailer.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_Parser.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_PatientProcessor.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_Scan.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_Scheduler.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_UI.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_Up.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_insurance_utils.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_main.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/MediLink_smart_import.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/Soumit_api.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/gmail_http_utils.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/gmail_oauth_utils.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/openssl.cnf +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/test.py +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/MediLink/webapp.html +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/README.md +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/medicafe.egg-info/dependency_links.txt +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/medicafe.egg-info/entry_points.txt +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/medicafe.egg-info/not-zip-safe +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/medicafe.egg-info/requires.txt +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/medicafe.egg-info/top_level.txt +0 -0
- {medicafe-0.251027.2 → medicafe-0.251029.0}/setup.cfg +0 -0
|
@@ -732,7 +732,8 @@ echo 4. Toggle Performance Logging ^(session^)
|
|
|
732
732
|
echo 5. Send TEST error report (email)
|
|
733
733
|
echo 6. Forced MediCafe version rollback
|
|
734
734
|
echo 7. Process CSV Files
|
|
735
|
-
echo 8.
|
|
735
|
+
echo 8. Edit Config File (JSON Editor)
|
|
736
|
+
echo 9. Back to Main Menu
|
|
736
737
|
echo.
|
|
737
738
|
set /p tchoice=Enter your choice:
|
|
738
739
|
if "%tchoice%"=="1" goto open_latest_log
|
|
@@ -742,7 +743,8 @@ if "%tchoice%"=="4" goto toggle_perf_logging
|
|
|
742
743
|
if "%tchoice%"=="5" goto send_test_error_report
|
|
743
744
|
if "%tchoice%"=="6" goto forced_version_rollback
|
|
744
745
|
if "%tchoice%"=="7" goto process_csvs
|
|
745
|
-
if "%tchoice%"=="8" goto
|
|
746
|
+
if "%tchoice%"=="8" goto config_editor
|
|
747
|
+
if "%tchoice%"=="9" goto main_menu
|
|
746
748
|
echo Invalid choice. Please try again.
|
|
747
749
|
pause
|
|
748
750
|
goto troubleshooting_menu
|
|
@@ -876,6 +878,14 @@ echo Rollback complete. Current MediCafe version: %medicafe_version%
|
|
|
876
878
|
pause >nul
|
|
877
879
|
goto troubleshooting_menu
|
|
878
880
|
|
|
881
|
+
::: Config Editor
|
|
882
|
+
:config_editor
|
|
883
|
+
cls
|
|
884
|
+
echo Starting Config Editor...
|
|
885
|
+
call "%~dp0config_editor.bat"
|
|
886
|
+
pause
|
|
887
|
+
goto troubleshooting_menu
|
|
888
|
+
|
|
879
889
|
::: Subroutine to display the last N lines of a file
|
|
880
890
|
:tail
|
|
881
891
|
::: Usage: call :tail filename number_of_lines
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal enabledelayedexpansion
|
|
3
|
+
|
|
4
|
+
:: Config Editor Launcher
|
|
5
|
+
:: Called from MediBot.bat Troubleshooting menu
|
|
6
|
+
|
|
7
|
+
:: Get script directory and set paths
|
|
8
|
+
set "script_dir=%~dp0"
|
|
9
|
+
set "workspace_root=%script_dir%.."
|
|
10
|
+
set "python_script=%script_dir%config_editor.py"
|
|
11
|
+
|
|
12
|
+
:: Use the same path resolution logic as MediLink_ConfigLoader
|
|
13
|
+
:: Try default path first (relative to MediCafe module)
|
|
14
|
+
set "config_path=%workspace_root%\json\config.json"
|
|
15
|
+
|
|
16
|
+
:: If default path doesn't exist, try platform-specific fallbacks
|
|
17
|
+
if not exist "%config_path%" (
|
|
18
|
+
:: Check for Windows XP (F: drive)
|
|
19
|
+
if exist "F:\" (
|
|
20
|
+
set "config_path=F:\Medibot\json\config.json"
|
|
21
|
+
) else (
|
|
22
|
+
:: Use current working directory for other Windows versions
|
|
23
|
+
set "config_path=%CD%\json\config.json"
|
|
24
|
+
)
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
:: Display header
|
|
28
|
+
cls
|
|
29
|
+
echo ========================================
|
|
30
|
+
echo MediCafe Config Editor
|
|
31
|
+
echo ========================================
|
|
32
|
+
echo.
|
|
33
|
+
|
|
34
|
+
:: Check if Python is available
|
|
35
|
+
python --version >nul 2>&1
|
|
36
|
+
if errorlevel 1 (
|
|
37
|
+
echo ERROR: Python is not available or not in PATH
|
|
38
|
+
echo.
|
|
39
|
+
echo Please ensure Python 3.4.4 or later is installed and accessible.
|
|
40
|
+
echo.
|
|
41
|
+
pause
|
|
42
|
+
exit /b 1
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
:: Check if config file exists
|
|
46
|
+
if not exist "%config_path%" (
|
|
47
|
+
echo WARNING: Config file not found at:
|
|
48
|
+
echo %config_path%
|
|
49
|
+
echo.
|
|
50
|
+
echo The editor will start with an empty configuration.
|
|
51
|
+
echo You can create a new config file or navigate to the correct location.
|
|
52
|
+
echo.
|
|
53
|
+
set /p continue_choice="Continue anyway? (Y/N): "
|
|
54
|
+
if /i not "!continue_choice!"=="Y" (
|
|
55
|
+
echo Operation cancelled.
|
|
56
|
+
pause
|
|
57
|
+
exit /b 0
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
:: Check if editor script exists
|
|
62
|
+
if not exist "%python_script%" (
|
|
63
|
+
echo ERROR: Config editor script not found at:
|
|
64
|
+
echo %python_script%
|
|
65
|
+
echo.
|
|
66
|
+
echo Please ensure config_editor.py is in the MediBot directory.
|
|
67
|
+
echo.
|
|
68
|
+
pause
|
|
69
|
+
exit /b 1
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
:: Run the config editor
|
|
73
|
+
echo Starting config editor...
|
|
74
|
+
echo.
|
|
75
|
+
python "%python_script%" "%config_path%"
|
|
76
|
+
|
|
77
|
+
:: Check exit code
|
|
78
|
+
if errorlevel 1 (
|
|
79
|
+
echo.
|
|
80
|
+
echo ERROR: Config editor encountered an error.
|
|
81
|
+
echo.
|
|
82
|
+
) else (
|
|
83
|
+
echo.
|
|
84
|
+
echo Config editor completed successfully.
|
|
85
|
+
echo.
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
:: Return to caller
|
|
89
|
+
pause
|
|
90
|
+
exit /b %errorlevel%
|
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
DOS-Style Config.json Editor
|
|
5
|
+
Interactive JSON configuration editor with DOS-like interface.
|
|
6
|
+
Compatible with Python 3.4.4 and Windows XP.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
import sys
|
|
11
|
+
import json
|
|
12
|
+
from collections import OrderedDict
|
|
13
|
+
|
|
14
|
+
# Import our helper functions
|
|
15
|
+
from config_editor_helpers import (
|
|
16
|
+
load_config_safe, create_backup, save_config_atomic, validate_json_structure,
|
|
17
|
+
is_sensitive_key, get_value_type, format_value_for_display, clear_config_cache,
|
|
18
|
+
get_nested_value, set_nested_value, get_path_string, validate_key_name, parse_value_input,
|
|
19
|
+
resolve_config_path
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
class ConfigEditor:
|
|
23
|
+
def __init__(self, config_path):
|
|
24
|
+
self.config_path = config_path
|
|
25
|
+
self.config = OrderedDict()
|
|
26
|
+
self.original_config = OrderedDict()
|
|
27
|
+
self.current_path = [] # List of keys representing current location
|
|
28
|
+
self.staged_changes = [] # List of (path, old_value, new_value) tuples
|
|
29
|
+
self.running = True
|
|
30
|
+
|
|
31
|
+
# Load initial config
|
|
32
|
+
self.config, error = load_config_safe(config_path)
|
|
33
|
+
if error:
|
|
34
|
+
print("WARNING: {}".format(error))
|
|
35
|
+
print("Starting with empty configuration.")
|
|
36
|
+
self.config = OrderedDict()
|
|
37
|
+
|
|
38
|
+
# Keep a copy of original for comparison
|
|
39
|
+
self.original_config = json.loads(json.dumps(self.config, ensure_ascii=False), object_pairs_hook=OrderedDict)
|
|
40
|
+
|
|
41
|
+
def clear_screen(self):
|
|
42
|
+
"""Clear the console screen (XP compatible)."""
|
|
43
|
+
os.system('cls' if os.name == 'nt' else 'clear')
|
|
44
|
+
|
|
45
|
+
def print_header(self):
|
|
46
|
+
"""Print the editor header."""
|
|
47
|
+
print("=" * 60)
|
|
48
|
+
print(" MediCafe Config Editor")
|
|
49
|
+
print("=" * 60)
|
|
50
|
+
print("")
|
|
51
|
+
|
|
52
|
+
def print_breadcrumb(self):
|
|
53
|
+
"""Print current navigation path."""
|
|
54
|
+
path_str = get_path_string(self.current_path)
|
|
55
|
+
print("Current Path: {}".format(path_str))
|
|
56
|
+
print("-" * 60)
|
|
57
|
+
|
|
58
|
+
def print_current_level(self):
|
|
59
|
+
"""Print the current level of the config tree."""
|
|
60
|
+
current_data, found = get_nested_value(self.config, self.current_path)
|
|
61
|
+
|
|
62
|
+
if not found:
|
|
63
|
+
print("ERROR: Invalid path")
|
|
64
|
+
return
|
|
65
|
+
|
|
66
|
+
if not isinstance(current_data, dict):
|
|
67
|
+
print("ERROR: Cannot navigate into non-object value")
|
|
68
|
+
return
|
|
69
|
+
|
|
70
|
+
if not current_data:
|
|
71
|
+
print("(Empty object)")
|
|
72
|
+
return
|
|
73
|
+
|
|
74
|
+
# Print numbered items
|
|
75
|
+
items = list(current_data.items())
|
|
76
|
+
for i, (key, value) in enumerate(items, 1):
|
|
77
|
+
value_display = format_value_for_display(value)
|
|
78
|
+
value_type = get_value_type(value)
|
|
79
|
+
|
|
80
|
+
# Mark sensitive keys
|
|
81
|
+
sensitive_mark = " [SENSITIVE]" if is_sensitive_key(key) else ""
|
|
82
|
+
|
|
83
|
+
print("[{}] {}: {} ({}){}".format(i, key, value_display, value_type, sensitive_mark))
|
|
84
|
+
|
|
85
|
+
def print_commands(self):
|
|
86
|
+
"""Print available commands."""
|
|
87
|
+
print("")
|
|
88
|
+
print("Commands:")
|
|
89
|
+
print(" [1-N] Navigate/Edit [0] Back [EDIT #] Edit [ADD] Add Key")
|
|
90
|
+
print(" [DIR] Refresh [HELP] Help [EXIT] Save & Exit")
|
|
91
|
+
print("-" * 60)
|
|
92
|
+
|
|
93
|
+
def print_help(self):
|
|
94
|
+
"""Print detailed help information."""
|
|
95
|
+
self.clear_screen()
|
|
96
|
+
self.print_header()
|
|
97
|
+
print("HELP - Config Editor Commands")
|
|
98
|
+
print("=" * 60)
|
|
99
|
+
print("")
|
|
100
|
+
print("Navigation:")
|
|
101
|
+
print(" [1-N] - Navigate into nested objects or edit simple values")
|
|
102
|
+
print(" [0] - Go back to parent level")
|
|
103
|
+
print(" [..] - Same as [0]")
|
|
104
|
+
print("")
|
|
105
|
+
print("Editing:")
|
|
106
|
+
print(" [EDIT #] - Edit the numbered item")
|
|
107
|
+
print(" [ADD] - Add a new key at current level")
|
|
108
|
+
print("")
|
|
109
|
+
print("Utilities:")
|
|
110
|
+
print(" [DIR] - Refresh current level display")
|
|
111
|
+
print(" [HELP] - Show this help screen")
|
|
112
|
+
print(" [EXIT] - Save changes and exit")
|
|
113
|
+
print(" [Q] - Same as [EXIT]")
|
|
114
|
+
print("")
|
|
115
|
+
print("Safety Features:")
|
|
116
|
+
print(" - All changes are staged until you save")
|
|
117
|
+
print(" - Automatic backup created before saving")
|
|
118
|
+
print(" - Sensitive keys marked with [SENSITIVE]")
|
|
119
|
+
print(" - Preview all changes before committing")
|
|
120
|
+
print("")
|
|
121
|
+
print("Press Enter to continue...")
|
|
122
|
+
input()
|
|
123
|
+
|
|
124
|
+
def navigate_to_item(self, item_number):
|
|
125
|
+
"""Navigate to a numbered item."""
|
|
126
|
+
current_data, found = get_nested_value(self.config, self.current_path)
|
|
127
|
+
|
|
128
|
+
if not found or not isinstance(current_data, dict):
|
|
129
|
+
print("ERROR: Cannot navigate from current location")
|
|
130
|
+
return
|
|
131
|
+
|
|
132
|
+
items = list(current_data.items())
|
|
133
|
+
if item_number < 1 or item_number > len(items):
|
|
134
|
+
print("ERROR: Invalid item number")
|
|
135
|
+
return
|
|
136
|
+
|
|
137
|
+
key, value = items[item_number - 1]
|
|
138
|
+
|
|
139
|
+
# If it's a simple value, offer to edit it
|
|
140
|
+
if not isinstance(value, dict):
|
|
141
|
+
self.edit_simple_value(key, value)
|
|
142
|
+
else:
|
|
143
|
+
# Navigate into the object
|
|
144
|
+
self.current_path.append(key)
|
|
145
|
+
|
|
146
|
+
def edit_simple_value(self, key, current_value):
|
|
147
|
+
"""Edit a simple (non-object) value."""
|
|
148
|
+
current_type = get_value_type(current_value)
|
|
149
|
+
current_display = format_value_for_display(current_value)
|
|
150
|
+
|
|
151
|
+
print("")
|
|
152
|
+
print("Editing: {}".format(key))
|
|
153
|
+
print("Current value: {} ({})".format(current_display, current_type))
|
|
154
|
+
print("")
|
|
155
|
+
|
|
156
|
+
# Get new value
|
|
157
|
+
new_value_str = input("Enter new value: ").strip()
|
|
158
|
+
|
|
159
|
+
if not new_value_str:
|
|
160
|
+
print("No changes made.")
|
|
161
|
+
return
|
|
162
|
+
|
|
163
|
+
# Parse the new value
|
|
164
|
+
new_value, error = parse_value_input(new_value_str, current_type)
|
|
165
|
+
if error:
|
|
166
|
+
print("ERROR: {}".format(error))
|
|
167
|
+
return
|
|
168
|
+
|
|
169
|
+
# Show preview
|
|
170
|
+
new_display = format_value_for_display(new_value)
|
|
171
|
+
print("")
|
|
172
|
+
print("Preview: {} -> {}".format(current_display, new_display))
|
|
173
|
+
|
|
174
|
+
# Confirm change
|
|
175
|
+
if is_sensitive_key(key):
|
|
176
|
+
print("WARNING: This appears to be a sensitive key!")
|
|
177
|
+
|
|
178
|
+
confirm = input("Apply this change? (Y/N): ").strip().upper()
|
|
179
|
+
if confirm in ['Y', 'YES']:
|
|
180
|
+
# Stage the change
|
|
181
|
+
full_path = self.current_path + [key]
|
|
182
|
+
self.staged_changes.append((full_path, current_value, new_value))
|
|
183
|
+
set_nested_value(self.config, full_path, new_value)
|
|
184
|
+
print("Change staged.")
|
|
185
|
+
else:
|
|
186
|
+
print("Change cancelled.")
|
|
187
|
+
|
|
188
|
+
def add_new_key(self):
|
|
189
|
+
"""Add a new key at the current level."""
|
|
190
|
+
current_data, found = get_nested_value(self.config, self.current_path)
|
|
191
|
+
|
|
192
|
+
if not found or not isinstance(current_data, dict):
|
|
193
|
+
print("ERROR: Cannot add key at current location")
|
|
194
|
+
return
|
|
195
|
+
|
|
196
|
+
print("")
|
|
197
|
+
print("Add New Key")
|
|
198
|
+
print("-" * 30)
|
|
199
|
+
|
|
200
|
+
# Get key name
|
|
201
|
+
while True:
|
|
202
|
+
key_name = input("Enter key name: ").strip()
|
|
203
|
+
is_valid, error = validate_key_name(key_name, current_data.keys())
|
|
204
|
+
if is_valid:
|
|
205
|
+
break
|
|
206
|
+
print("ERROR: {}".format(error))
|
|
207
|
+
|
|
208
|
+
# Get value type
|
|
209
|
+
print("")
|
|
210
|
+
print("Value types:")
|
|
211
|
+
print(" 1. string - Text value")
|
|
212
|
+
print(" 2. number - Numeric value")
|
|
213
|
+
print(" 3. boolean - true/false")
|
|
214
|
+
print(" 4. array - List of values")
|
|
215
|
+
print(" 5. object - Nested structure")
|
|
216
|
+
print("")
|
|
217
|
+
|
|
218
|
+
while True:
|
|
219
|
+
type_choice = input("Select value type (1-5): ").strip()
|
|
220
|
+
type_map = {'1': 'string', '2': 'number', '3': 'boolean', '4': 'array', '5': 'object'}
|
|
221
|
+
if type_choice in type_map:
|
|
222
|
+
value_type = type_map[type_choice]
|
|
223
|
+
break
|
|
224
|
+
print("ERROR: Invalid choice. Enter 1-5.")
|
|
225
|
+
|
|
226
|
+
# Get value based on type
|
|
227
|
+
if value_type == 'string':
|
|
228
|
+
value_input = input("Enter string value: ").strip()
|
|
229
|
+
elif value_type == 'number':
|
|
230
|
+
value_input = input("Enter number value: ").strip()
|
|
231
|
+
elif value_type == 'boolean':
|
|
232
|
+
value_input = input("Enter boolean value (true/false): ").strip()
|
|
233
|
+
elif value_type == 'array':
|
|
234
|
+
value_input = input("Enter array values (comma-separated): ").strip()
|
|
235
|
+
elif value_type == 'object':
|
|
236
|
+
value_input = "" # Empty object
|
|
237
|
+
print("Creating empty object. You can add keys to it later.")
|
|
238
|
+
|
|
239
|
+
# Parse the value
|
|
240
|
+
new_value, error = parse_value_input(value_input, value_type)
|
|
241
|
+
if error:
|
|
242
|
+
print("ERROR: {}".format(error))
|
|
243
|
+
return
|
|
244
|
+
|
|
245
|
+
# Show preview
|
|
246
|
+
new_display = format_value_for_display(new_value)
|
|
247
|
+
print("")
|
|
248
|
+
print("Preview: {}: {} ({})".format(key_name, new_display, value_type))
|
|
249
|
+
|
|
250
|
+
# Confirm addition
|
|
251
|
+
if is_sensitive_key(key_name):
|
|
252
|
+
print("WARNING: This appears to be a sensitive key!")
|
|
253
|
+
|
|
254
|
+
confirm = input("Add this key? (Y/N): ").strip().upper()
|
|
255
|
+
if confirm in ['Y', 'YES']:
|
|
256
|
+
# Stage the change
|
|
257
|
+
full_path = self.current_path + [key_name]
|
|
258
|
+
self.staged_changes.append((full_path, None, new_value))
|
|
259
|
+
set_nested_value(self.config, full_path, new_value)
|
|
260
|
+
print("Key added and staged.")
|
|
261
|
+
else:
|
|
262
|
+
print("Addition cancelled.")
|
|
263
|
+
|
|
264
|
+
def show_staged_changes(self):
|
|
265
|
+
"""Show all staged changes."""
|
|
266
|
+
if not self.staged_changes:
|
|
267
|
+
print("No staged changes.")
|
|
268
|
+
return
|
|
269
|
+
|
|
270
|
+
print("")
|
|
271
|
+
print("Staged Changes:")
|
|
272
|
+
print("-" * 30)
|
|
273
|
+
|
|
274
|
+
for i, (path, old_value, new_value) in enumerate(self.staged_changes, 1):
|
|
275
|
+
path_str = " > ".join(path)
|
|
276
|
+
if old_value is None:
|
|
277
|
+
print("{}. ADD: {} = {}".format(i, path_str, format_value_for_display(new_value)))
|
|
278
|
+
else:
|
|
279
|
+
print("{}. EDIT: {} = {} -> {}".format(
|
|
280
|
+
i, path_str,
|
|
281
|
+
format_value_for_display(old_value),
|
|
282
|
+
format_value_for_display(new_value)
|
|
283
|
+
))
|
|
284
|
+
|
|
285
|
+
def save_changes(self):
|
|
286
|
+
"""Save all staged changes to file."""
|
|
287
|
+
if not self.staged_changes:
|
|
288
|
+
print("No changes to save.")
|
|
289
|
+
return True
|
|
290
|
+
|
|
291
|
+
print("")
|
|
292
|
+
print("Saving Changes...")
|
|
293
|
+
print("-" * 30)
|
|
294
|
+
|
|
295
|
+
# Show summary
|
|
296
|
+
self.show_staged_changes()
|
|
297
|
+
print("")
|
|
298
|
+
|
|
299
|
+
# Validate JSON structure
|
|
300
|
+
is_valid, error = validate_json_structure(self.config)
|
|
301
|
+
if not is_valid:
|
|
302
|
+
print("ERROR: {}".format(error))
|
|
303
|
+
return False
|
|
304
|
+
|
|
305
|
+
# Create backup
|
|
306
|
+
backup_path = create_backup(self.config_path)
|
|
307
|
+
if backup_path:
|
|
308
|
+
print("Backup created: {}".format(os.path.basename(backup_path)))
|
|
309
|
+
else:
|
|
310
|
+
print("WARNING: Could not create backup")
|
|
311
|
+
|
|
312
|
+
# Save to file
|
|
313
|
+
success, error = save_config_atomic(self.config_path, self.config)
|
|
314
|
+
if not success:
|
|
315
|
+
print("ERROR: {}".format(error))
|
|
316
|
+
return False
|
|
317
|
+
|
|
318
|
+
# Clear cache
|
|
319
|
+
cache_success, cache_error = clear_config_cache()
|
|
320
|
+
if not cache_success:
|
|
321
|
+
print("WARNING: {}".format(cache_error))
|
|
322
|
+
|
|
323
|
+
print("Configuration saved successfully!")
|
|
324
|
+
return True
|
|
325
|
+
|
|
326
|
+
def process_command(self, command):
|
|
327
|
+
"""Process a user command."""
|
|
328
|
+
command = command.strip().upper()
|
|
329
|
+
|
|
330
|
+
if command == 'EXIT' or command == 'Q':
|
|
331
|
+
if self.staged_changes:
|
|
332
|
+
print("")
|
|
333
|
+
print("You have unsaved changes.")
|
|
334
|
+
self.show_staged_changes()
|
|
335
|
+
print("")
|
|
336
|
+
save_choice = input("Save changes before exiting? (Y/N): ").strip().upper()
|
|
337
|
+
if save_choice in ['Y', 'YES']:
|
|
338
|
+
if self.save_changes():
|
|
339
|
+
self.running = False
|
|
340
|
+
else:
|
|
341
|
+
print("Changes discarded.")
|
|
342
|
+
self.running = False
|
|
343
|
+
else:
|
|
344
|
+
self.running = False
|
|
345
|
+
|
|
346
|
+
elif command == 'HELP':
|
|
347
|
+
self.print_help()
|
|
348
|
+
|
|
349
|
+
elif command == 'DIR':
|
|
350
|
+
pass # Will refresh display
|
|
351
|
+
|
|
352
|
+
elif command == 'ADD':
|
|
353
|
+
self.add_new_key()
|
|
354
|
+
|
|
355
|
+
elif command.startswith('EDIT '):
|
|
356
|
+
try:
|
|
357
|
+
item_num = int(command[5:].strip())
|
|
358
|
+
self.navigate_to_item(item_num)
|
|
359
|
+
except ValueError:
|
|
360
|
+
print("ERROR: Invalid EDIT command. Use EDIT followed by a number.")
|
|
361
|
+
|
|
362
|
+
elif command == '0' or command == '..':
|
|
363
|
+
if self.current_path:
|
|
364
|
+
self.current_path.pop()
|
|
365
|
+
else:
|
|
366
|
+
print("Already at root level.")
|
|
367
|
+
|
|
368
|
+
elif command.isdigit():
|
|
369
|
+
item_num = int(command)
|
|
370
|
+
self.navigate_to_item(item_num)
|
|
371
|
+
|
|
372
|
+
else:
|
|
373
|
+
print("ERROR: Unknown command '{}'. Type HELP for available commands.".format(command))
|
|
374
|
+
|
|
375
|
+
def run(self):
|
|
376
|
+
"""Main editor loop."""
|
|
377
|
+
while self.running:
|
|
378
|
+
self.clear_screen()
|
|
379
|
+
self.print_header()
|
|
380
|
+
self.print_breadcrumb()
|
|
381
|
+
self.print_current_level()
|
|
382
|
+
self.print_commands()
|
|
383
|
+
|
|
384
|
+
if self.staged_changes:
|
|
385
|
+
print("")
|
|
386
|
+
print("You have {} unsaved changes.".format(len(self.staged_changes)))
|
|
387
|
+
|
|
388
|
+
try:
|
|
389
|
+
command = input("Config> ").strip()
|
|
390
|
+
if command:
|
|
391
|
+
self.process_command(command)
|
|
392
|
+
except KeyboardInterrupt:
|
|
393
|
+
print("\n")
|
|
394
|
+
print("Interrupted by user.")
|
|
395
|
+
if self.staged_changes:
|
|
396
|
+
save_choice = input("Save changes before exiting? (Y/N): ").strip().upper()
|
|
397
|
+
if save_choice in ['Y', 'YES']:
|
|
398
|
+
self.save_changes()
|
|
399
|
+
break
|
|
400
|
+
except EOFError:
|
|
401
|
+
break
|
|
402
|
+
|
|
403
|
+
print("Config editor closed.")
|
|
404
|
+
|
|
405
|
+
def main():
|
|
406
|
+
"""Main entry point."""
|
|
407
|
+
if len(sys.argv) != 2:
|
|
408
|
+
print("Usage: python config_editor.py <config_path>")
|
|
409
|
+
sys.exit(1)
|
|
410
|
+
|
|
411
|
+
# Resolve the config path using the same logic as MediLink_ConfigLoader
|
|
412
|
+
default_path = sys.argv[1]
|
|
413
|
+
config_path = resolve_config_path(default_path)
|
|
414
|
+
|
|
415
|
+
# Ensure the directory exists (create it if needed)
|
|
416
|
+
config_dir = os.path.dirname(config_path)
|
|
417
|
+
if not os.path.exists(config_dir):
|
|
418
|
+
try:
|
|
419
|
+
os.makedirs(config_dir)
|
|
420
|
+
except OSError as e:
|
|
421
|
+
# Ignore error if directory already exists (race condition)
|
|
422
|
+
if e.errno != 17: # EEXIST
|
|
423
|
+
print("ERROR: Could not create config directory '{}': {}".format(config_dir, str(e)))
|
|
424
|
+
sys.exit(1)
|
|
425
|
+
|
|
426
|
+
editor = ConfigEditor(config_path)
|
|
427
|
+
editor.run()
|
|
428
|
+
|
|
429
|
+
if __name__ == "__main__":
|
|
430
|
+
main()
|