diff options
author | Robert Brewer <fumanchu@aminus.org> | 2009-04-23 19:48:09 +0000 |
---|---|---|
committer | Robert Brewer <fumanchu@aminus.org> | 2009-04-23 19:48:09 +0000 |
commit | e0f24db0948bd4977625df5109fb4313eeb76a10 (patch) | |
tree | b532729da2b37afb43508a2f1d6fce88d9716045 /cherrypy/lib/covercp.py | |
parent | a13efa6ee946ea2916d902b3e386427c6bbb35ad (diff) | |
download | cherrypy-git-e0f24db0948bd4977625df5109fb4313eeb76a10.tar.gz |
covercp: Fixed bug when supplying port via command line. Added commandline option to serve different root. Removed admonition to subscribe covercp.start to start_thread.
Diffstat (limited to 'cherrypy/lib/covercp.py')
-rw-r--r-- | cherrypy/lib/covercp.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/cherrypy/lib/covercp.py b/cherrypy/lib/covercp.py index ecc8cf47..d338e739 100644 --- a/cherrypy/lib/covercp.py +++ b/cherrypy/lib/covercp.py @@ -11,7 +11,11 @@ http://www.nedbatchelder.com/code/modules/coverage.html To turn on coverage tracing, use the following code: cherrypy.engine.subscribe('start', covercp.start) - cherrypy.engine.subscribe('start_thread', covercp.start) + +DO NOT subscribe anything on the 'start_thread' channel, as previously +recommended. Calling start once in the main thread should be sufficient +to start coverage on all threads. Calling start again in each thread +effectively clears any coverage data gathered up to that point. Run your code, then use the covercp.serve() function to browse the results in a web browser. If you run this module from the command line, @@ -32,7 +36,7 @@ except ImportError: try: from coverage import the_coverage as coverage - def start(threadid=None): + def start(): coverage.start() except ImportError: # Setting coverage to None will raise errors @@ -42,14 +46,10 @@ except ImportError: import warnings warnings.warn("No code coverage will be performed; coverage.py could not be imported.") - def start(threadid=None): + def start(): pass start.priority = 20 -# Guess initial depth to hide FIXME this doesn't work for non-cherrypy stuff -import cherrypy -initial_base = os.path.dirname(cherrypy.__file__) - TEMPLATE_MENU = """<html> <head> <title>CherryPy Coverage Menu</title> @@ -140,7 +140,7 @@ TEMPLATE_FRAMESET = """<html> <frame name='main' src='' /> </frameset> </html> -""" % initial_base.lower() +""" TEMPLATE_COVERAGE = """<html> <head> @@ -266,8 +266,16 @@ def get_tree(base, exclude): class CoverStats(object): + def __init__(self, root=None): + if root is None: + # Guess initial depth. Files outside this path will not be + # reachable from the web interface. + import cherrypy + root = os.path.dirname(cherrypy.__file__) + self.root = root + def index(self): - return TEMPLATE_FRAMESET + return TEMPLATE_FRAMESET % self.root.lower() index.exposed = True def menu(self, base="/", pct="50", showpct="", @@ -344,17 +352,17 @@ class CoverStats(object): report.exposed = True -def serve(path=localFile, port=8080): +def serve(path=localFile, port=8080, root=None): if coverage is None: raise ImportError("The coverage module could not be imported.") coverage.cache_default = path import cherrypy - cherrypy.config.update({'server.socket_port': port, + cherrypy.config.update({'server.socket_port': int(port), 'server.thread_pool': 10, 'environment': "production", }) - cherrypy.quickstart(CoverStats()) + cherrypy.quickstart(CoverStats(root)) if __name__ == "__main__": serve(*tuple(sys.argv[1:])) |