summaryrefslogtreecommitdiff
path: root/service/pixelated/config
diff options
context:
space:
mode:
authorBruno Wagner <bwgpro@gmail.com>2015-06-09 18:00:19 -0300
committerBruno Wagner <bwgpro@gmail.com>2015-06-09 18:00:19 -0300
commit786c26b37a89b6f7afc5524dafd35242688dc13b (patch)
tree4773492dd43c5466ccb2e499844fae425774ce41 /service/pixelated/config
parentb509ff2f5faa63cca507505ede3d6708bfc4a8fa (diff)
Extracted services setup in a separate class
We removed app factory and moved root resource initialization to application.py
Diffstat (limited to 'service/pixelated/config')
-rw-r--r--service/pixelated/config/app_factory.py52
-rw-r--r--service/pixelated/config/services.py38
2 files changed, 38 insertions, 52 deletions
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