Commits

Gregory Haskins committed 5f5c2e6

Add support for specifying preset arguments for dev_appserver. This allows a
developer to globally enable the SQLite datastore stub, for instance, or have
other settings affect all `manage.py` commands, not just `runserver`. See the
`DEV_APPSERVER_OPTIONS` section under `DATABASES` in `settings_base.py`.

Comments (0)

Files changed (3)

         from google.appengine.tools import dev_appserver_main
         args = dev_appserver_main.DEFAULT_ARGS.copy()
         args.update(get_datastore_paths(connection.settings_dict))
+        args.update(connection.settings_dict.get('DEV_APPSERVER_OPTIONS', {}))
         log_level = logging.getLogger().getEffectiveLevel()
         logging.getLogger().setLevel(logging.WARNING)
         from google.appengine.tools import dev_appserver

management/commands/runserver.py

             help='The username to use with the SMTP server for sending email messages.'),
         make_option('--smtp_password',
             help='The password to use with the SMTP server for sending email messages.'),
+        make_option('--use_sqlite', action='store_true', default=False,
+            help='Use the new, SQLite datastore stub.'),
     )
 
     help = 'Runs a copy of the App Engine development server.'
                         '--smtp_password', settings.EMAIL_HOST_PASSWORD])
 
         # Pass the application specific datastore location to the server.
+        preset_options = {}
         for name in connections:
             connection = connections[name]
             if isinstance(connection, DatabaseWrapper):
                     arg = '--' + key
                     if arg not in args:
                         args.extend([arg, path])
+                # Get dev_appserver option presets, to be applied below
+                preset_options = connection.settings_dict.get('DEV_APPSERVER_OPTIONS', {})
                 break
 
         # Process the rest of the options here
         bool_options = ['debug', 'debug_imports', 'clear_datastore', 'require_indexes',
-                        'high_replication', 'enable_sendmail', ]
+                        'high_replication', 'enable_sendmail', 'use_sqlite',]
         for opt in bool_options:
             if options[opt] != False:
                 args.append("--%s" % opt)
             if options.get(opt, None) != None:
                 args.extend(["--%s" % opt, options[opt]])
 
+        # Fill any non-overridden options with presets from settings
+        for opt, value in preset_options.items():
+            arg = "--%s" % opt
+            if arg not in args:
+                if value and opt in bool_options:
+                    args.append(arg)
+                elif opt in str_options:
+                    args.extend([arg, value])
+                # TODO: issue warning about bogus option key(s)?
+
         # Reset logging level to INFO as dev_appserver will spew tons of debug logs
         logging.getLogger().setLevel(logging.INFO)
 
 
         # Switch to the App Engine for Business domain
         # 'DOMAIN': 'googleplex.com',
+
+        'DEV_APPSERVER_OPTIONS': {
+            # Optional parameters for development environment
+
+            # Emulate the high-replication datastore locally
+            # 'high_replication' : True,
+
+            # Use the SQLite backend for local storage (instead of default
+            # in-memory datastore). Useful for testing with larger datasets
+            # or when debugging concurrency/async issues (separate processes
+            # will share a common db state, rather than syncing on startup).
+            # 'use_sqlite': True,
+            }
     },
 }