Commits

Alexander Solovyov  committed 968f740

major change: proxy everything through wsgi object now

  • Participants
  • Parent commits 150cff8

Comments (0)

Files changed (4)

File svarga/__init__.py

 from svarga.core.env import env
 from svarga.core.database import db
+from svarga.core.handler import SvargaHandler

File svarga/bootstrap/project_template/manage.py

     sys.exit(1)
 execfile(act, {'__file__': act})
 
-from svarga.core.dispatch import run
+from svarga import SvargaHandler
 from svarga.utils.imports import module_not_found
 
 try:
         sys.exit(1)
     raise
 
+app = SvargaHandler(settings)
 
 if __name__ == "__main__":
-    run(settings)
+    app.run()

File svarga/core/dispatch.py

 import logging
+import warnings
 
 from opster import dispatch
-from svarga import db
+from svarga import db, env
 from svarga.core.env import Environment
 from svarga.utils.imports import import_module
 
 
 
 def run(settings):
-    Environment.init(settings)
+    warnings.warn('Calling svarga.core.dispatch.run is deprecated, '
+                  'instantiate app = svarga.SvargaHandler(settings instead and '
+                  'use app.run()',
+                  DeprecationWarning)
+    from svarga.core.handler import SvargaHandler
+    app = SvargaHandler(settings)
+    return app.run()
 
+
+def _run():
     import svarga.core.commands
-    for app in settings.APPS:
+    for app in env.settings.APPS:
         import_module(app + '.commands', required=False)
 
     try:
         finally:
             db.close()
 
+
 def global_setup(func):
     def extract_dict(source, keys):
         dest = {}
                     logger.setLevel(level)
                     logger.addHandler(logging.StreamHandler())
 
-        # Initialize environment without request, but with optional site setting
-        Environment.create(None)
-
         return func(*args, **kwargs)
     return inner
 

File svarga/core/handler.py

 from svarga.core.env import Environment, env, local_manager
 from svarga.core.exceptions import ImproperlyConfigured
 from svarga.utils.imports import import_attribute
+from svarga.core.dispatch import _run
 
 
 def get_url_conf():
     """
     _perform = None
 
+    def __init__(self, settings):
+        Environment.init(settings)
+        self.settings = settings
+
+    def run(self):
+        # Initialize environment without request, but with optional site setting
+        Environment.create(None)
+
+        return _run()
+
     @property
     def perform(self):
         if not self._perform: