def initialize_database(argv=None): """Initialize the database tables.""" parser = argparse.ArgumentParser() parser.add_argument('config', help="configuration file") args = parser.parse_args(argv) config = Configuration.from_file(args.config) make_app(config) from rhaptos2.repo.backend import initdb initdb(config) from rhaptos2.repo.sessioncache import set_config, initdb as sessinitdb set_config(config) sessinitdb()
def setup(): global TESTCONFIG global TESTAPP ## Tests can alter decl. THis resets everything reload(decl) # using nose-testconfig we obtain the config dict passed in through the # nosetests command line from testconfig import config ## now "convert" to app-style dict TESTCONFIG = convert_config(config) initdb(TESTCONFIG) cj = cookielib.CookieJar() ### Are we running by generating HTTP to fire at webserver ### or are we testing wsgi calls? if 'HTTPPROXY' in config.keys(): app = WSGIProxyApp(config['HTTPPROXY']) app.debug = True TESTAPP = TestApp(app, extra_environ={ 'REMOTE_ADDR': '1.2.3.4'}, cookiejar=cj) set_constants(config['HTTPPROXY'], TESTAPP) else: app = make_app(TESTCONFIG) app.debug = True sessioncache.set_config(config) TESTAPP = TestApp(app.wsgi_app, cookiejar=cj) set_constants("", TESTAPP)
def main_2(): opts, args = parse_args() config = Configuration.from_file(opts.conf) app = make_app(config) app.debug = True from waitress import serve serve(app.wsgi_app, host=opts.host, port=opts.port )
def get_app(opts, args, config, as_standalone = False, with_testuser = False): """ creates and sets up the app, *but does not run it through flask server unless told to* This intends to return a valid WSGI app to later be called by say gunicorn todo: I would like to use @pumazi approach of only importing _standalone server as needed returns a Flask app.wsgi_app, which can be passed into wsgi chain """ app = make_app(config) app.debug = True if as_standalone: if not os.path.isdir(opts.jslocation): raise IOError( "dir to serve static files (%s) does not exist" % opts.jslocation) ### Creating a mapping of URLS to file locations ### TODO: simplify this - proabbly need change atc and this ### may want to consider a config list of dirs, or grab ### list of dirs from FS (at jslocation) at startup time sloc = opts.jslocation stat = StaticURLParser(sloc) stat_config = StaticURLParser(os.path.join(sloc, "config")) stat_lib = StaticURLParser(os.path.join(sloc, "lib")) stat_bookish = StaticURLParser(os.path.join(sloc, "bookish")) stat_helpers = StaticURLParser(os.path.join(sloc, "helpers")) stat_node_modules = StaticURLParser(os.path.join(sloc, "node_modules")) ### give repo a simple response - /api/ will get rewritten ### todo: can I force URLMap not to adjust PATH info etc? mymaps = {"/": app.wsgi_app, "/js/": stat, "/js/config/": stat_config, "/js/lib/": stat_lib, "/js/bookish/": stat_bookish, "/js/helpers/": stat_helpers, "/js/node_modules/": stat_node_modules} urlmap = URLMap() urlmap.update(mymaps) # Need a fake user for testing, especially in the standalone case wrappedapp = urlmap else: wrappedapp = app.wsgi_app if with_testuser: wrappedapp = AddTestUser(wrappedapp) return wrappedapp
def paste_app_factory(global_config, **local_config): """Makes a WSGI application (in Flask this is ``app.wsgi_app``) and wraps it to serve the static web files. """ try: config_filepath = local_config['config'] except KeyError: raise RuntimeError("You must supply a reference as 'config' in " "the paste ini configuration file " "to the configuration ini file " "used by this application.") config = Configuration.from_file(config_filepath) app = make_app(config) # TODO This should be assigned in the app factory. app.debug = True return app
def mainold(): """Run the application, to be used to start up one instance""" opts, args = parse_args() confd = conf.get_config(opts.conf) app = make_app(confd) set_logger(APPTYPE, app.config) print app, "<-- Intialised app" # NOTE Do not use module reloading, even in debug mode, because it # produces new stray processes that supervisor does not ctl. app.run(host=opts.host, port=opts.port, debug=opts.debug, use_reloader=False )
def setup(): global TESTCONFIG global TESTAPP # using nose-testconfig we obtain the config dict passed in through the # nosetests command line from testconfig import config ## now "convert" to app-style dict TESTCONFIG = convert_config(config) if 'HTTPPROXY' in config.keys(): app = WSGIProxyApp(config['HTTPPROXY']) TESTAPP = TestApp(app, extra_environ={'REMOTE_ADDR': '1.2.3.4'}) else: app = make_app(TESTCONFIG) app.debug = True TESTAPP = TestApp(app.wsgi_app) print "Running setup" print "cookies", TESTAPP.cookies
def setup(): global TESTCONFIG global TESTAPP # using nose-testconfig we obtain the config dict passed in through the # nosetests command line from testconfig import config ## now "convert" to app-style dict TESTCONFIG = convert_config(config) # cleardown(TESTCONFIG) # initdb(TESTCONFIG) if 'HTTPPROXY' in config.keys(): app = WSGIProxyApp(config['HTTPPROXY']) TESTAPP = TestApp(app, extra_environ={'REMOTE_ADDR': '1.2.3.4'}) else: # cleardown(TESTCONFIG) # use this in setup - via a renaming? app = make_app(TESTCONFIG) app.debug = True TESTAPP = TestApp(app.wsgi_app)