diff options
author | Bruno Wagner <bwgpro@gmail.com> | 2015-06-09 18:00:19 -0300 |
---|---|---|
committer | Bruno Wagner <bwgpro@gmail.com> | 2015-06-09 18:00:19 -0300 |
commit | 786c26b37a89b6f7afc5524dafd35242688dc13b (patch) | |
tree | 4773492dd43c5466ccb2e499844fae425774ce41 /service | |
parent | b509ff2f5faa63cca507505ede3d6708bfc4a8fa (diff) |
Extracted services setup in a separate class
We removed app factory and moved root resource
initialization to application.py
Diffstat (limited to 'service')
-rw-r--r-- | service/pixelated/application.py | 18 | ||||
-rw-r--r-- | service/pixelated/config/app_factory.py | 52 | ||||
-rw-r--r-- | service/pixelated/config/services.py | 38 | ||||
-rw-r--r-- | service/test/support/integration/app_test_client.py | 2 |
4 files changed, 53 insertions, 57 deletions
diff --git a/service/pixelated/application.py b/service/pixelated/application.py index 2ae38c73..6d83c6f7 100644 --- a/service/pixelated/application.py +++ b/service/pixelated/application.py @@ -23,16 +23,26 @@ from OpenSSL import SSL from OpenSSL import crypto from pixelated.config import arguments -from pixelated.resources import loading_page +from pixelated.config.services import Services from pixelated.config.leap import initialize_leap -from pixelated.config import logger, app_factory +from pixelated.config import logger +from pixelated.resources.loading_page import LoadingResource +from pixelated.resources.root_resource import RootResource @defer.inlineCallbacks def start_user_agent(loading_app, host, port, sslkey, sslcert, leap_home, leap_session): yield loading_app.stopListening() - resource = app_factory.init_app(leap_home, leap_session) + services = Services(leap_home, leap_session) + + resource = RootResource() + + resource.initialize( + services.keymanager, + services.search_engine, + services.mail_service, + services.draft_service) if sslkey and sslcert: reactor.listenSSL(port, Site(resource), _ssl_options(sslkey, sslcert), interface=host) @@ -62,7 +72,7 @@ def initialize(): args = arguments.parse_user_agent_args() logger.init(debug=args.debug) - loading_app = reactor.listenTCP(args.port, Site(loading_page.LoadingResource()), interface=args.host) + loading_app = reactor.listenTCP(args.port, Site(LoadingResource()), interface=args.host) deferred = deferToThread( lambda: initialize_leap( diff --git a/service/pixelated/config/app_factory.py b/service/pixelated/config/app_factory.py deleted file mode 100644 index 0a366514..00000000 --- a/service/pixelated/config/app_factory.py +++ /dev/null @@ -1,52 +0,0 @@ -# -# Copyright (c) 2014 ThoughtWorks, Inc. -# -# Pixelated is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Pixelated is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Pixelated. If not, see <http://www.gnu.org/licenses/>. - -from pixelated.resources.root_resource import RootResource -from pixelated.adapter.services.mail_service import MailService -from pixelated.adapter.model.mail import InputMail -from pixelated.adapter.services.mail_sender import MailSender -from pixelated.adapter.services.mailboxes import Mailboxes -from pixelated.adapter.soledad.soledad_querier import SoledadQuerier -from pixelated.adapter.search import SearchEngine -from pixelated.adapter.services.draft_service import DraftService -from pixelated.adapter.listeners.mailbox_indexer_listener import MailboxIndexerListener - - -def init_app(leap_home, leap_session): - keymanager = leap_session.nicknym.keymanager - - soledad_querier = SoledadQuerier(soledad=leap_session.account._soledad) - - search_engine = SearchEngine(soledad_querier, agent_home=leap_home) - pixelated_mail_sender = MailSender(leap_session.account_email(), leap_session.smtp) - - pixelated_mailboxes = Mailboxes(leap_session.account, soledad_querier, search_engine) - - pixelated_mailboxes.add_welcome_mail_for_fresh_user() - - draft_service = DraftService(pixelated_mailboxes) - mail_service = MailService(pixelated_mailboxes, pixelated_mail_sender, soledad_querier, search_engine) - soledad_querier.remove_duplicates() - search_engine.index_mails(mails=mail_service.all_mails(), - callback=soledad_querier.mark_all_as_not_recent) - - MailboxIndexerListener.SEARCH_ENGINE = search_engine - InputMail.FROM_EMAIL_ADDRESS = leap_session.account_email() - - resource = RootResource() - resource.initialize(keymanager, search_engine, mail_service, draft_service) - - return resource diff --git a/service/pixelated/config/services.py b/service/pixelated/config/services.py new file mode 100644 index 00000000..80932a94 --- /dev/null +++ b/service/pixelated/config/services.py @@ -0,0 +1,38 @@ +from pixelated.resources.root_resource import RootResource +from pixelated.adapter.services.mail_service import MailService +from pixelated.adapter.model.mail import InputMail +from pixelated.adapter.services.mail_sender import MailSender +from pixelated.adapter.services.mailboxes import Mailboxes +from pixelated.adapter.soledad.soledad_querier import SoledadQuerier +from pixelated.adapter.search import SearchEngine +from pixelated.adapter.services.draft_service import DraftService +from pixelated.adapter.listeners.mailbox_indexer_listener import MailboxIndexerListener + + +class Services(object): + + def __init__(self, leap_home, leap_session): + keymanager = leap_session.nicknym.keymanager + + soledad_querier = SoledadQuerier(soledad=leap_session.account._soledad) + + search_engine = SearchEngine(soledad_querier, agent_home=leap_home) + pixelated_mail_sender = MailSender(leap_session.account_email(), leap_session.smtp) + + pixelated_mailboxes = Mailboxes(leap_session.account, soledad_querier, search_engine) + + pixelated_mailboxes.add_welcome_mail_for_fresh_user() + + draft_service = DraftService(pixelated_mailboxes) + mail_service = MailService(pixelated_mailboxes, pixelated_mail_sender, soledad_querier, search_engine) + soledad_querier.remove_duplicates() + search_engine.index_mails(mails=mail_service.all_mails(), + callback=soledad_querier.mark_all_as_not_recent) + + MailboxIndexerListener.SEARCH_ENGINE = search_engine + InputMail.FROM_EMAIL_ADDRESS = leap_session.account_email() + + self.keymanager = keymanager + self.search_engine = search_engine + self.mail_service = mail_service + self.draft_service = draft_service diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py index a1b0c3b8..06c0fd9c 100644 --- a/service/test/support/integration/app_test_client.py +++ b/service/test/support/integration/app_test_client.py @@ -73,7 +73,7 @@ class AppTestClient(object): self.search_engine.index_mails(self.mail_service.all_mails()) self.resource = RootResource() - self.resource.initialize(self.soledad_querier, self.keymanager, self.search_engine, self.mail_service, self.draft_service) + self.resource.initialize(self.keymanager, self.search_engine, self.mail_service, self.draft_service) def _render(self, request, as_json=True): def get_str(_str): |