Adrià Vilanova MartÃnez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 1 | # Copyright 2016 The Chromium Authors |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | """Main program for Monorail. |
| 5 | |
| 6 | Monorail is an issue tracking tool that is based on the code.google.com |
| 7 | issue tracker, but it has been ported to Google AppEngine and Google Cloud SQL. |
| 8 | """ |
| 9 | from __future__ import print_function |
| 10 | from __future__ import division |
| 11 | from __future__ import absolute_import |
| 12 | |
| 13 | import os |
| 14 | import six |
| 15 | |
| 16 | import flask |
| 17 | import google.appengine.api |
| 18 | import google.cloud.logging |
| 19 | |
| 20 | # Fix imports before importing gae_ts_mon. |
| 21 | import import_utils |
| 22 | |
| 23 | import_utils.FixImports() |
| 24 | |
| 25 | import gae_ts_mon |
| 26 | |
| 27 | import registerpages |
| 28 | from framework import sorting |
| 29 | from redirect import redirect |
| 30 | from services import service_manager |
| 31 | |
| 32 | if os.getenv('GAE_ENV') == 'standard': |
| 33 | # If this isn't a local server, set up cloud logging. |
| 34 | client = google.cloud.logging.Client() |
| 35 | client.setup_logging() |
| 36 | |
| 37 | if six.PY3: |
| 38 | # https://github.com/GoogleCloudPlatform/appengine-python-standard/issues/70 |
| 39 | import functools |
| 40 | from google.appengine.api import memcache |
| 41 | unpickler = functools.partial(six.moves.cPickle.Unpickler, encoding='bytes') |
| 42 | memcache.setup_client(memcache.Client(unpickler=unpickler)) |
| 43 | |
| 44 | services = service_manager.set_up_services() |
| 45 | sorting.InitializeArtValues(services) |
| 46 | |
| 47 | app = flask.Flask(__name__) |
| 48 | app.wsgi_app = google.appengine.api.wrap_wsgi_app(app.wsgi_app) |
| 49 | |
| 50 | redirect_app = redirect.GenerateRedirectApp() |
| 51 | app.wsgi_app = redirect.RedirectMiddleware(app.wsgi_app, redirect_app.wsgi_app) |
| 52 | |
| 53 | registerpages.ServletRegistry().Register(services, app) |
| 54 | registerpages.RegisterEndpointsUrls(app) |
| 55 | registerpages.RegisterTeardown(app) |
| 56 | |
| 57 | gae_ts_mon.initialize_prod(app) |