|
17 | 17 |
|
18 | 18 | """Command-line script that runs a server over roundup.cgi.client. |
19 | 19 |
|
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 $ |
21 | 21 | """ |
22 | 22 | __docformat__ = 'restructuredtext' |
23 | 23 |
|
@@ -71,6 +71,7 @@ class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
71 | 71 | TRACKERS = None |
72 | 72 | LOG_IPADDRESS = 1 |
73 | 73 | DEBUG_MODE = False |
| 74 | + CONFIG = None |
74 | 75 |
|
75 | 76 | def get_tracker(self, name): |
76 | 77 | """Return a tracker instance for given tracker name""" |
@@ -167,11 +168,39 @@ def inner_run_cgi(self): |
167 | 168 | ''' |
168 | 169 | rest = self.path |
169 | 170 |
|
| 171 | + # file-like object for the favicon.ico file information |
| 172 | + favicon_fileobj = None |
| 173 | + |
170 | 174 | 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 | + |
171 | 187 | self.send_response(200) |
172 | 188 | self.send_header('Content-Type', 'image/x-icon') |
173 | 189 | 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 | + |
175 | 204 | return |
176 | 205 |
|
177 | 206 | i = rest.rfind('?') |
@@ -329,6 +358,9 @@ class ServerConfig(configuration.Config): |
329 | 358 | "If empty, listen on all network interfaces."), |
330 | 359 | (configuration.IntegerNumberOption, "port", DEFAULT_PORT, |
331 | 360 | "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."), |
332 | 364 | (configuration.NullableOption, "user", "", |
333 | 365 | "User ID as which the server will answer requests.\n" |
334 | 366 | "In order to use this option, " |
@@ -432,6 +464,7 @@ class RequestHandler(RoundupRequestHandler): |
432 | 464 | TRACKER_HOMES = dict(tracker_homes) |
433 | 465 | TRACKERS = trackers |
434 | 466 | DEBUG_MODE = self["MULTIPROCESS"] == "debug" |
| 467 | + CONFIG = self |
435 | 468 |
|
436 | 469 | # obtain request server class |
437 | 470 | if self["MULTIPROCESS"] not in MULTIPROCESS_TYPES: |
|
0 commit comments