File size: 6,156 Bytes
ec038f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env python3
"""

Debug Mode Enabler for Glossarion

This script enables debug buttons and features for developers/troubleshooting.

"""

import json
import os
import sys

CONFIG_FILE = 'config.json'

def enable_debug_mode():
    """Enable debug mode by adding show_debug_buttons to config"""
    
    if not os.path.exists(CONFIG_FILE):
        print("❌ config.json not found. Please run Glossarion at least once to create the config file.")
        return False
    
    try:
        # Load existing config
        with open(CONFIG_FILE, 'r', encoding='utf-8') as f:
            config = json.load(f)
        
        print(f"πŸ“– Loaded config file: {CONFIG_FILE}")
        
        # Check if already enabled
        if config.get('show_debug_buttons', False):
            print("βœ… Debug mode is already enabled!")
            return True
        
        # Enable debug mode
        config['show_debug_buttons'] = True
        
        # Create backup
        backup_file = f"{CONFIG_FILE}.backup"
        with open(backup_file, 'w', encoding='utf-8') as f:
            json.dump(config, f, ensure_ascii=False, indent=2)
        print(f"πŸ’Ύ Created backup: {backup_file}")
        
        # Save updated config
        with open(CONFIG_FILE, 'w', encoding='utf-8') as f:
            json.dump(config, f, ensure_ascii=False, indent=2)
        
        print("βœ… Debug mode enabled successfully!")
        print("πŸ”§ Debug features now available:")
        print("   β€’ Debug Mode toggle button in Other Settings (GUI)")
        print("   β€’ Enhanced debugging in all save functions")
        print("   β€’ Comprehensive environment variable checking")
        print("πŸ’‘ You can also toggle debug mode directly in the GUI: Other Settings β†’ Debug Mode toggle")
        
        return True
        
    except Exception as e:
        print(f"❌ Error enabling debug mode: {e}")
        return False

def disable_debug_mode():
    """Disable debug mode by removing show_debug_buttons from config"""
    
    if not os.path.exists(CONFIG_FILE):
        print("❌ config.json not found.")
        return False
    
    try:
        # Load existing config
        with open(CONFIG_FILE, 'r', encoding='utf-8') as f:
            config = json.load(f)
        
        print(f"πŸ“– Loaded config file: {CONFIG_FILE}")
        
        # Check if already disabled
        if not config.get('show_debug_buttons', False):
            print("βœ… Debug mode is already disabled!")
            return True
        
        # Disable debug mode
        config['show_debug_buttons'] = False
        
        # Save updated config
        with open(CONFIG_FILE, 'w', encoding='utf-8') as f:
            json.dump(config, f, ensure_ascii=False, indent=2)
        
        print("βœ… Debug mode disabled successfully!")
        print("πŸ”’ Debug buttons will be hidden from users")
        
        return True
        
    except Exception as e:
        print(f"❌ Error disabling debug mode: {e}")
        return False

def check_debug_status():
    """Check current debug mode status"""
    
    if not os.path.exists(CONFIG_FILE):
        print("❌ config.json not found.")
        return
    
    try:
        with open(CONFIG_FILE, 'r', encoding='utf-8') as f:
            config = json.load(f)
        
        debug_enabled = config.get('show_debug_buttons', False)
        
        print("πŸ” Current Debug Mode Status:")
        print(f"   show_debug_buttons: {debug_enabled}")
        
        if debug_enabled:
            print("βœ… Debug mode is ENABLED")
            print("   β€’ Debug buttons will appear in Other Settings")
            print("   β€’ Enhanced debugging is active in save functions")
        else:
            print("πŸ”’ Debug mode is DISABLED")
            print("   β€’ Debug buttons are hidden from users")
            print("   β€’ Standard logging only")
            
    except Exception as e:
        print(f"❌ Error checking debug status: {e}")

if __name__ == "__main__":
    from shutdown_utils import run_cli_main
    def _main():
        print("πŸš€ Glossarion Debug Mode Manager")
        print("=" * 40)
        
        if len(sys.argv) > 1:
            action = sys.argv[1].lower()
            
            if action in ['enable', 'on', 'true']:
                enable_debug_mode()
            elif action in ['disable', 'off', 'false']:
                disable_debug_mode()
            elif action in ['status', 'check']:
                check_debug_status()
            else:
                print(f"❌ Unknown action: {action}")
                print("Valid actions: enable, disable, status")
        else:
            # Interactive mode
            print("Choose an action:")
            print("1. Enable debug mode")
            print("2. Disable debug mode") 
            print("3. Check current status")
            print("4. Exit")
            
            try:
                choice = input("\nEnter your choice (1-4): ").strip()
                
                if choice == '1':
                    enable_debug_mode()
                elif choice == '2':
                    disable_debug_mode()
                elif choice == '3':
                    check_debug_status()
                elif choice == '4':
                    print("πŸ‘‹ Goodbye!")
                else:
                    print("❌ Invalid choice")
                    
            except KeyboardInterrupt:
                print("\nπŸ‘‹ Goodbye!")
            except Exception as e:
                print(f"❌ Error: {e}")
        
        print("\n" + "=" * 40)
        print("πŸ’‘ Usage:")
        print("  python enable_debug_mode.py enable   # Enable debug mode")
        print("  python enable_debug_mode.py disable  # Disable debug mode")
        print("  python enable_debug_mode.py status   # Check status")
        print("  python enable_debug_mode.py          # Interactive mode")
        return 0
    run_cli_main(_main)