Make download server less chatty. Fix a bug that made it impossible to exit.
This commit is contained in:
@@ -46,7 +46,7 @@ def announce_server_start(ip, port):
|
|||||||
subprocess.run(['spd-say', '-Cw', message])
|
subprocess.run(['spd-say', '-Cw', message])
|
||||||
print(f"Download server running on {ip}:{port}")
|
print(f"Download server running on {ip}:{port}")
|
||||||
print("Press any key to repeat server information")
|
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:
|
except Exception as e:
|
||||||
print(f"Could not announce server start: {e}")
|
print(f"Could not announce server start: {e}")
|
||||||
print(f"Download server running on {ip}:{port}")
|
print(f"Download server running on {ip}:{port}")
|
||||||
@@ -77,9 +77,21 @@ def keyboard_listener():
|
|||||||
# Read a single character
|
# Read a single character
|
||||||
key = sys.stdin.read(1)
|
key = sys.stdin.read(1)
|
||||||
|
|
||||||
# Any key press will trigger the announcement
|
# Check for specific keys
|
||||||
if key:
|
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:
|
except KeyboardInterrupt:
|
||||||
# Handle Ctrl+C gracefully
|
# Handle Ctrl+C gracefully
|
||||||
@@ -125,16 +137,19 @@ class DownloadHandler(http.server.SimpleHTTPRequestHandler):
|
|||||||
super().__init__(*args, directory='/home/stormux', **kwargs)
|
super().__init__(*args, directory='/home/stormux', **kwargs)
|
||||||
|
|
||||||
def log_message(self, format, *args):
|
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]
|
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:
|
try:
|
||||||
# Only announce actual file downloads, not directory listings or favicon requests
|
|
||||||
path = args[1] if len(args) > 1 else "unknown"
|
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)
|
filename = os.path.basename(path)
|
||||||
subprocess.run(['spd-say', '-Cw', f'File {filename} downloaded by {client_ip}'],
|
# Only announce files with actual content extensions
|
||||||
timeout=5)
|
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:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
# Still print to console
|
# Still print to console
|
||||||
|
|||||||
Reference in New Issue
Block a user