Skip to content

Commit 310bcbd

Browse files
author
Alexander Smishlajev
committed
added favicon config option (patch [SF#1355661])
1 parent bdc36f6 commit 310bcbd

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

roundup/scripts/roundup_server.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
"""Command-line script that runs a server over roundup.cgi.client.
1919
20-
$Id: roundup_server.py,v 1.80 2005-12-03 09:37:24 a1s Exp $
20+
$Id: roundup_server.py,v 1.81 2005-12-25 14:52:33 a1s Exp $
2121
"""
2222
__docformat__ = 'restructuredtext'
2323

@@ -71,6 +71,7 @@ class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
7171
TRACKERS = None
7272
LOG_IPADDRESS = 1
7373
DEBUG_MODE = False
74+
CONFIG = None
7475

7576
def get_tracker(self, name):
7677
"""Return a tracker instance for given tracker name"""
@@ -167,11 +168,39 @@ def inner_run_cgi(self):
167168
'''
168169
rest = self.path
169170

171+
# file-like object for the favicon.ico file information
172+
favicon_fileobj = None
173+
170174
if rest == '/favicon.ico':
175+
# check to see if a custom favicon was specified, and set
176+
# favicon_fileobj to the input file
177+
if self.CONFIG is not None:
178+
favicon_filepath = os.path.abspath(self.CONFIG['FAVICON'])
179+
180+
if os.access(favicon_filepath, os.R_OK):
181+
favicon_fileobj = open(favicon_filepath, 'rb')
182+
183+
184+
if favicon_fileobj is None:
185+
favicon_fileobj = StringIO.StringIO(favico)
186+
171187
self.send_response(200)
172188
self.send_header('Content-Type', 'image/x-icon')
173189
self.end_headers()
174-
self.wfile.write(favico)
190+
191+
# this bufsize is completely arbitrary, I picked 4K because it sounded good.
192+
# if someone knows of a better buffer size, feel free to plug it in.
193+
bufsize = 4 * 1024
194+
Processing = True
195+
while Processing:
196+
data = favicon_fileobj.read(bufsize)
197+
if len(data) > 0:
198+
self.wfile.write(data)
199+
else:
200+
Processing = False
201+
202+
favicon_fileobj.close()
203+
175204
return
176205

177206
i = rest.rfind('?')
@@ -329,6 +358,9 @@ class ServerConfig(configuration.Config):
329358
"If empty, listen on all network interfaces."),
330359
(configuration.IntegerNumberOption, "port", DEFAULT_PORT,
331360
"Port to listen on."),
361+
(configuration.NullableFilePathOption, "favicon", "favicon.ico",
362+
"Path to favicon.ico image file."
363+
" If unset, built-in favicon.ico is used."),
332364
(configuration.NullableOption, "user", "",
333365
"User ID as which the server will answer requests.\n"
334366
"In order to use this option, "
@@ -432,6 +464,7 @@ class RequestHandler(RoundupRequestHandler):
432464
TRACKER_HOMES = dict(tracker_homes)
433465
TRACKERS = trackers
434466
DEBUG_MODE = self["MULTIPROCESS"] == "debug"
467+
CONFIG = self
435468

436469
# obtain request server class
437470
if self["MULTIPROCESS"] not in MULTIPROCESS_TYPES:

0 commit comments

Comments
 (0)