Commits

Waldemar Kornewald committed 868f212

renamed manage.py update to manage.py deploy. also fixed a small bug when retrieving no items, at all, and fixed a bug with getting a default value for fields that don't have a value

  • Participants
  • Parent commits 7f69f3d

Comments (0)

Files changed (5)

     MAIN_DIRS = (PROJECT_DIR,)
 
 # Overrides for os.environ
-env_ext = {'DJANGO_SETTINGS_MODULE': 'settings'}
+env_ext = {}
+if 'DJANGO_SETTINGS_MODULE' not in os.environ:
+    env_ext['DJANGO_SETTINGS_MODULE'] = 'settings'
 
 def setup_env():
     """Configures app engine environment for command-line apps."""

File db/compiler.py

                 results = self.get_matching_pk(pk_filters)
             else:
                 low_mark, high_mark = self.limits
-                results = query.Get(high_mark - low_mark, low_mark)
+                if high_mark > low_mark:
+                    results = query.Get(high_mark - low_mark, low_mark)
+                else:
+                    results = ()
         except Exception, e: 
             raise DatabaseError, DatabaseError(*tuple(e)), sys.exc_info()[2] 
 
             result = []
             for field in self.query.get_meta().local_fields:
                 if not field.null and entity.get(field.column,
-                        field.default) is None:
+                        field.get_default()) is None:
                     raise ValueError("Non-nullable field %s can't be None!" % field.name)
                 result.append(self.convert_value_from_db(field.db_type(
-                    connection=self.connection), entity.get(field.column, field.default)))
+                    connection=self.connection), entity.get(field.column, field.get_default())))
             yield result
 
     def has_results(self):

File main/main.py

-import os, 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
-# on the first request of a main.py instance, so don't add parent_dir multiple
-# times.
-parent_dir = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
-if parent_dir not in sys.path:
-    sys.path.insert(0, parent_dir)
-
-# Remove the standard version of Django
-for k in [k for k in sys.modules if k.startswith('django')]:
-    del sys.modules[k]
-
-from djangoappengine import boot
-boot.setup_threading()
-boot.setup_project()
-boot.setup_logging()
-
-import django.core.handlers.wsgi
-from google.appengine.ext.webapp import util
-from django.conf import settings
-
-def log_traceback(*args, **kwargs):
-    import logging
-    logging.exception('Exception in request:')
-
-from django.core import signals
-signals.got_request_exception.connect(log_traceback)
-
-def real_main():
-    # Reset path and environment variables
-    global path_backup
-    try:
-        sys.path = path_backup[:]
-    except:
-        path_backup = sys.path[:]
-    os.environ.update(boot.env_ext)
-    boot.setup_logging()
-
-    # Create a Django application for WSGI.
-    application = django.core.handlers.wsgi.WSGIHandler()
-
-    # Run the WSGI CGI handler with that application.
-    util.run_wsgi_app(application)
-
-def profile_main():
-    import logging, cProfile, pstats, random, StringIO
-    only_forced_profile = getattr(settings, 'ONLY_FORCED_PROFILE', False)
-    profile_percentage = getattr(settings, 'PROFILE_PERCENTAGE', None)
-    if (only_forced_profile and
-                'profile=forced' not in os.environ.get('QUERY_STRING')) or \
-            (not only_forced_profile and profile_percentage and
-                float(profile_percentage) / 100.0 <= random.random()):
-        return real_main()
-
-    prof = cProfile.Profile()
-    prof = prof.runctx('real_main()', globals(), locals())
-    stream = StringIO.StringIO()
-    stats = pstats.Stats(prof, stream=stream)
-    sort_by = getattr(settings, 'SORT_PROFILE_RESULTS_BY', 'time')
-    if not isinstance(sort_by, (list, tuple)):
-        sort_by = (sort_by,)
-    stats.sort_stats(*sort_by)
-
-    restrictions = []
-    profile_pattern = getattr(settings, 'PROFILE_PATTERN', None)
-    if profile_pattern:
-        restrictions.append(profile_pattern)
-    max_results = getattr(settings, 'MAX_PROFILE_RESULTS', 80)
-    if max_results and max_results != 'all':
-        restrictions.append(max_results)
-    stats.print_stats(*restrictions)
-    extra_output = getattr(settings, 'EXTRA_PROFILE_OUTPUT', None) or ()
-    if not isinstance(sort_by, (list, tuple)):
-        extra_output = (extra_output,)
-    if 'callees' in extra_output:
-        stats.print_callees()
-    if 'callers' in extra_output:
-        stats.print_callers()
-    logging.info('Profile data:\n%s', stream.getvalue())
-
-main = getattr(settings, 'ENABLE_PROFILER', False) and profile_main or real_main
-
-if __name__ == '__main__':
-    main()
+import os, 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
+# on the first request of a main.py instance, so don't add parent_dir multiple
+# times.
+parent_dir = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
+if parent_dir not in sys.path:
+    sys.path.insert(0, parent_dir)
+
+# Remove the standard version of Django
+for k in [k for k in sys.modules if k.startswith('django')]:
+    del sys.modules[k]
+
+from djangoappengine import boot
+boot.setup_threading()
+boot.setup_project()
+boot.setup_logging()
+
+import django.core.handlers.wsgi
+from google.appengine.ext.webapp import util
+from django.conf import settings
+
+def log_traceback(*args, **kwargs):
+    import logging
+    logging.exception('Exception in request:')
+
+from django.core import signals
+signals.got_request_exception.connect(log_traceback)
+
+def real_main():
+    # Reset path and environment variables
+    global path_backup
+    try:
+        sys.path = path_backup[:]
+    except:
+        path_backup = sys.path[:]
+    os.environ.update(boot.env_ext)
+    boot.setup_logging()
+
+    # Create a Django application for WSGI.
+    application = django.core.handlers.wsgi.WSGIHandler()
+
+    # Run the WSGI CGI handler with that application.
+    util.run_wsgi_app(application)
+
+def profile_main():
+    import logging, cProfile, pstats, random, StringIO
+    only_forced_profile = getattr(settings, 'ONLY_FORCED_PROFILE', False)
+    profile_percentage = getattr(settings, 'PROFILE_PERCENTAGE', None)
+    if (only_forced_profile and
+                'profile=forced' not in os.environ.get('QUERY_STRING')) or \
+            (not only_forced_profile and profile_percentage and
+                float(profile_percentage) / 100.0 <= random.random()):
+        return real_main()
+
+    prof = cProfile.Profile()
+    prof = prof.runctx('real_main()', globals(), locals())
+    stream = StringIO.StringIO()
+    stats = pstats.Stats(prof, stream=stream)
+    sort_by = getattr(settings, 'SORT_PROFILE_RESULTS_BY', 'time')
+    if not isinstance(sort_by, (list, tuple)):
+        sort_by = (sort_by,)
+    stats.sort_stats(*sort_by)
+
+    restrictions = []
+    profile_pattern = getattr(settings, 'PROFILE_PATTERN', None)
+    if profile_pattern:
+        restrictions.append(profile_pattern)
+    max_results = getattr(settings, 'MAX_PROFILE_RESULTS', 80)
+    if max_results and max_results != 'all':
+        restrictions.append(max_results)
+    stats.print_stats(*restrictions)
+    extra_output = getattr(settings, 'EXTRA_PROFILE_OUTPUT', None) or ()
+    if not isinstance(sort_by, (list, tuple)):
+        extra_output = (extra_output,)
+    if 'callees' in extra_output:
+        stats.print_callees()
+    if 'callers' in extra_output:
+        stats.print_callers()
+    logging.info('Profile data:\n%s', stream.getvalue())
+
+main = getattr(settings, 'ENABLE_PROFILER', False) and profile_main or real_main
+
+if __name__ == '__main__':
+    main()

File management/commands/deploy.py

+#!/usr/bin/python2.4
+#
+# Copyright 2008 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# CHANGED: show warning if profiler is enabled, so you don't mistakenly upload
+# with non-production settings. Also, added --nosyncdb switch.
+
+import sys
+import logging
+
+from django.core.management.base import BaseCommand
+
+def run_appcfg(argv):
+    # import this so that we run through the checks at the beginning
+    # and report the appropriate errors
+    import appcfg
+
+    # We don't really want to use that one though, it just executes this one
+    from google.appengine.tools import appcfg
+
+    # Reset the logging level to WARN as appcfg will spew tons of logs on INFO
+    logging.getLogger().setLevel(logging.WARN)
+    
+    new_args = argv[:]
+    new_args[1] = 'update'
+    new_args.append('.')
+    syncdb = True
+    if '--nosyncdb' in new_args:
+        syncdb = False
+        new_args.remove('--nosyncdb')
+    appcfg.main(new_args)
+
+    if syncdb:
+        from django.core.management import call_command
+        from django.db import connection
+        connection.setup_remote()
+        print 'Running syncdb.'
+        call_command('syncdb', remote=True, interactive=True)
+
+    from django.conf import settings
+    if getattr(settings, 'ENABLE_PROFILER', False):
+        print '--------------------------\n' \
+              'WARNING: PROFILER ENABLED!\n' \
+              '--------------------------'
+
+class Command(BaseCommand):
+    """Deploys the website to the production server.
+
+    Any additional arguments are passed directly to appcfg.py update
+    """
+    help = 'Calls appcfg.py update for the current project.'
+    args = '[any appcfg.py options]'
+
+    def run_from_argv(self, argv):
+        run_appcfg(argv)

File management/commands/update.py

-#!/usr/bin/python2.4
-#
-# Copyright 2008 Google Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#  http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-# CHANGED: show warning if profiler is enabled, so you don't mistakenly upload
-# with non-production settings. Also, added --nosyncdb switch.
-
-import sys
-import logging
-
-from django.core.management.base import BaseCommand
-
-def run_appcfg(argv):
-    # import this so that we run through the checks at the beginning
-    # and report the appropriate errors
-    import appcfg
-
-    # We don't really want to use that one though, it just executes this one
-    from google.appengine.tools import appcfg
-
-    # Reset the logging level to WARN as appcfg will spew tons of logs on INFO
-    logging.getLogger().setLevel(logging.WARN)
-    
-    # Note: if we decide to change the name of this command to something other
-    # than 'update' we will have to munge the args to replace whatever
-    # we called it with 'update'
-    new_args = argv[:]
-    new_args.append('.')
-    syncdb = True
-    if '--nosyncdb' in new_args:
-        syncdb = False
-        new_args.remove('--nosyncdb')
-    appcfg.main(new_args)
-
-    if syncdb:
-        from django.core.management import call_command
-        from django.db import connection
-        connection.setup_remote()
-        print 'Running syncdb.'
-        call_command('syncdb', remote=True, interactive=True)
-
-    from django.conf import settings
-    if getattr(settings, 'ENABLE_PROFILER', False):
-        print '--------------------------\n' \
-              'WARNING: PROFILER ENABLED!\n' \
-              '--------------------------'
-
-class Command(BaseCommand):
-    """Calls the appcfg.py's update command for the current project.
-
-    Any additional arguments are passed directly to appcfg.py.
-    """
-    help = 'Calls appcfg.py update for the current project.'
-    args = '[any appcfg.py options]'
-
-    def run_from_argv(self, argv):
-        run_appcfg(argv)