Exemple #1
0
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
Exemple #2
0
	username="******",
	realname="jacob"
)

@coroutine_page()
def last_page():
        yield
	print "returning: %s" % repr("\n".join(last_messages))
        raise StopIteration("\n".join(last_messages))


application = URLMap()
application.update({
	"/pony": PonyMiddleware(HTTPNotFound()),
	"/introspector": Introspector(),
	"/irc": CometIRCReader(irc_conn),
	"/last": last_page,
	"/static": StaticFileServer("/home/jacob/code/chiral/irc-static")
})

HTTPServer(
	bind_addr = ('', 8081),
	application = application
).start()

print "Running..."

reactor.run()

stats.dump()
Exemple #3
0
print "Initializing..."

@coroutine_page()
@use_template("genshi", "chiral.web.templates.helloworld")
def asyncpagetest():
	yield
	raise StopIteration({ "foo": "Test Page" })

introspector = Introspector()

application = URLMap()
application.update({
	"/pony": PonyMiddleware(HTTPNotFound()),
	"/introspector": Introspector(),
	"/static": StaticFileServer("/home/jacob/code/chiral/static"),
	"/asyncpagetest": asyncpagetest,
	"/cometlib": CometLibServer(),
	"/": CometClock()
})

HTTPServer(
	bind_addr = ('', 8081),
	application = application
).start()

ChiralShellServer(
	bind_addr = ('', 9123)
).start()

print "Running..."