blob: 1cb886a1a57e99efdb4ba002755e020ab6b3025d [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# 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."""
7from __future__ import print_function
8from __future__ import division
9from __future__ import absolute_import
10
11from features import autolink
12from services import cachemanager_svc
13from services import chart_svc
14from services import config_svc
15from services import features_svc
16from services import issue_svc
17from services import project_svc
18from services import spam_svc
19from services import star_svc
20from services import template_svc
21from services import user_svc
22from services import usergroup_svc
23
24
25svcs = None
26
27
28class 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
56def 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