app/main.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Mon, 09 Mar 2009 00:53:07 +0000
changeset 1772 1ba548e57ab2
parent 1015 b9d51be5104a
child 2066 1855c783934f
permissions -rw-r--r--
Set new Melange version number to 0-5-20090308 in app.yaml.template. Patch by: Pawel Solyga
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
__authors__ = [
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
  # alphabetical order by last name, please
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
  '"Augie Fackler" <durin42@gmail.com>',
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
  ]
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    22
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
import logging
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
import os
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    25
import sys
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    26
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    27
from google.appengine.ext.webapp import util
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    29
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
# Remove the standard version of Django.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    31
for k in [k for k in sys.modules if k.startswith('django')]:
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    32
  del sys.modules[k]
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    33
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    34
# Force sys.path to have our own directory first, in case we want to import
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    35
# from it. This lets us replace the built-in Django
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    36
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    37
144
53d8b8064019 Release shell script and associated changes. Set svn:ignore property on /app/django.zip file and /release folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    38
sys.path.insert(0, os.path.abspath('django.zip'))
53d8b8064019 Release shell script and associated changes. Set svn:ignore property on /app/django.zip file and /release folder.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 54
diff changeset
    39
684
896672e44e03 Fix for randomely ocurring bug
Sverre Rabbelier <srabbelier@gmail.com>
parents: 324
diff changeset
    40
ultimate_sys_path = None
896672e44e03 Fix for randomely ocurring bug
Sverre Rabbelier <srabbelier@gmail.com>
parents: 324
diff changeset
    41
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    42
# Force Django to reload its settings.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    43
from django.conf import settings
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    44
settings._target = None
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    45
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    46
# Must set this env var before importing any part of Django
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    47
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    48
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    49
import django.core.handlers.wsgi
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    50
import django.core.signals
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    51
import django.db
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    52
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
# Log errors.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    54
def log_exception(*args, **kwds):
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    55
  logging.exception('Exception in request:')
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    56
324
05e21c089be6 Add missing import in soc/views/site/sponsor/list.py which caused exception when app was deployed and first site you visited was "List Site Sponsors". Update files according to recent django update and django backwards incompatibility (for example newforms is changed to forms).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 144
diff changeset
    57
# Log all exceptions detected by Django.
05e21c089be6 Add missing import in soc/views/site/sponsor/list.py which caused exception when app was deployed and first site you visited was "List Site Sponsors". Update files according to recent django update and django backwards incompatibility (for example newforms is changed to forms).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 144
diff changeset
    58
django.core.signals.got_request_exception.connect(log_exception)
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    59
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    60
# Unregister the rollback event handler.
324
05e21c089be6 Add missing import in soc/views/site/sponsor/list.py which caused exception when app was deployed and first site you visited was "List Site Sponsors". Update files according to recent django update and django backwards incompatibility (for example newforms is changed to forms).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 144
diff changeset
    61
django.core.signals.got_request_exception.disconnect(
05e21c089be6 Add missing import in soc/views/site/sponsor/list.py which caused exception when app was deployed and first site you visited was "List Site Sponsors". Update files according to recent django update and django backwards incompatibility (for example newforms is changed to forms).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 144
diff changeset
    62
    django.db._rollback_on_exception)
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    63
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    64
1015
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    65
def profile_main_as_html():
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    66
  """Main program for profiling. Profiling data added as HTML to the page.
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    67
  """
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    68
  import cProfile
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    69
  import pstats
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    70
  import StringIO
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    71
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    72
  prof = cProfile.Profile()
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    73
  prof = prof.runctx('real_main()', globals(), locals())
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    74
  stream = StringIO.StringIO()
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    75
  stats = pstats.Stats(prof, stream=stream)
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    76
  # stats.strip_dirs()  # Don't; too many modules are named __init__.py.
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    77
  
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    78
  # 'time', 'cumulative' or 'calls'
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    79
  stats.sort_stats('time')  
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    80
  
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    81
  # Optional arg: how many to print
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    82
  stats.print_stats() 
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    83
  # The rest is optional.
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    84
  # stats.print_callees()
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    85
  # stats.print_callers()
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    86
  print '\n<hr>'
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    87
  print '<h1>Profile data</h1>'
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    88
  print '<pre>'
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    89
  print stream.getvalue()[:1000000]
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    90
  print '</pre>'
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    91
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    92
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    93
def profile_main_as_logs():
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    94
  """Main program for profiling. Profiling data logged.
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    95
  """
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    96
  import cProfile
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    97
  import pstats
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    98
  import StringIO
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
    99
  
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   100
  prof = cProfile.Profile()
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   101
  prof = prof.runctx("real_main()", globals(), locals())
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   102
  stream = StringIO.StringIO()
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   103
  stats = pstats.Stats(prof, stream=stream)
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   104
  stats.sort_stats('time')  # Or cumulative
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   105
  stats.print_stats(80)  # 80 = how many to print
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   106
  # The rest is optional.
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   107
  # stats.print_callees()
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   108
  # stats.print_callers()
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   109
  logging.info("Profile data:\n%s", stream.getvalue())
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   110
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   111
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   112
def real_main():
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   113
  """Main program without profiling.
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   114
  """
684
896672e44e03 Fix for randomely ocurring bug
Sverre Rabbelier <srabbelier@gmail.com>
parents: 324
diff changeset
   115
  global ultimate_sys_path
896672e44e03 Fix for randomely ocurring bug
Sverre Rabbelier <srabbelier@gmail.com>
parents: 324
diff changeset
   116
  if ultimate_sys_path is None:
896672e44e03 Fix for randomely ocurring bug
Sverre Rabbelier <srabbelier@gmail.com>
parents: 324
diff changeset
   117
    ultimate_sys_path = list(sys.path)
896672e44e03 Fix for randomely ocurring bug
Sverre Rabbelier <srabbelier@gmail.com>
parents: 324
diff changeset
   118
  else:
896672e44e03 Fix for randomely ocurring bug
Sverre Rabbelier <srabbelier@gmail.com>
parents: 324
diff changeset
   119
    sys.path[:] = ultimate_sys_path
896672e44e03 Fix for randomely ocurring bug
Sverre Rabbelier <srabbelier@gmail.com>
parents: 324
diff changeset
   120
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   121
  # Create a Django application for WSGI.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   122
  application = django.core.handlers.wsgi.WSGIHandler()
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   123
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   124
  # Run the WSGI CGI handler with that application.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   125
  util.run_wsgi_app(application)
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   126
1015
b9d51be5104a Add profiling support to Melange. By assigning profile_main_as_logs or profile_main_as_html to main variable you can turn on profiling. profile_main_as_logs will log profile data to App Engine console logs, profile_main_as_html will show profile data as html at the bottom of the page. If you want to profile app on deployed app just set the profiling function and deploy it.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 684
diff changeset
   127
main = real_main
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   128
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   129
if __name__ == '__main__':
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   130
  main()