Commits

Waldemar Kornewald  committed b1144a6

removed deprecated common-apps dir support and fixed runserver

  • Participants
  • Parent commits e7a4df0

Comments (0)

Files changed (2)

 import os
 import sys
 
-# We allow a two-level project structure where your root folder contains
-# project-specific apps and the "common" subfolder contains common apps.
-COMMON_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
-PROJECT_DIR = os.path.dirname(COMMON_DIR)
-if os.path.basename(COMMON_DIR) == 'common-apps':
-    MAIN_DIRS = (PROJECT_DIR, COMMON_DIR)
-    print >>sys.stderr, '!!!!!!!!!!!!!!!!!!!!!!!!!!\n' \
-                        'Deprecation warning: the "common-apps" folder ' \
-                        'is deprecated. Please move all modules from ' \
-                        'there into the main project folder and remove ' \
-                        'the "common-apps" folder.\n' \
-                        '!!!!!!!!!!!!!!!!!!!!!!!!!!\n'
-else:
-    PROJECT_DIR = COMMON_DIR
-    MAIN_DIRS = (PROJECT_DIR,)
+PROJECT_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
 
 # Overrides for os.environ
-env_ext = {}
-if 'DJANGO_SETTINGS_MODULE' not in os.environ:
-    env_ext['DJANGO_SETTINGS_MODULE'] = 'settings'
+env_ext = {'DJANGO_SETTINGS_MODULE': 'settings'}
 
 def setup_env():
     """Configures app engine environment for command-line apps."""
         # may be. First look within the project for a local copy, then look for
         # where the Mac OS SDK installs it.
         paths = [os.path.join(PROJECT_DIR, '.google_appengine'),
-                 os.path.join(COMMON_DIR, '.google_appengine'),
                  '/usr/local/google_appengine',
                  '/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine']
         for path in os.environ.get('PATH', '').split(os.pathsep):
             path = r'%(PROGRAMFILES)s\Google\google_appengine' % os.environ
             paths.append(path)
         # Loop through all possible paths and look for the SDK dir.
-        SDK_PATH = None
-        for sdk_path in paths:
-            sdk_path = os.path.realpath(sdk_path)
-            if os.path.exists(sdk_path):
-                SDK_PATH = sdk_path
+        sdk_path = None
+        for path in paths:
+            path = os.path.realpath(path)
+            if os.path.exists(path):
+                sdk_path = path
                 break
-        if SDK_PATH is None:
+        if sdk_path is None:
             # The SDK could not be found in any known location.
             sys.stderr.write('The Google App Engine SDK could not be found!\n'
                              "Make sure it's accessible via your PATH "
                              "environment and called google_appengine.")
             sys.exit(1)
         # Add the SDK and the libraries within it to the system path.
-        EXTRA_PATHS = [SDK_PATH]
-        lib = os.path.join(SDK_PATH, 'lib')
+        extra_paths = [sdk_path]
+        lib = os.path.join(sdk_path, 'lib')
         # Automatically add all packages in the SDK's lib folder:
         for dir in os.listdir(lib):
             path = os.path.join(lib, dir)
             detect = (os.path.join(path, dir), os.path.join(path, 'lib', dir))
             for path in detect:
                 if os.path.isdir(path) and not dir == 'django':
-                    EXTRA_PATHS.append(os.path.dirname(path))
+                    extra_paths.append(os.path.dirname(path))
                     break
-        sys.path = EXTRA_PATHS + sys.path
+        sys.path = extra_paths + sys.path
         from google.appengine.api import apiproxy_stub_map
 
     setup_project()
         setup_threading()
     setup_logging()
 
-    # Patch Django to support loading management commands from zip files
-    from django.core import management
-    management.find_commands = find_commands
+    if not have_appserver:
+        # Patch Django to support loading management commands from zip files
+        from django.core import management
+        management.find_commands = find_commands
 
 def find_commands(management_dir):
     """
     from .utils import have_appserver, on_production_server
     if have_appserver:
         # This fixes a pwd import bug for os.path.expanduser()
-        global env_ext
         env_ext['HOME'] = PROJECT_DIR
 
     # The dev_appserver creates a sandbox which restricts access to certain
 
     os.environ.update(env_ext)
 
-    EXTRA_PATHS = list(MAIN_DIRS)
-    EXTRA_PATHS.append(os.path.dirname(PROJECT_DIR))
-    EXTRA_PATHS.append(os.path.join(os.path.dirname(__file__), 'lib'))
-
-    ZIP_PACKAGES_DIRS = tuple(os.path.join(dir, 'zip-packages')
-                              for dir in MAIN_DIRS)
+    extra_paths = [PROJECT_DIR, os.path.join(os.path.dirname(__file__), 'lib')]
+    zip_packages_dir = os.path.join(PROJECT_DIR, 'zip-packages')
 
     # We support zipped packages in the common and project folders.
-    for packages_dir in ZIP_PACKAGES_DIRS:
-        if os.path.isdir(packages_dir):
-            for zip_package in os.listdir(packages_dir):
-                EXTRA_PATHS.append(os.path.join(packages_dir, zip_package))
+    if os.path.isdir(zip_packages_dir):
+        for zip_package in os.listdir(zip_packages_dir):
+            extra_paths.append(os.path.join(zip_packages_dir, zip_package))
 
     # App Engine causes main.py to be reloaded if an exception gets raised
     # on the first request of a main.py instance, so don't call setup_project()
     # multiple times. We ensure this indirectly by checking if we've already
     # modified sys.path.
-    if len(sys.path) < len(EXTRA_PATHS) or \
-            sys.path[:len(EXTRA_PATHS)] != EXTRA_PATHS:
+    if len(sys.path) < len(extra_paths) or \
+            sys.path[:len(extra_paths)] != extra_paths:
 
-        sys.path = EXTRA_PATHS + sys.path
+        sys.path = extra_paths + sys.path

File main/main.py

-import os, sys
+import os
+import sys
 
 # Add parent folder to sys.path, so we can import boot.
 # App Engine causes main.py to be reloaded if an exception gets raised
               if k.startswith('django\.') or k == 'django']:
         del sys.modules[k]
 
-from djangoappengine.boot import setup_env
+from djangoappengine.boot import setup_env, setup_logging, env_ext
 setup_env()
 
 import django.core.handlers.wsgi
         sys.path = path_backup[:]
     except:
         path_backup = sys.path[:]
-    os.environ.update(boot.env_ext)
-    boot.setup_logging()
+    os.environ.update(env_ext)
+    setup_logging()
 
     # Create a Django application for WSGI.
     application = django.core.handlers.wsgi.WSGIHandler()