Anonymous avatar Anonymous committed 94ed5e3

app-removal branch first commit

Comments (0)

Files changed (3)

examples/manage.py

 import pprint
 
-from flask import Flask, Response
-from flaskext.script import Manager, Command, Option, Shell, Server
+from flask import Flask, current_app
+from flaskext.script import Manager
 
 def create_app(config=None):
     app = Flask(__name__)
 manager = Manager(create_app)
 
 @manager.command
-def dumpconfig(app):
+def dumpconfig():
     "Dumps config"
-    pprint.pprint(app.config)
+    pprint.pprint(current_app.config)
 
 @manager.command
-def output(app, name):
+def output(name):
     "print something"
     print name
 
 @manager.command
-def outputplus(app, name, url=None):
+def outputplus(name, url=None):
     "print name and url"
     print name, url
 
 @manager.option('-n', '--name', dest='name', help="your name")
 @manager.option('-u', '--url', dest='url', help="your url")
-def optional(app, name, url):
+def optional(name, url):
     "print name and url"
     print name, url
 

flaskext/script.py

 
 import argparse
 
-from flask import Flask
+from flask import Flask, _request_ctx_stack
 
 __all__ = ["Command", "Shell", "Server", "Manager", "Option",
            "prompt", "prompt_pass", "prompt_bool", "prompt_choices"]
         
         return parser
 
-    def run(self, app):
+    def run(self):
 
         """
         Runs a command. This must be implemented by the subclass. The first
         self.use_ipython = use_ipython
 
         if make_context is None:
-            make_context = lambda app: dict(app=app)
+            make_context = lambda: dict(app=_request_ctx_stack.top.app)
 
         self.make_context = make_context
     
                        dest='no_ipython',
                        default=not(self.use_ipython)),)
 
-    def get_context(self, app):
+    def get_context(self):
         
         """
         Returns a dict of context variables added to the shell namespace.
         """
 
-        return self.make_context(app)
+        return self.make_context()
 
-    def run(self, app, no_ipython):
+    def run(self, no_ipython):
 
         """
         Runs the shell. Unless no_ipython is True or use_python is False
         then runs IPython shell if that is installed.
         """
 
-        context = self.get_context(app)
+        context = self.get_context()
         if not no_ipython:
             try:
                 import IPython
                        dest='use_reloader',
                        default=self.use_reloader))
 
-    def run(self, app, host, port, use_debugger, use_reloader):
+    def run(self, host, port, use_debugger, use_reloader):
+        app = _request_ctx_stack.top.app
         app.run(host=host,
                 port=port,
                 debug=use_debugger,
 
         # first arg is always "app" : ignore
 
-        args = args[1:]
         defaults = defaults or []
         kwargs = dict(zip(*[reversed(l) for l in (args, defaults)]))
 
         app = self.create_app(**app_namespace.__dict__)
 
         with app.test_request_context():
-            command.run(app, **command_namespace.__dict__)
-        
+            command.run(**command_namespace.__dict__)
+
     def run(self, commands=None):
         
         """
 class SimpleCommand(Command):
     "simple command"
 
-    def run(self, app):
+    def run(self):
         print "OK"
 
 
         Option("name"),
     )
 
-    def run(self, app, name):
+    def run(self, name):
         print name
 
 
                dest="name"),
     )
 
-    def run(self, app, name):
+    def run(self, name):
         print name
 
 
                    default=self.default_name),
             )
 
-    def run(self, app, name):
+    def run(self, name):
         print name
 
 
         manager = Manager(self.app)
         
         @manager.command
-        def hello(app):
+        def hello():
             print "hello"
 
         assert 'hello' in manager._commands
         manager = Manager(self.app)
         
         @manager.command
-        def hello(app, name):
+        def hello(name):
             print "hello", name
         
 
         manager = Manager(self.app)
         
         @manager.command
-        def hello(app, name='fred'):
+        def hello(name='fred'):
             "Prints your name"
             print "hello", name
 
         manager = Manager(self.app)
         
         @manager.command
-        def verify(app, verified=False):
+        def verify(verified=False):
             "Checks if verified"
             print "VERIFIED ?", "YES" if verified else "NO"
 
         manager = Manager(self.app)
         
         @manager.command
-        def hello(app, name, url=None):
+        def hello(name, url=None):
             if url:
                 print "hello", name, "from", url
             else:
         manager = Manager(self.app)
         
         @manager.option('-n', '--name', dest='name', help='Your name')
-        def hello(app, name):
+        def hello(name):
             print "hello", name
 
         assert 'hello' in manager._commands
 
         @manager.option('-n', '--name', dest='name', help='Your name')
         @manager.option('-u', '--url', dest='url', help='Your URL')
-        def hello_again(app, name, url=None):
+        def hello_again(name, url=None):
             if url:
                 print "hello", name, "from", url
             else:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.