9
9
"""
10
10
11
11
import argparse
12
+ import json
12
13
import os
13
14
import re
14
15
import subprocess
15
- import json
16
- from typing import Optional , Any
16
+ from typing import Optional
17
17
18
18
19
19
def analyze_debug_log (log_file : str = "debug.log" ) -> None :
@@ -25,30 +25,25 @@ def analyze_debug_log(log_file: str = "debug.log") -> None:
25
25
return
26
26
27
27
print (f"Analyzing { log_file } ..." ) # noqa: T201
28
- with open (log_file , 'r' ) as f :
28
+ with open (log_file , "r" ) as f :
29
29
content = f .read ()
30
30
31
31
# Look for error patterns
32
- error_patterns = [
33
- r'ERROR' ,
34
- r'Exception' ,
35
- r'Traceback' ,
36
- r'Failed to'
37
- ]
32
+ error_patterns = [r"ERROR" , r"Exception" , r"Traceback" , r"Failed to" ]
38
33
39
34
errors_found = False
40
35
for pattern in error_patterns :
41
36
matches = re .finditer (pattern , content , re .IGNORECASE )
42
37
for match in matches :
43
- line_start = content .rfind (' \n ' , 0 , match .start ()) + 1
44
- line_end = content .find (' \n ' , match .end ())
38
+ line_start = content .rfind (" \n " , 0 , match .start ()) + 1
39
+ line_end = content .find (" \n " , match .end ())
45
40
if line_end == - 1 :
46
41
line_end = len (content )
47
-
42
+
48
43
line = content [line_start :line_end ].strip ()
49
44
print (f"Potential issue found: { line } " ) # noqa: T201
50
45
errors_found = True
51
-
46
+
52
47
if not errors_found :
53
48
print ("No obvious errors found in the log file." ) # noqa: T201
54
49
@@ -61,29 +56,36 @@ def test_connectivity(server_url: Optional[str] = None) -> None:
61
56
# Try to get server URL from zuliprc
62
57
zuliprc_path = os .path .expanduser ("~/.zuliprc" )
63
58
if os .path .exists (zuliprc_path ):
64
- with open (zuliprc_path , 'r' ) as f :
59
+ with open (zuliprc_path , "r" ) as f :
65
60
for line in f :
66
- if line .startswith (' site=' ):
67
- server_url = line .split ('=' )[1 ].strip ()
61
+ if line .startswith (" site=" ):
62
+ server_url = line .split ("=" )[1 ].strip ()
68
63
break
69
-
64
+
70
65
if not server_url :
71
- print ("Error: No server URL provided and couldn't find one in ~/.zuliprc" ) # noqa: T201
66
+ print (
67
+ "Error: No server URL provided and couldn't find one in ~/.zuliprc"
68
+ ) # noqa: T201
72
69
return
73
70
74
71
print (f"Testing connectivity to { server_url } ..." ) # noqa: T201
75
72
try :
76
73
import requests
74
+
77
75
response = requests .get (f"{ server_url } /api/v1/server_settings" )
78
76
if response .status_code == 200 :
79
77
print (f"Successfully connected to { server_url } " ) # noqa: T201
80
78
try :
81
79
settings = response .json ()
82
- print (f"Server version: { settings .get ('zulip_version' , 'unknown' )} " ) # noqa: T201
80
+ print (
81
+ f"Server version: { settings .get ('zulip_version' , 'unknown' )} "
82
+ ) # noqa: T201
83
83
except json .JSONDecodeError :
84
84
print ("Received response, but couldn't parse as JSON" ) # noqa: T201
85
85
else :
86
- print (f"Failed to connect: HTTP status { response .status_code } " ) # noqa: T201
86
+ print (
87
+ f"Failed to connect: HTTP status { response .status_code } "
88
+ ) # noqa: T201
87
89
except Exception as e :
88
90
print (f"Connection error: { e } " ) # noqa: T201
89
91
@@ -93,29 +95,30 @@ def check_terminal_capabilities() -> None:
93
95
Check for terminal capabilities that might affect Zulip Terminal.
94
96
"""
95
97
print ("Checking terminal capabilities..." ) # noqa: T201
96
-
98
+
97
99
# Check for color support
98
- colors = os .environ .get (' TERM' , ' unknown' )
100
+ colors = os .environ .get (" TERM" , " unknown" )
99
101
print (f"TERM environment: { colors } " ) # noqa: T201
100
-
101
- if ' COLORTERM' in os .environ :
102
+
103
+ if " COLORTERM" in os .environ :
102
104
print (f"COLORTERM: { os .environ ['COLORTERM' ]} " ) # noqa: T201
103
-
105
+
104
106
# Check for Unicode support
105
107
print ("\n Testing Unicode rendering capabilities:" ) # noqa: T201
106
108
test_chars = [
107
109
("Basic symbols" , "▶ ◀ ✓ ✗" ),
108
110
("Emoji (simple)" , "😀 🙂 👍" ),
109
111
("Box drawing" , "│ ┌ ┐ └ ┘ ├ ┤ ┬ ┴ ┼" ),
110
- ("Math symbols" , "∞ ∑ √ ∫ π" )
112
+ ("Math symbols" , "∞ ∑ √ ∫ π" ),
111
113
]
112
-
114
+
113
115
for name , chars in test_chars :
114
116
print (f" { name } : { chars } " ) # noqa: T201
115
-
117
+
116
118
# Check for urwid compatibility
117
119
try :
118
120
import urwid # noqa: F401
121
+
119
122
print ("\n Urwid detected. Running basic urwid test..." ) # noqa: T201
120
123
# This doesn't actually run a visual test - just checks if urwid can be imported
121
124
print ("Urwid import successful" ) # noqa: T201
@@ -129,24 +132,26 @@ def main() -> None:
129
132
"""
130
133
parser = argparse .ArgumentParser (description = "Zulip Terminal Debugging Helper" )
131
134
subparsers = parser .add_subparsers (dest = "command" , help = "Command to run" )
132
-
135
+
133
136
# Log analyzer
134
137
log_parser = subparsers .add_parser ("log" , help = "Analyze debug logs" )
135
138
log_parser .add_argument ("--file" , default = "debug.log" , help = "Log file to analyze" )
136
-
139
+
137
140
# Connectivity test
138
141
conn_parser = subparsers .add_parser ("connect" , help = "Test connectivity" )
139
- conn_parser .add_argument ("--server" , help = "Server URL (e.g., https://chat.zulip.org)" )
140
-
142
+ conn_parser .add_argument (
143
+ "--server" , help = "Server URL (e.g., https://chat.zulip.org)"
144
+ )
145
+
141
146
# Terminal test
142
147
subparsers .add_parser ("terminal" , help = "Check terminal capabilities" )
143
-
148
+
144
149
# Run zulip-term with debug
145
150
run_parser = subparsers .add_parser ("run" , help = "Run zulip-term with debugging" )
146
151
run_parser .add_argument ("--profile" , action = "store_true" , help = "Enable profiling" )
147
-
152
+
148
153
args = parser .parse_args ()
149
-
154
+
150
155
if args .command == "log" :
151
156
analyze_debug_log (args .file )
152
157
elif args .command == "connect" :
0 commit comments