1 # -*- coding: utf-8 -*-
\r
2 """This module contains functions called from console script entry points."""
\r
5 from os import getcwd, getpid
\r
6 from os.path import dirname, exists, join
\r
9 pkg_resources.require("TurboGears>=1.0.7")
\r
14 cherrypy.lowercase_api = True
\r
17 class ConfigurationError(Exception):
\r
22 """Start the CherryPy application server."""
\r
24 setupdir = dirname(dirname(__file__))
\r
27 # First look on the command line for a desired config file,
\r
28 # if it's not on the command line, then look for 'setup.py'
\r
29 # in the current directory. If there, load configuration
\r
30 # from a file called 'dev.cfg'. If it's not there, the project
\r
31 # is probably installed and we'll look first for a file called
\r
32 # 'prod.cfg' in the current directory and then for a default
\r
33 # config file called 'default.cfg' packaged in the egg.
\r
34 if len(sys.argv) > 1:
\r
35 configfile = sys.argv[1]
\r
36 elif exists(join(setupdir, "setup.py")):
\r
37 configfile = join(setupdir, "dev.cfg")
\r
38 elif exists(join(curdir, "prod.cfg")):
\r
39 configfile = join(curdir, "prod.cfg")
\r
42 configfile = pkg_resources.resource_filename(
\r
43 pkg_resources.Requirement.parse("MonitorWeb"),
\r
44 "config/default.cfg")
\r
45 except pkg_resources.DistributionNotFound:
\r
46 raise ConfigurationError("Could not find default configuration.")
\r
48 if "prod" in configfile:
\r
49 f = open("/var/run/monitorweb.pid", 'w')
\r
50 f.write(str(getpid()))
\r
53 turbogears.update_config(configfile=configfile,
\r
54 modulename="monitorweb.config")
\r
56 from monitorweb.controllers import Root
\r
58 turbogears.start_server(Root())
\r