Make download server less chatty. Fix a bug that made it impossible to exit.

This commit is contained in:
Storm Dragon
2025-08-27 00:31:27 -04:00
parent 3bc8b256b3
commit 0c9058e454
+24 -9
View File
@@ -46,7 +46,7 @@ def announce_server_start(ip, port):
subprocess.run(['spd-say', '-Cw', message])
print(f"Download server running on {ip}:{port}")
print("Press any key to repeat server information")
print("Press Ctrl+C to stop server")
print("Press 'q' to quit server")
except Exception as e:
print(f"Could not announce server start: {e}")
print(f"Download server running on {ip}:{port}")
@@ -77,9 +77,21 @@ def keyboard_listener():
# Read a single character
key = sys.stdin.read(1)
# Any key press will trigger the announcement
# Check for specific keys
if key:
repeat_announcement()
if key.lower() == 'q':
# Quit the server
print("\nShutting down server...")
try:
subprocess.run(['spd-say', '-Cw', 'Download server shutting down'])
except Exception:
pass
if server_info['httpd']:
server_info['httpd'].shutdown()
os._exit(0)
else:
# Any other key repeats the announcement
repeat_announcement()
except KeyboardInterrupt:
# Handle Ctrl+C gracefully
@@ -125,16 +137,19 @@ class DownloadHandler(http.server.SimpleHTTPRequestHandler):
super().__init__(*args, directory='/home/stormux', **kwargs)
def log_message(self, format, *args):
# Log downloads with speech announcement
# Log downloads with speech announcement - be less chatty
client_ip = self.client_address[0]
if 'GET' in format % args and not any(x in format % args for x in ['.ico', '.css', '.js']):
if 'GET' in format % args:
try:
# Only announce actual file downloads, not directory listings or favicon requests
path = args[1] if len(args) > 1 else "unknown"
if not path.endswith('/'): # It's a file, not directory
# Only announce actual file downloads (not directories, not common web files)
if (not path.endswith('/') and
not any(x in path.lower() for x in ['.ico', '.css', '.js', '.png', '.jpg', '.gif', '.svg']) and
path != '/' and path != '' and '?' not in path):
filename = os.path.basename(path)
subprocess.run(['spd-say', '-Cw', f'File {filename} downloaded by {client_ip}'],
timeout=5)
# Only announce files with actual content extensions
if any(filename.lower().endswith(ext) for ext in ['.mp3', '.ogg', '.flac', '.wav', '.nes', '.smc', '.do', '.dsk', '.pdf', '.txt', '.zip', '.tgz', '.tar']):
subprocess.run(['spd-say', '-Cw', f'File {filename} downloaded'], timeout=3)
except Exception:
pass
# Still print to console