def main(environ=None, start_response=None):

	""" INCEPTION! :) """

	global run
	global rules
	
	if environ is not None and start_response is not None:
		logging.info('Running in WSGI mode... :)')
		action = run_wsgi
	else:
		action = run
	
	if config.debug:
		rules = get_rules()
		
	## Grab debug and system config
	debug = config.debug
	ndb.debug = debug
	sys_config = config.config.get('apptools.system')
	
	## Create the app, get it ready for middleware
	app = webapp2.WSGIApplication(rules, debug=debug, config=config.config)

	try:
		## If we're in debug mode, automatically activate some stuff
		if debug:
			logging.info('CORE: Jinja2 debugging enabled.')
			enable_jinja2_debugging()
			enable_filesystem_wb()

		## Consider system hooks
		if sys_config.get('hooks', False) != False:
		
			## First up - appstats (RPC tracking)
			if sys_config['hooks'].get('appstats', False) != False:
				if sys_config['hooks']['appstats']['enabled'] == True:
					logging.info('CORE: AppStats enabled.')		
					app = enable_appstats(app)
				
			## Next up - apptrace (Memory footprint tracking)
			if sys_config['hooks'].get('apptrace', False) != False:
				if sys_config['hooks']['apptrace']['enabled'] == True:
					logging.info('CORE: AppTrace enabled.')
					app = enable_apptrace(app)

			## Execution tree + CPU time tracking
			if sys_config['hooks']['profiler']['enabled'] == True:
				import cProfile
				def profile_run(app):
					logging.info('CORE: Profiling enabled.')
					enable_jinja2_debugging()
					dump_path = '/'.join(os.path.realpath(__file__).split('/')[0:-1]+['FatCatMap.profile'])
					cProfile.runctx("run(app)", globals(), locals(), filename=dump_path)
				action = profile_run ## Set our action to the profiler

	except Exception, e:
		logging.critical('CORE: CRITICAL FAILURE: Unhandled exception in main: "'+str(e)+'".')
		if config.debug:
			raise
Exemple #2
0
import bootstrap
bootstrap.AppBootstrapper.prepareImports()  # fix imports

try:
    import ndb
except ImportError, e:
    from google.appengine.ext import ndb

import config
import logging
import webapp2

from urls import get_rules

rules = get_rules()


def enable_appstats(app):

    """ Utility function that enables appstats middleware."""

    from google.appengine.ext.appstats.recording import appstats_wsgi_middleware
    app.app = appstats_wsgi_middleware(app.app)
    return app


def enable_apptrace(app):

    """ Utility function that enables apptrace middleware. """
Exemple #3
0
def enable_jinja2_debugging():
    """Enables blacklisted modules that help Jinja2 debugging."""
    if not debug:
        return
    from google.appengine.tools.dev_appserver import HardenedModulesHook
    HardenedModulesHook._WHITE_LIST_C_MODULES += ['_ctypes', 'gestalt']


# Corriendo en debug?
debug = os.environ.get('SERVER_SOFTWARE', '').startswith('Dev')

fullver = os.environ.get('CURRENT_VERSION_ID', '1')

config['directodueno']['app_version_id'] = fullver
config['directodueno']['app_version'] = fullver[0:fullver.rfind('.')]

# Instanciamos la aplicacion.
app = webapp2.WSGIApplication(routes=get_rules(config),
                              debug=debug,
                              config=config)
enable_jinja2_debugging()


def main():
    app.run()


if __name__ == '__main__':
    main()
Exemple #4
0
import webapp2

from config import config
from urls import get_rules

def enable_jinja2_debugging():
    """Enables blacklisted modules that help Jinja2 debugging."""
    if not debug:
        return
    from google.appengine.tools.dev_appserver import HardenedModulesHook
    HardenedModulesHook._WHITE_LIST_C_MODULES += ['_ctypes', 'gestalt']

# Corriendo en debug?
debug = os.environ.get('SERVER_SOFTWARE', '').startswith('Dev')

fullver = os.environ.get('CURRENT_VERSION_ID', '1')

config['ultraprop']['app_version_id'] = fullver
config['ultraprop']['app_version']    = fullver[0:fullver.rfind('.')]

# Instanciamos la aplicacion.
app = webapp2.WSGIApplication(routes=get_rules(config), debug=debug, config=config)
enable_jinja2_debugging()

def main():
    app.run()

if __name__ == '__main__':
    main()
Exemple #5
0
def main(environ=None, start_response=None):
    """ INCEPTION! :) """

    global run
    global rules

    if environ is not None and start_response is not None:
        logging.info('Running in WSGI mode... :)')
        action = run_wsgi
    else:
        action = run

    if config.debug:
        rules = get_rules()

    ## Grab debug and system config
    debug = config.debug
    ndb.debug = debug
    sys_config = config.config.get('apptools.system')

    ## Create the app, get it ready for middleware
    app = webapp2.WSGIApplication(rules, debug=debug, config=config.config)

    try:
        ## If we're in debug mode, automatically activate some stuff
        if debug:
            logging.info('CORE: Jinja2 debugging enabled.')
            enable_jinja2_debugging()
            enable_filesystem_wb()

        ## Consider system hooks
        if sys_config.get('hooks', False) != False:

            ## First up - appstats (RPC tracking)
            if sys_config['hooks'].get('appstats', False) != False:
                if sys_config['hooks']['appstats']['enabled'] == True:
                    logging.info('CORE: AppStats enabled.')
                    app = enable_appstats(app)

            ## Next up - apptrace (Memory footprint tracking)
            if sys_config['hooks'].get('apptrace', False) != False:
                if sys_config['hooks']['apptrace']['enabled'] == True:
                    logging.info('CORE: AppTrace enabled.')
                    app = enable_apptrace(app)

            ## Execution tree + CPU time tracking
            if sys_config['hooks']['profiler']['enabled'] == True:
                import cProfile

                def profile_run(app):
                    logging.info('CORE: Profiling enabled.')
                    enable_jinja2_debugging()
                    dump_path = '/'.join(
                        os.path.realpath(__file__).split('/')[0:-1] +
                        ['FatCatMap.profile'])
                    cProfile.runctx("run(app)",
                                    globals(),
                                    locals(),
                                    filename=dump_path)

                action = profile_run  ## Set our action to the profiler

    except Exception, e:
        logging.critical(
            'CORE: CRITICAL FAILURE: Unhandled exception in main: "' + str(e) +
            '".')
        if config.debug:
            raise
Exemple #6
0
""" main.py - everything starts here. """

import os
import sys

import bootstrap
bootstrap.AppBootstrapper.prepareImports()

import ndb
import config
import logging
import webapp2

from urls import get_rules

rules = get_rules()


def enable_appstats(app):
    """ Utility function that enables appstats middleware."""

    from google.appengine.ext.appstats.recording import appstats_wsgi_middleware
    app.app = appstats_wsgi_middleware(app.app)
    return app


def enable_apptrace(app):
    """ Utility function that enables apptrace middleware. """

    from apptrace import middleware
    middleware.Config.URL_PATTERNS = ['^/$']
Exemple #7
0
def warm_urls():
  for rule in get_rules():
    logging.info("warm rule: %r" % rule.handler)
    import_string(rule.handler)