Hello people,
forwarding another bug by the same fellow DD as in the other message. See it
here:
  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=584781

--->8---
I'd like to run a bottle server without it spewing messages to
stdout/stderr. For that, I need to turn off the welcome code here:

   def run(app=None, server=AutoServer, host='127.0.0.1', port=8080,
           interval=1, reloader=False, **kargs):
       """ Runs bottle as a web server. """
       app = app if app else default_app()
       quiet = bool(kargs.get('quiet', False))
       # Instantiate server, if it is a class instead of an instance
       if isinstance(server, type):
           server = server(host=host, port=port, **kargs)
       if not isinstance(server, ServerAdapter):
           raise RuntimeError("Server must be a subclass of WSGIAdapter")
       if not quiet and isinstance(server, ServerAdapter): # pragma: no cover
           if not reloader or os.environ.get('BOTTLE_CHILD') == 'true':
               print "Bottle server starting up (using %s)..." % repr(server)
               print "Listening on http://%s:%d/"; % (server.host, server.port)
               print "Use Ctrl-C to quit."
               print
           else:
               print "Bottle auto reloader starting up..."
       try:
           if reloader and interval:
               reloader_run(server, app, interval)
           else:
               server.run(app)
       except KeyboardInterrupt:
           if not quiet: # pragma: no cover
               print "Shutting Down..."

Note that in order to do it, one just needs to pass quiet=True. Great.
Except, it uses kargs.get instead of kargs.pop, therefore leaving quiet
in the args that are passed to the server constructor 3 lines later.

Except, nowhere it says that the server constructor will accept a
'quiet' argument:

   $ ./arki-server ../data/conf  --quiet
   Traceback (most recent call last):
   [...]
     File "./arki-server", line 385, in start_server
       bottle.run(host=info.host, port=info.port, quiet=True)
     File "/usr/lib/pymodules/python2.5/bottle.py", line 1246, in run
       server.run(app)
     File "/usr/lib/pymodules/python2.5/bottle.py", line 1219, in run
       return sa(self.host, self.port, **self.options).run(handler)
     File "/usr/lib/pymodules/python2.5/bottle.py", line 1143, in run
       httpserver.serve(app, host=self.host, port=str(self.port),
   **self.options) TypeError: serve() got an unexpected keyword argument 'quiet'

All I'm left is monkeypatching ServerAdapter to remove quiet from its
args:

    # Monkeypatch bottle.ServerAdapter in order not to choke on 'quiet'
    oldinit = bottle.ServerAdapter.__init__
    def wrapper(self, host='127.0.0.1', port=8080, **kargs):
        kargs.pop("quiet", None)
        oldinit(self, host, port, **kargs)
    bottle.ServerAdapter.__init__ = wrapper

And yet, it's not enough:

    $ ./arki-server ../data/conf  --quiet
    serving on http://127.0.0.1:8080

There is no way whatsoever to tell paste's httpserver to shut up. It
just damn prints. From /usr/share/pyshared/paste/httpserver.py:
    [..]
---8<---

I already patched the Debian package to use kargs.pop() instead of kargs.get()
(that's why you see that bug closed). I already cloned it to the paste package,
so that they can fix that on their side.
However, there's still another message from him, which could be useful:

--->8---
Just for the record, here is the gist on how to silence that from
Bottle:

class WSGIRefServer(ServerAdapter):
    def run(self, handler): # pragma: no cover
        from wsgiref.simple_server import make_server, WSGIRequestHandler
        class QuietHandler(WSGIRequestHandler):
            def log_request(*args, **kw):
                pass
        srv = make_server(self.host, self.port, handler,
handler_class=QuietHandler)
        srv.serve_forever()

Obviously instead of pass one could choose to log properly, but I just
want it damn quiet, so that is my code.
---8<---

Maybe we can do something like that from Bottle's side, to have a consistent
"quiet=True" behaviour between the various adapters? (i.e. total silence, with
no output whatsoever, and maybe proper logging) -- I know it's a hack, but
better than waiting for the other N servers out there to be fixed.

Please remember to keep the bug CCed :)

Kindly,
David

-- 
 . ''`.   Debian developer | http://wiki.debian.org/DavidPaleino
 : :'  : Linuxer #334216 --|-- http://www.hanskalabs.net/
 `. `'`  GPG: 1392B174 ----|---- http://deb.li/dapal
   `-   2BAB C625 4E66 E7B8 450A C3E1 E6AA 9017 1392 B174

Attachment: signature.asc
Description: PGP signature

Reply via email to