Source /

import os

from werkzeug import script
from werkzeug.serving import run_simple
from werkzeug.utils import create_environ, run_wsgi_app

from shorty.application import make_app
from shorty.utils import local, session

root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__)))

db_uri = 'sqlite:///' + os.path.join(root_dir, 'shorty.db')

def run_app(app, path='/'):
	env = create_environ(path)
	return run_wsgi_app(app, env)

action_runserver = script.make_runserver(
	lambda: make_app(db_uri), use_reloader=True)

action_shell = script.make_shell(
	lambda: {
		'app': make_app(db_uri, False, True),
		'local': local,
		'session': session,
		'run_app': run_app,
	("""Welcome to the interactive shell environment of Shorty!
	You can use the following predefined objects: app, local, session.
	To run the application (creates a request) use *run_app*.""")

action_initdb = lambda: make_app(db_uri).init_database()

if __name__ == '__main__':