| 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 from the system path. | 52 # Try to import the appengine code, if it fails check for a local copy of |
| 53 # the SDK to add to the sys.path | |
| 53 try: | 54 try: |
| 54 from google.appengine.api import apiproxy_stub_map | 55 from google.appengine.api import apiproxy_stub_map |
| 55 except ImportError, e: | 56 except ImportError, e: |
| 56 # Not on the system path. Build a list of alternative paths where it may be. | 57 SDK_PATH = None |
| 57 # First look within the project for a local copy, then look for where the Mac | 58 paths = [os.path.join(PARENT_DIR, 'google_appengine'), |
| 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'] | 59 '/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. | |
| 72 SDK_PATH = None | |
| 73 for sdk_path in paths: | 60 for sdk_path in paths: |
| 74 if os.path.exists(sdk_path): | 61 if os.path.exists(sdk_path): |
| 75 SDK_PATH = sdk_path | 62 SDK_PATH = sdk_path |
| 76 break | 63 break |
| 77 if SDK_PATH is None: | 64 if SDK_PATH is None: |
| 78 # The SDK could not be found in any known location. | 65 raise |
| 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. | |
| 89 EXTRA_PATHS = [ | 66 EXTRA_PATHS = [ |
| 90 SDK_PATH, | 67 SDK_PATH, |
| 91 os.path.join(SDK_PATH, 'lib', 'django'), | 68 os.path.join(SDK_PATH, 'lib', 'django'), |
| 92 os.path.join(SDK_PATH, 'lib', 'webob'), | 69 os.path.join(SDK_PATH, 'lib', 'webob'), |
| 93 os.path.join(SDK_PATH, 'lib', 'yaml', 'lib'), | 70 os.path.join(SDK_PATH, 'lib', 'yaml', 'lib'), |
| 94 ] | 71 ] |
| 95 sys.path = EXTRA_PATHS + sys.path | 72 sys.path.extend(EXTRA_PATHS) |
| 96 from google.appengine.api import apiproxy_stub_map | 73 from google.appengine.api import apiproxy_stub_map |
| 97 | 74 |
| 98 | 75 |
| 99 # Remove the standard version of Django if a local copy has been provided. | 76 # Remove the standard version of Django if a local copy has been provided. |
| 100 if os.path.exists(os.path.join(PARENT_DIR, 'django')): | 77 if os.path.exists(os.path.join(PARENT_DIR, 'django')): |
| 101 for k in [k for k in sys.modules if k.startswith('django')]: | 78 for k in [k for k in sys.modules if k.startswith('django')]: |
| 102 del sys.modules[k] | 79 del sys.modules[k] |
| 103 | 80 |
| 104 from django import VERSION | 81 from django import VERSION |
| 105 from django.conf import settings | 82 from django.conf import settings |
| (...skipping 97 matching lines...) Show 10 above Show 10 below | |
| 203 | 180 |
| 204 | 181 |
| 205 def PatchDeserializedObjectClass(): | 182 def PatchDeserializedObjectClass(): |
| 206 """Patches the DeserializedObject class. | 183 """Patches the DeserializedObject class. |
| 207 | 184 |
| 208 The default implementation calls save directly on the django Model base | 185 The default implementation calls save directly on the django Model base |
| 209 class to avoid pre-save handlers. The model class provided by this package | 186 class to avoid pre-save handlers. The model class provided by this package |
| 210 is not derived from the Django Model class and therefore must be called | 187 is not derived from the Django Model class and therefore must be called |
| 211 directly. | 188 directly. |
| 212 | 189 |
| 213 Additionally we need to clear the internal _parent attribute as it may | 190 Only required for Django 0.97. |
| 214 contain a FakeParent class that is used to deserialize instances without | 191 """ |
| 215 needing to load the parent instance itself. See the PythonDeserializer for | 192 if VERSION < (0, 97, None): |
| 216 more details. | 193 return |
| 217 """ | |
| 218 # This can't be imported until InstallAppengineDatabaseBackend has run. | 194 # This can't be imported until InstallAppengineDatabaseBackend has run. |
| 219 from django.core.serializers import base | 195 from django.core.serializers import base |
| 220 class NewDeserializedObject(base.DeserializedObject): | 196 class NewDeserializedObject(base.DeserializedObject): |
| 221 def save(self, save_m2m=True): | 197 def save(self, save_m2m=True): |
| 222 self.object.save() | 198 self.object.save() |
| 223 self.object._parent = None | |
| 224 base.DeserializedObject = NewDeserializedObject | 199 base.DeserializedObject = NewDeserializedObject |
| 225 logging.debug("Replacement DeserializedObject class installed") | 200 logging.debug("Replacement DeserializedObject class installed") |
| 226 | 201 |
| 227 def DisableModelValidation(): | 202 def DisableModelValidation(): |
| 228 """Disables Django's model validation routines. | 203 """Disables Django's model validation routines. |
| 229 | 204 |
| 230 The model validation is primarily concerned with validating foreign key | 205 The model validation is primarily concerned with validating foreign key |
| 231 references. There is no equivalent checking code for datastore References at | 206 references. There is no equivalent checking code for datastore References at |
| 232 this time. | 207 this time. |
| 233 | 208 |
| (...skipping 45 matching lines...) Show 10 above Show 10 below | |
| 279 if modname in disallowed_middleware_mods: | 254 if modname in disallowed_middleware_mods: |
| 280 # Currently only the CommonMiddleware has been ported. As other base modu les | 255 # Currently only the CommonMiddleware has been ported. As other base modu les |
| 281 # are converted, remove from the disallowed_middleware_mods tuple. | 256 # are converted, remove from the disallowed_middleware_mods tuple. |
| 282 mw_mods.remove(modname) | 257 mw_mods.remove(modname) |
| 283 logging.warn("Middleware module '%s' is not compatible. Removed!" % | 258 logging.warn("Middleware module '%s' is not compatible. Removed!" % |
| 284 modname) | 259 modname) |
| 285 setattr(settings, "MIDDLEWARE_CLASSES", tuple(mw_mods)) | 260 setattr(settings, "MIDDLEWARE_CLASSES", tuple(mw_mods)) |
| 286 | 261 |
| 287 # Remove incompatible application modules | 262 # Remove incompatible application modules |
| 288 app_mods = list(getattr(settings, "INSTALLED_APPS", ())) | 263 app_mods = list(getattr(settings, "INSTALLED_APPS", ())) |
| 289 disallowed_apps = ( | 264 allowed_apps = ("django.contrib.auth",) |
|
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',) | |
| 293 for app in app_mods[:]: | 265 for app in app_mods[:]: |
| 294 if app in disallowed_apps: | 266 if app.startswith("django.") and app not in allowed_apps: |
| 295 # TODO(mglb): Again this is probably overly broad. | 267 # TODO(mglb): Again this is probably overly broad. |
| 296 app_mods.remove(app) | 268 app_mods.remove(app) |
| 297 logging.warn("Application module '%s' is not compatible. Removed!" % app) | 269 logging.warn("Application module '%s' is not compatible. Removed!" % app) |
| 298 setattr(settings, "INSTALLED_APPS", tuple(app_mods)) | 270 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)) | |
| 299 | 281 |
| 300 | 282 |
| 301 def ModifyAvailableCommands(): | 283 def ModifyAvailableCommands(): |
| 302 """Removes incompatible commands and installs replacements where possible.""" | 284 """Removes incompatible commands and installs replacements where possible.""" |
| 303 if have_appserver: | 285 if have_appserver: |
| 304 # Commands are not used when running from an appserver. | 286 # Commands are not used when running from an appserver. |
| 305 return | 287 return |
| 306 from django.core import management | 288 from django.core import management |
| 307 if VERSION < (0, 97, None): | 289 if VERSION < (0, 97, None): |
| 308 RemoveCommands(management.DEFAULT_ACTION_MAPPING) | 290 RemoveCommands(management.DEFAULT_ACTION_MAPPING) |
| (...skipping 76 matching lines...) Show 10 above Show 10 below | |
| 385 mail.mail_managers = gmail.mail_managers | 367 mail.mail_managers = gmail.mail_managers |
| 386 | 368 |
| 387 def InstallAuthentication(): | 369 def InstallAuthentication(): |
| 388 logging.debug("Installing authentication framework") | 370 logging.debug("Installing authentication framework") |
| 389 from django.contrib.auth import models as django_models | 371 from django.contrib.auth import models as django_models |
| 390 from appengine_django.auth.models import DjangoUser | 372 from appengine_django.auth.models import DjangoUser |
| 391 django_models.User = DjangoUser | 373 django_models.User = DjangoUser |
| 392 from django.contrib.auth import middleware as django_middleware | 374 from django.contrib.auth import middleware as django_middleware |
| 393 from appengine_django.auth import middleware | 375 from appengine_django.auth import middleware |
| 394 django_middleware.AuthenticationMiddleware = middleware.AuthenticationMiddlewa re | 376 django_middleware.AuthenticationMiddleware = middleware.AuthenticationMiddlewa re |
| LEFT | RIGHT |