Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style |
| 3 | # license that can be found in the LICENSE file or at |
| 4 | # https://developers.google.com/open-source/licenses/bsd |
| 5 | |
| 6 | """Service manager to initialize all services.""" |
| 7 | from __future__ import print_function |
| 8 | from __future__ import division |
| 9 | from __future__ import absolute_import |
| 10 | |
| 11 | from features import autolink |
| 12 | from services import cachemanager_svc |
| 13 | from services import chart_svc |
| 14 | from services import config_svc |
| 15 | from services import features_svc |
| 16 | from services import issue_svc |
| 17 | from services import project_svc |
| 18 | from services import spam_svc |
| 19 | from services import star_svc |
| 20 | from services import template_svc |
| 21 | from services import user_svc |
| 22 | from services import usergroup_svc |
| 23 | |
| 24 | |
| 25 | svcs = None |
| 26 | |
| 27 | |
| 28 | class Services(object): |
| 29 | """A simple container for widely-used service objects.""" |
| 30 | |
| 31 | def __init__( |
| 32 | self, project=None, user=None, issue=None, config=None, |
| 33 | usergroup=None, cache_manager=None, autolink_obj=None, |
| 34 | user_star=None, project_star=None, issue_star=None, features=None, |
| 35 | spam=None, hotlist_star=None, chart=None, template=None): |
| 36 | # Persistence services |
| 37 | self.project = project |
| 38 | self.user = user |
| 39 | self.usergroup = usergroup |
| 40 | self.issue = issue |
| 41 | self.config = config |
| 42 | self.user_star = user_star |
| 43 | self.project_star = project_star |
| 44 | self.hotlist_star = hotlist_star |
| 45 | self.issue_star = issue_star |
| 46 | self.features = features |
| 47 | self.template = template |
| 48 | |
| 49 | # Misc. services |
| 50 | self.cache_manager = cache_manager |
| 51 | self.autolink = autolink_obj |
| 52 | self.spam = spam |
| 53 | self.chart = chart |
| 54 | |
| 55 | |
| 56 | def set_up_services(): |
| 57 | """Set up all services.""" |
| 58 | |
| 59 | global svcs |
| 60 | if svcs is None: |
| 61 | # Sorted as: cache_manager first, everything which depends on it, |
| 62 | # issue (which depends on project and config), things with no deps. |
| 63 | cache_manager = cachemanager_svc.CacheManager() |
| 64 | config = config_svc.ConfigService(cache_manager) |
| 65 | features = features_svc.FeaturesService(cache_manager, config) |
| 66 | hotlist_star = star_svc.HotlistStarService(cache_manager) |
| 67 | issue_star = star_svc.IssueStarService(cache_manager) |
| 68 | project = project_svc.ProjectService(cache_manager) |
| 69 | project_star = star_svc.ProjectStarService(cache_manager) |
| 70 | user = user_svc.UserService(cache_manager) |
| 71 | user_star = star_svc.UserStarService(cache_manager) |
| 72 | usergroup = usergroup_svc.UserGroupService(cache_manager) |
| 73 | chart = chart_svc.ChartService(config) |
| 74 | issue = issue_svc.IssueService(project, config, cache_manager, chart) |
| 75 | autolink_obj = autolink.Autolink() |
| 76 | spam = spam_svc.SpamService() |
| 77 | template = template_svc.TemplateService(cache_manager) |
| 78 | svcs = Services( |
| 79 | cache_manager=cache_manager, config=config, features=features, |
| 80 | issue_star=issue_star, project=project, project_star=project_star, |
| 81 | user=user, user_star=user_star, usergroup=usergroup, issue=issue, |
| 82 | autolink_obj=autolink_obj, spam=spam, hotlist_star=hotlist_star, |
| 83 | chart=chart, template=template) |
| 84 | return svcs |