Browse Source

Fix manage db create and runserver

Gu1 11 years ago
parent
commit
cc26ab6296
2 changed files with 16 additions and 9 deletions
  1. 2 3
      README.md
  2. 14 6
      manage.py

+ 2 - 3
README.md

@@ -8,9 +8,8 @@ ffdnispdb
 Preferably in a virtualenv, run:
 
     pip install -r requirements.txt
-    python shell.py
-    >> db.create_all()
-    python run.py
+    python manage.py db create
+    python manage.py runserver
 
 
 ## How to translate

+ 14 - 6
manage.py

@@ -7,19 +7,24 @@ import werkzeug.serving
 from werkzeug.debug import DebuggedApplication
 
 import os; os.environ.setdefault('FFDNISPDB_SETTINGS', '../settings_dev.py')
+import sys
 from flask.ext.script import (Shell, Server, Manager, Command, Option,
                               prompt, prompt_bool, prompt_pass)
 import ffdnispdb
 
 
 
-database_manager = Manager(usage=u'Perform database operations')
-
-@database_manager.command
-def create():
+class CreateDB(Command):
     "Initialize database, create tables"
-    ffdnispdb.db.create_all()
+    def handle(self, app, *args, **kwargs):
+        with app.app_context():
+            return self.run(*args, **kwargs)
 
+    def run(self):
+        ffdnispdb.db.create_all()
+
+database_manager = Manager(usage=u'Perform database operations')
+database_manager.add_command("create", CreateDB)
 
 @database_manager.command
 def drop():
@@ -50,12 +55,15 @@ def rebuild():
 class MyServer(Server):
     def handle(self, app, host, port, use_debugger, use_reloader,
                threaded, processes, passthrough_errors):
+        if os.environ.get('WERKZEUG_RUN_MAIN') != 'true':
+            print >>sys.stderr, ' * Running on http://%s:%d/'%(host, port)
+
         if use_debugger:
             app=DebuggedApplication(app, evalex=True)
 
         @werkzeug.serving.run_with_reloader
         def run():
-            ws = gevent.pywsgi.WSGIServer(('', 5000), app)
+            ws = gevent.pywsgi.WSGIServer((host, port), app)
             ws.serve_forever()