Skip to content

Commit ce796de

Browse files
committed
scripts/debug: Reformat helper tools.
1 parent a1a61bc commit ce796de

File tree

2 files changed

+40
-200
lines changed

2 files changed

+40
-200
lines changed

tools/debug_helper.py

-165
This file was deleted.

zulipterminal/scripts/debug_helper.py

+40-35
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
"""
1010

1111
import argparse
12+
import json
1213
import os
1314
import re
1415
import subprocess
15-
import json
16-
from typing import Optional, Any
16+
from typing import Optional
1717

1818

1919
def analyze_debug_log(log_file: str = "debug.log") -> None:
@@ -25,30 +25,25 @@ def analyze_debug_log(log_file: str = "debug.log") -> None:
2525
return
2626

2727
print(f"Analyzing {log_file}...") # noqa: T201
28-
with open(log_file, 'r') as f:
28+
with open(log_file, "r") as f:
2929
content = f.read()
3030

3131
# 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"]
3833

3934
errors_found = False
4035
for pattern in error_patterns:
4136
matches = re.finditer(pattern, content, re.IGNORECASE)
4237
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())
4540
if line_end == -1:
4641
line_end = len(content)
47-
42+
4843
line = content[line_start:line_end].strip()
4944
print(f"Potential issue found: {line}") # noqa: T201
5045
errors_found = True
51-
46+
5247
if not errors_found:
5348
print("No obvious errors found in the log file.") # noqa: T201
5449

@@ -61,29 +56,36 @@ def test_connectivity(server_url: Optional[str] = None) -> None:
6156
# Try to get server URL from zuliprc
6257
zuliprc_path = os.path.expanduser("~/.zuliprc")
6358
if os.path.exists(zuliprc_path):
64-
with open(zuliprc_path, 'r') as f:
59+
with open(zuliprc_path, "r") as f:
6560
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()
6863
break
69-
64+
7065
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
7269
return
7370

7471
print(f"Testing connectivity to {server_url}...") # noqa: T201
7572
try:
7673
import requests
74+
7775
response = requests.get(f"{server_url}/api/v1/server_settings")
7876
if response.status_code == 200:
7977
print(f"Successfully connected to {server_url}") # noqa: T201
8078
try:
8179
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
8383
except json.JSONDecodeError:
8484
print("Received response, but couldn't parse as JSON") # noqa: T201
8585
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
8789
except Exception as e:
8890
print(f"Connection error: {e}") # noqa: T201
8991

@@ -93,29 +95,30 @@ def check_terminal_capabilities() -> None:
9395
Check for terminal capabilities that might affect Zulip Terminal.
9496
"""
9597
print("Checking terminal capabilities...") # noqa: T201
96-
98+
9799
# Check for color support
98-
colors = os.environ.get('TERM', 'unknown')
100+
colors = os.environ.get("TERM", "unknown")
99101
print(f"TERM environment: {colors}") # noqa: T201
100-
101-
if 'COLORTERM' in os.environ:
102+
103+
if "COLORTERM" in os.environ:
102104
print(f"COLORTERM: {os.environ['COLORTERM']}") # noqa: T201
103-
105+
104106
# Check for Unicode support
105107
print("\nTesting Unicode rendering capabilities:") # noqa: T201
106108
test_chars = [
107109
("Basic symbols", "▶ ◀ ✓ ✗"),
108110
("Emoji (simple)", "😀 🙂 👍"),
109111
("Box drawing", "│ ┌ ┐ └ ┘ ├ ┤ ┬ ┴ ┼"),
110-
("Math symbols", "∞ ∑ √ ∫ π")
112+
("Math symbols", "∞ ∑ √ ∫ π"),
111113
]
112-
114+
113115
for name, chars in test_chars:
114116
print(f" {name}: {chars}") # noqa: T201
115-
117+
116118
# Check for urwid compatibility
117119
try:
118120
import urwid # noqa: F401
121+
119122
print("\nUrwid detected. Running basic urwid test...") # noqa: T201
120123
# This doesn't actually run a visual test - just checks if urwid can be imported
121124
print("Urwid import successful") # noqa: T201
@@ -129,24 +132,26 @@ def main() -> None:
129132
"""
130133
parser = argparse.ArgumentParser(description="Zulip Terminal Debugging Helper")
131134
subparsers = parser.add_subparsers(dest="command", help="Command to run")
132-
135+
133136
# Log analyzer
134137
log_parser = subparsers.add_parser("log", help="Analyze debug logs")
135138
log_parser.add_argument("--file", default="debug.log", help="Log file to analyze")
136-
139+
137140
# Connectivity test
138141
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+
141146
# Terminal test
142147
subparsers.add_parser("terminal", help="Check terminal capabilities")
143-
148+
144149
# Run zulip-term with debug
145150
run_parser = subparsers.add_parser("run", help="Run zulip-term with debugging")
146151
run_parser.add_argument("--profile", action="store_true", help="Enable profiling")
147-
152+
148153
args = parser.parse_args()
149-
154+
150155
if args.command == "log":
151156
analyze_debug_log(args.file)
152157
elif args.command == "connect":

0 commit comments

Comments
 (0)