def enter(context, install_dependencies=True, upgrade_db=True):
    """
    Enter into IPython notebook shell with an initialized app.
    """
    if install_dependencies:
        context.invoke_execute(context, 'app.dependencies.install')
    if upgrade_db:
        context.invoke_execute(context, 'app.db.upgrade')
 
    import pprint
    import logging

    from werkzeug import script
    import flask

    import app
    flask_app = app.create_app()

    def shell_context():
        context = dict(pprint=pprint.pprint)
        context.update(vars(flask))
        context.update(vars(app))
        return context

    with flask_app.app_context():
        script.make_shell(shell_context, use_ipython=True)()
Beispiel #2
0
def main(argv=None):

    if not argv:
        argv = sys.argv[1:]

    options = parse_args(argv)

    app = init_app(options.config)

    if options.shell:
        script.make_shell(make_shell, use_ipython=True)
    else:
        app.run(host=options.host, port=int(options.port))

    return 0
Beispiel #3
0
def run_werkzeug(app, host='127.0.0.1', port=8000, thread=0, proc=1):
    from werkzeug import script
    action_runserver = None
    if thread > 0:
        action_runserver = script.make_runserver(lambda: app, hostname=host, port=port, threaded=thread)
    else:
        action_runserver = script.make_runserver(lambda: app, hostname=host, port=port, processes=proc)
    log.info("Server running on port %s:%d" % (host, port))
    action_shell = script.make_shell(lambda: {})
    script.run(args=['runserver'])
Beispiel #4
0
 def __init__(self, application):
     self.application = application
     self._actions = {
             'cherrypy'  :   run_cherrypy_server(application),
             'runcgi'    :   runcgi(application),
             'shell'     :   script.make_shell(lambda: {"app": application}),
             'runserver' :   script.make_runserver(lambda: application,
                                 use_reloader=True, threaded=True, hostname='localhost',
                                 port=7777, use_debugger=True),
     }
Beispiel #5
0
def action_template_shell(ipython=True):
    """Start an interactive debugging shell.

    Two extras are in the shell namespace: 'loader', a template
    loader, and 'config', a blatter config.

    """
    config = load_config()
    env = dict(config=config,
               loader=template_loader_for(config))

    from werkzeug import script
    shell = script.make_shell(init_func=lambda: env)
    return shell(ipython=ipython)
Beispiel #6
0
from werkzeug import script

env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do',
                                     'jinja2.ext.loopcontrols',
                                     'jinja2.ext.with_',
                                     'jinja2.ext.autoescape'],
                         autoescape=True)

def shell_init_func():
    def _compile(x):
        print(env.compile(x, raw=True))
    result = {
        'e':        env,
        'c':        _compile,
        't':        env.from_string,
        'p':        env.parse
    }
    for key in jinja2.__all__:
        result[key] = getattr(jinja2, key)
    return result


def action_compile():
    print(env.compile(sys.stdin.read(), raw=True))

action_shell = script.make_shell(shell_init_func)


if __name__ == '__main__':
    script.run()
Beispiel #7
0
"""
import os
from werkzeug import script


def make_app():
    """Helper function that creates a plnt app."""
    from plnt import Plnt
    database_uri = os.environ.get('PLNT_DATABASE_URI')
    app = Plnt(database_uri or 'sqlite:////tmp/plnt.db')
    app.bind_to_context()
    return app


action_runserver = script.make_runserver(make_app, use_reloader=True)
action_shell = script.make_shell(lambda: {'app': make_app()})


def action_initdb():
    """Initialize the database"""
    from plnt.database import Blog, session
    make_app().init_database()
    # and now fill in some python blogs everybody should read (shamelessly
    # added my own blog too)
    blogs = [
        Blog('Armin Ronacher', 'http://lucumr.pocoo.org/',
             'http://lucumr.pocoo.org/cogitations/feed/'),
        Blog('Georg Brandl', 'http://pyside.blogspot.com/',
             'http://pyside.blogspot.com/feeds/posts/default'),
        Blog('Ian Bicking', 'http://blog.ianbicking.org/',
             'http://blog.ianbicking.org/feed/'),
Beispiel #8
0
#!/usr/bin/env python

from werkzeug import script
from werkzeug.contrib import profiler
import tracker.main
import tracker.tests
import sys

def make_app():
	return tracker.main.application

action_runserver = script.make_runserver(make_app, use_reloader=True)
action_shell = script.make_shell(use_ipython=True)
action_profile = profiler.make_action(make_app)

def action_syncviews():
	"""
	Synchronize views to CouchDB.
	"""
	from webui import couchdb_views
	from couchdb.design import ViewDefinition
	import webui.db
	try:
		ViewDefinition.sync_many(webui.db.database,
			couchdb_views.view_definitions)
	except AttributeError:
		print 'Error: CouchDB must not be running'
		sys.exit(1)

if __name__ == '__main__':
	script.run()
def shell():
    script.make_shell(lambda: {'app': app}, use_ipython=True)()
Beispiel #10
0
from mozugs.app import BugTrackerApp


static = {"/static": os.path.join(root, "static")}
config_dir = os.path.join(root, "config")
config_files = [os.path.join(config_dir, fn) for fn in os.listdir(config_dir) if fn.endswith(".ini")]


def _create_app():
    app = BugTrackerApp(root, [os.path.join(config_dir, "test.ini"), os.path.join(config_dir, "local.ini")])
    models.ModelBase.metadata.create_all(app.engine)
    return app


def _init_shell():
    return {"app": _create_app()}


action_run = script.make_runserver(
    _create_app, port=1111, use_reloader=True, extra_files=config_files, static_files=static
)
action_shell = script.make_shell(_init_shell)


def action_gensalt():
    print(security.gen_salt(8))


if __name__ == "__main__":
    script.run(globals())
Beispiel #11
0
from lodgeit import local
from lodgeit.application import make_app
from lodgeit.database import session

dburi = 'sqlite:////tmp/lodgeit.db'

SECRET_KEY = 'no secret key'


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


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

action_shell = script.make_shell(
    lambda: {
        'app': make_app(dburi, SECRET_KEY, False, True),
        'local': local,
        'session': session,
        'run_app': run_app
    }, ('\nWelcome to the interactive shell environment of LodgeIt!\n'
        '\n'
        'You can use the following predefined objects: app, local, session.\n'
        'To run the application (creates a request) use *run_app*.'))

if __name__ == '__main__':
    script.run()
Beispiel #12
0
            templates = path.realpath(path.expanduser(templates))
            if path.exists(templates):
                template_paths.append(templates)
            else:
                print ' * ERROR: The specified template path wasn\'t found.'
                sys.exit(1)
        else:        
            if path.exists(path.join(path.dirname(__file__), 'templates')):
                template_paths.append(path.abspath(path.join(path.dirname(__file__), 'templates')))
            if path.exists('/usr/share/buteo/templates'):
                template_paths.append('/usr/share/buteo/templates')
            
        if template_paths == []:
            print ' * ERROR: No template files have been found. Specify a template path with the -t option.'
            sys.exit(1)
        else:
            print ' * Using %s as template path.' % template_paths
         
        from buteo import Buteo
        from werkzeug.serving import run_simple
        app = Buteo(cfg_file, plugin_path, template_paths)
        run_simple(hostname, port, app, reloader, debugger, evalex,
                   extra_files, 1, threaded, processes, static_files)
    return action

action_runserver = _runserver()
action_shell = script.make_shell(lambda: {'app': _runserver()})

if __name__ == '__main__':       
    script.run()   
Beispiel #13
0
sys.path.insert(0, path.normpath(path.join(
    path.dirname(path.realpath(__file__)), path.pardir)))

from config import config

parser = argparse.ArgumentParser()
parser.add_argument('command', type=str, nargs=1,
                    help='Command to run')
parser.add_argument('--config', required=False, default='default',
                    help='Config name')
args = parser.parse_args()


config.use(args.config)


if 'shell' in args.command:
    from werkzeug import script

    def make_shell():
        return {
            'config': config,
        }

    script.make_shell(make_shell, use_ipython=True)()

elif 'shovel' in args.command:
    from web.server.application import create_app
    app = create_app()
    app.run()
Beispiel #14
0
from werkzeug import script

def __make_app():
  from gluttonee import app
  return app

def __make_shell():
  app = __make_app()

  ctx = app.test_request_context()
  ctx.push()
  app.preprocess_request()

  import flask

  return locals()

def __map_app():
  app = __make_app()
  print "Routing Map: \n"+str(app.url_map)

action_map = __map_app
action_serve = script.make_runserver(__make_app, use_reloader=True,
        use_debugger=True)
action_console = script.make_shell(__make_shell)
script.run()


Beispiel #15
0
dburi = 'sqlite:////tmp/lodgeit.db'

SECRET_KEY = 'no secret key'


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


action_runserver = script.make_runserver(
    lambda: make_app(dburi, SECRET_KEY, debug=True),
    use_reloader=True)


action_shell = script.make_shell(
    lambda: {
        'app': make_app(dburi, SECRET_KEY, False, True),
        'local': local,
        'db': db,
        'run_app': run_app
    },
    ('\nWelcome to the interactive shell environment of LodgeIt!\n'
     '\n'
     'You can use the following predefined objects: app, local, db.\n'
     'To run the application (creates a request) use *run_app*.')
)

if __name__ == '__main__':
    script.run()
Beispiel #16
0
        WSGIServer(application, "/", bindAddress=(hostname, port), debug=True).run()

    def show_tables():
        models.tsdb.showTables()

    def show_create():
        models.tsdb.showCreate()

    def db_shell():
        models.tsdb.runDBShell()

    from werkzeug import script
    import wsgiref.handlers

    script.run(
        dict(
            runserver=script.make_runserver(
                lambda: application, hostname="0.0.0.0", use_reloader=True, threaded=True, port=8888, use_debugger=True
            ),
            shell=script.make_shell(lambda: {"app": application}),
            runcgi=lambda: wsgiref.handlers.CGIHandler().run(application),
            cherrypy=run_cherrypy_server,
            runfcgi=run_fcgi,
            runscgi=run_scgi,
            dbshell=db_shell,
            show_tables=show_tables,
            show_create=show_create,
        ),
        "",
    )
Beispiel #17
0
from nms import ctx
from nms.application import run, init_ctx
from werkzeug import script


def shell_env():
    ctx = init_ctx()
    from nms.database import db
    return {
        'ctx': init_ctx(),
        'db': db,
        'nms': nms
    }

action_shell = script.make_shell(shell_env,
    ('\nWelcome to the interactive shell environment of NMS!\n'
     '\n'
     'You can use the following predefined objects: app, ctx, nms, db.\n'))


def run_app():
    try:
        run()
    except KeyboardInterrupt:
        pass
    sys.exit(0)
    print "Thanks for using!"

action_run = lambda: run_app()


if __name__ == '__main__':
Beispiel #18
0
#!/usr/local/virtualenv/huesound/bin/python

#!/usr/bin/env python

import sys
sys.path.append("../huesound")

from werkzeug import script
from huesound import config


def make_app():
    from huesound.application import HueSoundServer
    return HueSoundServer(config.PG_CONNECT)


def make_shell():
    from huesound import utils
    application = make_app()
    return locals()


action_runserver = script.make_runserver(make_app, use_reloader=True)
action_shell = script.make_shell(make_shell)

script.run()
Beispiel #19
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
    Manage i18nurls
    ~~~~~~~~~~~~~~~

    Manage the i18n url example application.

    :copyright: (c) 2009 by the Werkzeug Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
"""
import os
from i18nurls import make_app
from werkzeug import script

action_runserver = script.make_runserver(make_app)
action_shell = script.make_shell(lambda: {})

if __name__ == '__main__':
    script.run()
Beispiel #20
0
"""
Creates shell using IPython
"""
from werkzeug import script

from pybossa import model
from pybossa.core import create_app, db


def make_shell():
    return dict(app=create_app(), model=model, db_session=db.session)


if __name__ == "__main__":

    script.make_shell(make_shell, use_ipython=True)()
Beispiel #21
0
from werkzeug import script

from tongbupan import app
from models import metadata, session
import models as m
import lib.functions as f
import lib.fileserver as fs
import lib.statistics as s
import lib.events as e
import views.admin as admin
import views.feeds as updatefeeds
from models.tables import *
from scripts import *
from lib.contacts import csvfile

ctx = app.test_request_context()

def make_shell():
    return dict(globals())

def ctx_push():
    ctx.push()

def ctx_pop():
    ctx.pop()
    
    
if __name__ == "__main__":
    script.make_shell(make_shell, use_ipython=False)()
    app = Wurstgulasch(database_uri=Configuration().database_uri)
    app.__call__ = SharedDataMiddleware(
        app.__call__, {
            '/assets': './assets',
            '/static': './static'
        }
    )

    #app.__call__ = CacheMiddleware(app.__call__)
    app.__call__ = SessionMiddleware(app.__call__, type='dbm', data_dir='./sessions')

    return app

def shell_init(conf_file_location='wurstgulasch.cfg'):
    Configuration().load_from_file(conf_file_location)
    import model
    return {
        'wurstgulasch': Wurstgulasch(database_uri=Configuration().database_uri),
        'model': model
    }

if __name__ == "__main__":
    from werkzeug.serving import run_simple
    from werkzeug import script

    action_runserver = script.make_runserver(create_app, use_debugger=True, use_reloader=True)
    action_initdb = lambda: create_app().init_database()
    action_shell = script.make_shell(shell_init)

    script.run()
Beispiel #23
0
 def __call__(self, options, args):
     from werkzeug.script import make_shell
     make_shell(lambda: {'app': self.application})()
Beispiel #24
0
from werkzeug import script
from exmrss import application, db

def make_app():
    return application

def make_shell_locals():
    from sqlalchemy.orm import create_session
    app = make_app()
    return {"db_engine": app.db_engine, "sess": create_session(app.db_engine),
            "app": app, "metadata": db.metadata}

action_runserver = script.make_runserver(make_app, use_reloader=True)
action_shell = script.make_shell(make_shell_locals)

if __name__ == "__main__":
    script.run()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
    Manage web.py like application
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    A small example application that is built after the web.py tutorial.  We
    even use regular expression based dispatching.  The original code can be
    found on the `webpy.org webpage`__ in the tutorial section.

    __ http://webpy.org/tutorial2.en

    :copyright: (c) 2009 by the Werkzeug Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
"""
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), "webpylike"))
from example import app
from werkzeug import script

action_runserver = script.make_runserver(lambda: app)
action_shell = script.make_shell(lambda: {})

if __name__ == "__main__":
    script.run()
Beispiel #26
0
#!/usr/bin/env python
import os
import tempfile
from werkzeug import script

def make_app():
    from shorty.application import Shorty
    filename = os.path.join(tempfile.gettempdir(), "shorty.db")
    return Shorty('sqlite:///{0}'.format(filename))

def make_shell():
    from shorty import models, utils
    application = make_app()
    return locals()

action_runserver = script.make_runserver(make_app, use_reloader=True)
action_shell = script.make_shell(make_shell)
action_initdb = lambda: make_app().init_database()

script.run()
Beispiel #27
0
def shell():
    script.make_shell(lambda: {'app': app}, use_ipython=True)()