Esempio n. 1
0
    def warmup(self):
        """Common warmup functionality. Loads big/slow Modules."""
        import datetime
        import jinja2

        import gaetk2.tools.http

        # http://groups.google.com/group/google-appengine-python/browse_thread/thread/efbcffa181c32f33
        datetime.datetime.strptime('2000-01-01', '%Y-%m-%d').date()
        LOGGER.debug('is_production=%s is_development=%s', is_production(),
                     is_development())
        LOGGER.debug('SERVER_SOFTWARE %r',
                     os.environ.get('SERVER_SOFTWARE', ''))
        LOGGER.debug('SERVER_NAME %r', os.environ.get('SERVER_NAME', ''))
        return repr([gaetk2.tools.http, jinja2])
Esempio n. 2
0
    def get(self):
        """Deliver robots.txt based on application version."""
        if not is_production():
            response = ('# use http://%s/\nUser-agent: *\nDisallow: /\n' %
                        google.appengine.api.app_identity.
                        get_default_version_hostname())
        else:
            try:
                # read robots.txt
                response = open('robots.txt').read().strip()
            except IOError:
                # robots.txt file not available - use somewhat simple-minded default
                response = 'User-agent: *\nDisallow: /intern\nDisallow: /admin\n'

        self.return_text(response)
Esempio n. 3
0
    def _add_jinja2env_globals(self, env):
        """Helper to provide additional Globals to Jinja2 Environment.

        This should be considered one time initialisation.

        Example::
            env.globals['bottommenuurl'] = '/admin/'
            env.globals['bottommenuaddon'] = '<i class="fa fa-area-chart"></i> Admin'
            env.globals['profiler_includes'] = gae_mini_profiler.templatetags.profiler_includes

        """
        if not gaetkconfig.APP_NAME:
            gaetkconfig.APP_NAME = get_application_id().capitalize()
        env.globals.update(
            dict(
                gaetk_production=is_production(),
                gaetk_development=is_development(),
                gaetk_release=get_release(),
                gaetk_app_name=gaetkconfig.APP_NAME,
                gaetk_sentry_dsn=gaetkconfig.SENTRY_PUBLIC_DSN,
                gaetk_gae_version=os.environ.get('CURRENT_VERSION_ID', 'dev'),
            ))
        return env
Esempio n. 4
0
 def get(self):
     """Import all Modules."""
     for fname in [
             'app-uploaded.yaml', 'lib/appengine-toolkit2/include.yaml'
     ]:
         appyaml = yaml.safe_load(open(fname))
         for handler in appyaml['handlers']:
             if 'script' not in handler:
                 continue
             mod = handler['script'].split('.')
             mod = '.'.join(mod[:-1])
             url = handler.get('url')
             if mod not in ('gaetk2.views.load_into_bigquery', ):
                 LOGGER.info('importing %s from %s', mod, url)
                 __import__(mod)
     self.return_text(
         json.dumps({
             'get_release': get_release(),
             'get_revision': get_revision(),
             'get_version': get_version(),
             'is_development': is_development(),
             'is_production': is_production(),
         }))
Esempio n. 5
0
    def add_jinja2env_globals(self, env):
        """Set variables to be used in the supplied bootstrap templates."""
        sup = super(Gaetk1Mixin, self)
        if hasattr(sup, 'add_jinja2env_globals'):
            sup.add_jinja2env_globals(env)

        env.globals['ist_produktion'] = is_production(
        )  # TODO: use `gaetk_production`
        env.globals['beta_banner'] = ''
        env.globals['release'] = get_release()
        # if not is_production():
        #     # from https://codepen.io/eode9/pen/twkKm
        #     env.globals['beta_banner'] = (
        #         '<style>.corner-ribbon{z-index: 1001; width: 200px; background: #e43; position: absolute;'
        #         'top: 25px; left: -50px; text-align: center; line-height: 50px;'
        #         'letter-spacing: 1px; color: #f0f0f0; transform: rotate(-45deg);'
        #         '-webkit-transform: rotate(-45deg); }\n'
        #         '.corner-ribbon.sticky{ position: fixed; }\n'
        #         '.corner-ribbon.shadow{ box-shadow: 0 0 3px rgba(0,0,0,.3); }\n'
        #         '.corner-ribbon.bottom-right{ top: auto; right: -50px; bottom: 25px;'
        #         'left: auto; transform: rotate(-45deg); -webkit-transform: rotate(-45deg);}\n'
        #         '.corner-ribbon.red{background: #e43;}\n'
        #         '</style><div class="corner-ribbon bottom-right sticky red shadow">Development</div>')
        return env