def setUp(self): """Loads the sample application.""" app_root = os.path.join(os.path.dirname(__file__), 'sample') os.chdir(app_root) sys.path.insert(0, os.getcwd()) self.conf = twistedae.getAppConfig() assert self.conf.application == 'sample'
def main(): """Runs the apptool console script.""" op = optparse.OptionParser(description=DESCRIPTION, usage=USAGE) op.add_option("--fcgi_host", dest="addr", metavar="ADDR", help="use this FastCGI host", default='localhost') op.add_option("--fcgi_port", dest="port", metavar="PORT", help="use this port of the FastCGI host", default='8081') op.add_option("-n", "--nginx", dest="nginx", metavar="FILE", help="write nginx configuration to this file", default=os.path.join('etc', 'server.conf')) op.add_option("-s", "--supervisor", dest="supervisor", metavar="FILE", help="write supervisor configuration to this file", default=os.path.join('etc', 'appserver.conf')) op.add_option("--var", dest="var", metavar="PATH", help="use this directory for platform independent data", default=os.environ.get('TMPDIR', '/var')) (options, args) = op.parse_args() if sys.argv[-1].startswith('-') or sys.argv[-1] == sys.argv[0]: op.print_usage() sys.exit(2) app_root = sys.argv[-1] if not os.path.isabs(app_root): app_root = os.path.normpath(os.path.join(os.getcwd(), app_root)) conf = twistedae.getAppConfig(app_root) write_nginx_conf(options, conf, app_root) write_supervisor_conf(options, conf, app_root)
def main(): """Initializes the server.""" op = optparse.OptionParser(description=DESCRIPTION, usage=USAGE) op.add_option("--log", dest="logfile", metavar="FILE", help="write logging output to this file", default=os.path.join(os.environ['TMPDIR'], 'fcgi.log')) (options, args) = op.parse_args() if sys.argv[-1].startswith('-') or sys.argv[-1] == sys.argv[0]: op.print_usage() sys.exit(2) app_root = sys.argv[-1] logging.basicConfig( format='%(levelname)-8s %(asctime)s %(filename)s:%(lineno)s] ' '%(message)s', level=logging.INFO, filename=options.logfile) # Change the current working directory to the application root and load # the application configuration os.chdir(app_root) sys.path.insert(0, app_root) conf = twistedae.getAppConfig() # Inititalize API proxy stubs twistedae.setupStubs(conf) # Serve the application try: serve(conf) except: logging.error(get_traceback())