| LEFT | RIGHT |
|---|---|
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # | 2 # |
| 3 # Copyright 2008 Google Inc. | 3 # Copyright 2008 Google Inc. |
| 4 # | 4 # |
| 5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 # you may not use this file except in compliance with the License. | 6 # you may not use this file except in compliance with the License. |
| 7 # You may obtain a copy of the License at | 7 # You may obtain a copy of the License at |
| 8 # | 8 # |
| 9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 # | 10 # |
| (...skipping 31 matching lines...) Show 10 above Show 10 below | |
| 42 import os | 42 import os |
| 43 import sys | 43 import sys |
| 44 | 44 |
| 45 | 45 |
| 46 DIR_PATH = os.path.abspath(os.path.dirname(__file__)) | 46 DIR_PATH = os.path.abspath(os.path.dirname(__file__)) |
| 47 PARENT_DIR = os.path.dirname(DIR_PATH) | 47 PARENT_DIR = os.path.dirname(DIR_PATH) |
| 48 | 48 |
| 49 # Add this project to the start of sys path to enable direct imports. | 49 # Add this project to the start of sys path to enable direct imports. |
| 50 sys.path = [PARENT_DIR,] + sys.path | 50 sys.path = [PARENT_DIR,] + sys.path |
| 51 | 51 |
| 52 # Try to import the appengine code, if it fails check for a local copy of | 52 # Try to import the appengine code from the system path. |
| 53 # the SDK to add to the sys.path | |
| 54 try: | 53 try: |
| 55 from google.appengine.api import apiproxy_stub_map | 54 from google.appengine.api import apiproxy_stub_map |
| 56 except ImportError, e: | 55 except ImportError, e: |
| 56 # Not on the system path. Build a list of alternative paths where it may be. | |
| 57 # First look within the project for a local copy, then look for where the Mac | |
| 58 # OS SDK installs it. | |
| 59 paths = [os.path.join(PARENT_DIR, '.google_appengine'), | |
| 60 os.path.join(PARENT_DIR, 'google_appengine'), | |
| 61 '/usr/local/google_appengine'] | |
| 62 # Then if on windows, look for where the Windows SDK installed it. | |
| 63 try: | |
| 64 import win32api | |
| 65 ROOT_PATH = os.path.dirname(win32api.GetWindowsDirectory()) | |
| 66 paths.append(os.path.join(ROOT_PATH, 'Program Files', 'Google', | |
| 67 'google_appengine')) | |
| 68 except ImportError, e: | |
| 69 # Not windows. | |
| 70 pass | |
| 71 # Loop through all possible paths and look for the SDK dir. | |
| 57 SDK_PATH = None | 72 SDK_PATH = None |
| 58 paths = [os.path.join(PARENT_DIR, 'google_appengine'), | |
| 59 '/usr/local/google_appengine'] | |
| 60 for sdk_path in paths: | 73 for sdk_path in paths: |
| 61 if os.path.exists(sdk_path): | 74 if os.path.exists(sdk_path): |
| 62 SDK_PATH = sdk_path | 75 SDK_PATH = sdk_path |
| 63 break | 76 break |
| 64 if SDK_PATH is None: | 77 if SDK_PATH is None: |
| 65 raise | 78 # The SDK could not be found in any known location. |
| 79 sys.stderr.write("The Google App Engine SDK could not be found!\n") | |
| 80 sys.stderr.write("See README for installation instructions.\n") | |
| 81 sys.exit(1) | |
| 82 if SDK_PATH == os.path.join(PARENT_DIR, 'google_appengine'): | |
| 83 logging.warn('Loading the SDK from the \'google_appengine\' subdirectory ' | |
| 84 'is now deprecated!') | |
| 85 logging.warn('Please move the SDK to a subdirectory named ' | |
| 86 '\'.google_appengine\' instead.') | |
| 87 logging.warn('See README for further details.') | |
| 88 # Add the SDK and the libraries within it to the system path. | |
| 66 EXTRA_PATHS = [ | 89 EXTRA_PATHS = [ |
| 67 SDK_PATH, | 90 SDK_PATH, |
| 68 os.path.join(SDK_PATH, 'lib', 'django'), | 91 os.path.join(SDK_PATH, 'lib', 'django'), |
| 69 os.path.join(SDK_PATH, 'lib', 'webob'), | 92 os.path.join(SDK_PATH, 'lib', 'webob'), |
| 70 os.path.join(SDK_PATH, 'lib', 'yaml', 'lib'), | 93 os.path.join(SDK_PATH, 'lib', 'yaml', 'lib'), |
| 71 ] | 94 ] |
| 72 sys.path.extend(EXTRA_PATHS) | 95 sys.path = EXTRA_PATHS + sys.path |
| 73 from google.appengine.api import apiproxy_stub_map | 96 from google.appengine.api import apiproxy_stub_map |
| 74 | 97 |
| 75 | 98 |
| 76 # Remove the standard version of Django if a local copy has been provided. | 99 # Remove the standard version of Django if a local copy has been provided. |
| 77 if os.path.exists(os.path.join(PARENT_DIR, 'django')): | 100 if os.path.exists(os.path.join(PARENT_DIR, 'django')): |
| 78 for k in [k for k in sys.modules if k.startswith('django')]: | 101 for k in [k for k in sys.modules if k.startswith('django')]: |
| 79 del sys.modules[k] | 102 del sys.modules[k] |
| 80 | 103 |
| 81 from django import VERSION | 104 from django import VERSION |
| 82 from django.conf import settings | 105 from django.conf import settings |
| (...skipping 97 matching lines...) Show 10 above Show 10 below | |
| 180 | 203 |
| 181 | 204 |
| 182 def PatchDeserializedObjectClass(): | 205 def PatchDeserializedObjectClass(): |
| 183 """Patches the DeserializedObject class. | 206 """Patches the DeserializedObject class. |
| 184 | 207 |
| 185 The default implementation calls save directly on the django Model base | 208 The default implementation calls save directly on the django Model base |
| 186 class to avoid pre-save handlers. The model class provided by this package | 209 class to avoid pre-save handlers. The model class provided by this package |
| 187 is not derived from the Django Model class and therefore must be called | 210 is not derived from the Django Model class and therefore must be called |
| 188 directly. | 211 directly. |
| 189 | 212 |
| 190 Only required for Django 0.97. | 213 Additionally we need to clear the internal _parent attribute as it may |
| 191 """ | 214 contain a FakeParent class that is used to deserialize instances without |
| 192 if VERSION < (0, 97, None): | 215 needing to load the parent instance itself. See the PythonDeserializer for |
| 193 return | 216 more details. |
| 217 """ | |
| 194 # This can't be imported until InstallAppengineDatabaseBackend has run. | 218 # This can't be imported until InstallAppengineDatabaseBackend has run. |
| 195 from django.core.serializers import base | 219 from django.core.serializers import base |
| 196 class NewDeserializedObject(base.DeserializedObject): | 220 class NewDeserializedObject(base.DeserializedObject): |
| 197 def save(self, save_m2m=True): | 221 def save(self, save_m2m=True): |
| 198 self.object.save() | 222 self.object.save() |
| 223 self.object._parent = None | |
| 199 base.DeserializedObject = NewDeserializedObject | 224 base.DeserializedObject = NewDeserializedObject |
| 200 logging.debug("Replacement DeserializedObject class installed") | 225 logging.debug("Replacement DeserializedObject class installed") |
| 201 | 226 |
| 202 def DisableModelValidation(): | 227 def DisableModelValidation(): |
| 203 """Disables Django's model validation routines. | 228 """Disables Django's model validation routines. |
| 204 | 229 |
| 205 The model validation is primarily concerned with validating foreign key | 230 The model validation is primarily concerned with validating foreign key |
| 206 references. There is no equivalent checking code for datastore References at | 231 references. There is no equivalent checking code for datastore References at |
| 207 this time. | 232 this time. |
| 208 | 233 |
| (...skipping 45 matching lines...) Show 10 above Show 10 below | |
| 254 if modname in disallowed_middleware_mods: | 279 if modname in disallowed_middleware_mods: |
| 255 # Currently only the CommonMiddleware has been ported. As other base modu les | 280 # Currently only the CommonMiddleware has been ported. As other base modu les |
| 256 # are converted, remove from the disallowed_middleware_mods tuple. | 281 # are converted, remove from the disallowed_middleware_mods tuple. |
| 257 mw_mods.remove(modname) | 282 mw_mods.remove(modname) |
| 258 logging.warn("Middleware module '%s' is not compatible. Removed!" % | 283 logging.warn("Middleware module '%s' is not compatible. Removed!" % |
| 259 modname) | 284 modname) |
| 260 setattr(settings, "MIDDLEWARE_CLASSES", tuple(mw_mods)) | 285 setattr(settings, "MIDDLEWARE_CLASSES", tuple(mw_mods)) |
| 261 | 286 |
| 262 # Remove incompatible application modules | 287 # Remove incompatible application modules |
| 263 app_mods = list(getattr(settings, "INSTALLED_APPS", ())) | 288 app_mods = list(getattr(settings, "INSTALLED_APPS", ())) |
| 264 allowed_apps = ("django.contrib.auth",) | 289 disallowed_apps = ( |
|
mattbrown.nz
2008/05/18 11:23:43
We're using a blacklist for middleware modules, fo
aalbrecht
2008/05/18 19:17:47
On 2008/05/18 11:23:43, mattbrown.nz wrote:
> We'r
| |
| 290 'django.contrib.contenttypes', | |
| 291 'django.contrib.sessions', | |
| 292 'django.contrib.sites',) | |
| 265 for app in app_mods[:]: | 293 for app in app_mods[:]: |
| 266 if app.startswith("django.") and app not in allowed_apps: | 294 if app in disallowed_apps: |
| 267 # TODO(mglb): Again this is probably overly broad. | 295 # TODO(mglb): Again this is probably overly broad. |
| 268 app_mods.remove(app) | 296 app_mods.remove(app) |
| 269 logging.warn("Application module '%s' is not compatible. Removed!" % app) | 297 logging.warn("Application module '%s' is not compatible. Removed!" % app) |
| 270 setattr(settings, "INSTALLED_APPS", tuple(app_mods)) | 298 setattr(settings, "INSTALLED_APPS", tuple(app_mods)) |
| 271 | |
| 272 # Remove incompatible context processors. | |
| 273 bad_processors = tuple() | |
| 274 ctx_procs = list(getattr(settings, "TEMPLATE_CONTEXT_PROCESSORS", ())) | |
| 275 for proc in ctx_procs[:]: | |
| 276 if proc in bad_processors: | |
| 277 ctx_procs.remove(proc) | |
| 278 logging.warn("Template Context Processor '%s' is incompatible. Removed!" | |
| 279 % proc) | |
| 280 setattr(settings, "TEMPLATE_CONTEXT_PROCESSORS", tuple(ctx_procs)) | |
| 281 | 299 |
| 282 | 300 |
| 283 def ModifyAvailableCommands(): | 301 def ModifyAvailableCommands(): |
| 284 """Removes incompatible commands and installs replacements where possible.""" | 302 """Removes incompatible commands and installs replacements where possible.""" |
| 285 if have_appserver: | 303 if have_appserver: |
| 286 # Commands are not used when running from an appserver. | 304 # Commands are not used when running from an appserver. |
| 287 return | 305 return |
| 288 from django.core import management | 306 from django.core import management |
| 289 if VERSION < (0, 97, None): | 307 if VERSION < (0, 97, None): |
| 290 RemoveCommands(management.DEFAULT_ACTION_MAPPING) | 308 RemoveCommands(management.DEFAULT_ACTION_MAPPING) |
| (...skipping 76 matching lines...) Show 10 above Show 10 below | |
| 367 mail.mail_managers = gmail.mail_managers | 385 mail.mail_managers = gmail.mail_managers |
| 368 | 386 |
| 369 def InstallAuthentication(): | 387 def InstallAuthentication(): |
| 370 logging.debug("Installing authentication framework") | 388 logging.debug("Installing authentication framework") |
| 371 from django.contrib.auth import models as django_models | 389 from django.contrib.auth import models as django_models |
| 372 from appengine_django.auth.models import DjangoUser | 390 from appengine_django.auth.models import DjangoUser |
| 373 django_models.User = DjangoUser | 391 django_models.User = DjangoUser |
| 374 from django.contrib.auth import middleware as django_middleware | 392 from django.contrib.auth import middleware as django_middleware |
| 375 from appengine_django.auth import middleware | 393 from appengine_django.auth import middleware |
| 376 django_middleware.AuthenticationMiddleware = middleware.AuthenticationMiddlewa re | 394 django_middleware.AuthenticationMiddleware = middleware.AuthenticationMiddlewa re |
| LEFT | RIGHT |