Commits

Anonymous committed 40bd2bb

updated to the latest SDK and Django release

Comments (0)

Files changed (4)

 from djangotoolbox.db.base import NonrelDatabaseFeatures, \
     NonrelDatabaseOperations, NonrelDatabaseWrapper, NonrelDatabaseClient, \
     NonrelDatabaseValidation, NonrelDatabaseIntrospection
+from google.appengine.api.datastore import Query
 from urllib2 import HTTPError, URLError
 import logging
 import os
 import time
 
 REMOTE_API_SCRIPT = '$PYTHON_LIB/google/appengine/ext/remote_api/handler.py'
+DATASTORE_PATHS = {
+    'datastore_path': os.path.join(DATA_ROOT, 'datastore'),
+    'blobstore_path': os.path.join(DATA_ROOT, 'blobstore'),
+    'rdbms_sqlite_path': os.path.join(DATA_ROOT, 'rdbms'),
+    'prospective_search_path': os.path.join(DATA_ROOT, 'prospective-search'),
+}
 
 def auth_func():
     import getpass
     return appengine_rpc.HttpRpcServer(*args, ** kwargs)
 
 def get_datastore_paths(options):
-    """Returns a tuple with the path to the datastore and history file.
+    paths = {}
+    for key, path in DATASTORE_PATHS.items():
+        paths[key] = options.get(key, path)
+    return paths
 
-    The datastore is stored in the same location as dev_appserver uses by
-    default, but the name is altered to be unique to this project so multiple
-    Django projects can be developed on the same machine in parallel.
+def get_test_datastore_paths(options, inmemory=True):
+    paths = get_datastore_paths(options)
+    for key in paths:
+        paths[key] += '.test'
+    if inmemory:
+        for key in ('datastore_path', 'blobstore_path'):
+            paths[key] = None
+    return paths
 
-    Returns:
-      (datastore_path, history_path)
-    """
-    from google.appengine.tools import dev_appserver_main
-    datastore_path = options.get('datastore_path',
-                                 os.path.join(DATA_ROOT, 'datastore'))
-    blobstore_path = options.get('blobstore_path',
-                                 os.path.join(DATA_ROOT, 'blobstore'))
-    history_path = options.get('history_path',
-                               os.path.join(DATA_ROOT, 'history'))
-    return datastore_path, blobstore_path, history_path
-
-def get_test_datastore_paths(inmemory=True):
-    """Returns a tuple with the path to the test datastore and history file.
-
-    If inmemory is true, (None, None) is returned to request an in-memory
-    datastore. If inmemory is false the path returned will be similar to the path
-    returned by get_datastore_paths but with a different name.
-
-    Returns:
-      (datastore_path, history_path)
-    """
-    if inmemory:
-        return None, None, None
-    datastore_path, blobstore_path, history_path = get_datastore_paths()
-    datastore_path = datastore_path.replace('.datastore', '.testdatastore')
-    blobstore_path = blobstore_path.replace('.blobstore', '.testblobstore')
-    history_path = history_path.replace('.datastore', '.testdatastore')
-    return datastore_path, blobstore_path, history_path
-
-def destroy_datastore(*args):
+def destroy_datastore(paths):
     """Destroys the appengine datastore at the specified paths."""
-    for path in args:
+    for path in paths.values():
         if not path:
             continue
         try:
     pass
 
 class DatabaseIntrospection(NonrelDatabaseIntrospection):
-    pass
+    def table_names(self):
+        """Returns a list of names of all tables that exist in the database."""
+        return [kind.key().name() for kind in Query(kind='__kind__').Run()]
 
 class DatabaseWrapper(NonrelDatabaseWrapper):
     def __init__(self, *args, **kwds):
 
     def _get_paths(self):
         if self.use_test_datastore:
-            return get_test_datastore_paths(self.test_datastore_inmemory)
+            return get_test_datastore_paths(self.settings_dict, self.test_datastore_inmemory)
         else:
             return get_datastore_paths(self.settings_dict)
 
         if not have_appserver:
             from google.appengine.tools import dev_appserver_main
             args = dev_appserver_main.DEFAULT_ARGS.copy()
-            args['datastore_path'], args['blobstore_path'], args['history_path'] = self._get_paths()
+            args.update(self._get_paths())
+            log_level = logging.getLogger().getEffectiveLevel()
+            logging.getLogger().setLevel(logging.WARNING)
             from google.appengine.tools import dev_appserver
             dev_appserver.SetupStubs(appid, **args)
+            logging.getLogger().setLevel(log_level)
         # If we're supposed to set up the remote_api, do that now.
         if self.remote:
             self.setup_remote()
                 print 'Aborting'
                 exit()
         else:
-            destroy_datastore(*self._get_paths())
+            destroy_datastore(self._get_paths())
         self._setup_stubs()
     def destroy_test_db(self, *args, **kw):
         """Destroys the test datastore files."""
         from .base import destroy_datastore, get_test_datastore_paths
-        destroy_datastore(*get_test_datastore_paths())
+        destroy_datastore(get_test_datastore_paths(self.connection.settings_dict))

management/commands/runserver.py

     for name in connections:
         connection = connections[name]
         if isinstance(connection, DatabaseWrapper):
-            p = connection._get_paths()
-            if '--datastore_path' not in args:
-                args.extend(['--datastore_path', p[0]])
-            if '--blobstore_path' not in args:
-                args.extend(['--blobstore_path', p[1]])
-            if '--history_path' not in args:
-                args.extend(['--history_path', p[2]])
+            for key, path in connection._get_paths().items():
+                # XXX/TODO: Remove this when SDK 1.4.3 is released
+                if key == 'prospective_search_path':
+                    continue
+
+                arg = '--' + key
+                if arg not in args:
+                    args.extend([arg, path])
             break
 
     # Reset logging level to INFO as dev_appserver will spew tons of debug logs
     'django.core.files.uploadhandler.MemoryFileUploadHandler',
 )
 
-CACHE_BACKEND = 'memcached://?timeout=0'
+CACHES = {
+    'default': {
+        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
+        'TIMEOUT': 0,
+    }
+}
+
 SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'
 
 if not on_production_server: