diff options
author | Roald de Vries <rdevries@thoughtworks.com> | 2016-12-05 10:32:12 +0100 |
---|---|---|
committer | Roald de Vries <rdevries@thoughtworks.com> | 2016-12-05 10:32:12 +0100 |
commit | 391cc55537a97ec8b2b55662db9c63f86ab885ef (patch) | |
tree | 3dcf6adc12efa9a84e02f9340fae925b057fcb89 | |
parent | a0de084e04f02a5f09d5a14b86ece156f4f6df5f (diff) |
get templates from pkg_resources
-rw-r--r-- | service/pixelated/adapter/welcome_mail.py | 2 | ||||
-rw-r--r-- | service/pixelated/application.py | 20 | ||||
-rw-r--r-- | service/pixelated/assets/__init__.py | 0 | ||||
-rw-r--r-- | service/pixelated/resources/inbox_resource.py | 8 | ||||
-rw-r--r-- | service/pixelated/resources/login_resource.py | 7 | ||||
-rw-r--r-- | service/pixelated/resources/root_resource.py | 6 | ||||
-rw-r--r-- | service/templates/Interstitial.html (renamed from service/pixelated/assets/Interstitial.html) | 0 | ||||
-rw-r--r-- | service/templates/Interstitial.js (renamed from service/pixelated/assets/Interstitial.js) | 0 | ||||
-rw-r--r-- | service/templates/_login_disclaimer_banner.html (renamed from service/pixelated/assets/_login_disclaimer_banner.html) | 0 | ||||
-rw-r--r-- | service/templates/favicon.png (renamed from service/pixelated/assets/favicon.png) | bin | 592 -> 592 bytes | |||
-rw-r--r-- | service/templates/hive-bg.png (renamed from service/pixelated/assets/hive-bg.png) | bin | 3356 -> 3356 bytes | |||
-rw-r--r-- | service/templates/index.html (renamed from service/pixelated/assets/index.html) | 0 | ||||
-rw-r--r-- | service/templates/jquery-2.1.3.min.js (renamed from service/pixelated/assets/jquery-2.1.3.min.js) | 0 | ||||
-rw-r--r-- | service/templates/login.html (renamed from service/pixelated/assets/login.html) | 0 | ||||
-rw-r--r-- | service/templates/normalize.min.css (renamed from service/pixelated/assets/normalize.min.css) | 0 | ||||
-rw-r--r-- | service/templates/opensans.css (renamed from service/pixelated/assets/opensans.css) | 0 | ||||
-rw-r--r-- | service/templates/pixelated-logo-orange.svg (renamed from service/pixelated/assets/pixelated-logo-orange.svg) | 0 | ||||
-rw-r--r-- | service/templates/pixelated.css (renamed from service/pixelated/assets/pixelated.css) | 0 | ||||
-rw-r--r-- | service/templates/snap.svg-min.js (renamed from service/pixelated/assets/snap.svg-min.js) | 0 | ||||
-rw-r--r-- | service/templates/welcome.mail.en-US (renamed from service/pixelated/assets/welcome.mail.en-US) | 0 | ||||
-rw-r--r-- | service/templates/welcome.mail.pt-BR (renamed from service/pixelated/assets/welcome.mail.pt-BR) | 0 | ||||
-rw-r--r-- | service/templates/welcome.mail.pt-BR.txt (renamed from service/pixelated/assets/welcome.mail.pt-BR.txt) | 0 | ||||
-rw-r--r-- | service/test/integration/test_contacts.py | 1 | ||||
-rw-r--r-- | service/test/unit/test_welcome_mail.py | 3 |
24 files changed, 21 insertions, 26 deletions
diff --git a/service/pixelated/adapter/welcome_mail.py b/service/pixelated/adapter/welcome_mail.py index 8d3cdd7a..50147990 100644 --- a/service/pixelated/adapter/welcome_mail.py +++ b/service/pixelated/adapter/welcome_mail.py @@ -20,7 +20,7 @@ from pixelated.adapter.model.mail import InputMail def add_welcome_mail(mail_store, language='en-US'): welcome_mail = pkg_resources.resource_filename( - 'pixelated.assets', + 'templates', 'welcome.mail.%s' % (language)) with open(welcome_mail) as mail_template_file: diff --git a/service/pixelated/application.py b/service/pixelated/application.py index 0c2383dd..7263482d 100644 --- a/service/pixelated/application.py +++ b/service/pixelated/application.py @@ -42,6 +42,16 @@ from pixelated.resources.root_resource import RootResource log = Logger() +def get_templates_folder(): + return os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "templates") + + +def get_static_folder(): + # TODO: make sure sandbox keeps working + # TODO: make sure this works for packaging + return os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "web-ui", "public")) + + class UserAgentMode(object): def __init__(self, is_single_user): self.is_single_user = is_single_user @@ -88,16 +98,6 @@ def _create_service_factory(args): return ServicesFactory(UserAgentMode(is_single_user=False)) -def get_templates_folder(): - return os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets") - - -def get_static_folder(): - # TODO: make sure sandbox keeps working - # TODO: make sure this works for packaging - return os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "web-ui", "public")) - - def initialize(): log.info('Starting the Pixelated user agent') args = arguments.parse_user_agent_args() diff --git a/service/pixelated/assets/__init__.py b/service/pixelated/assets/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/service/pixelated/assets/__init__.py +++ /dev/null diff --git a/service/pixelated/resources/inbox_resource.py b/service/pixelated/resources/inbox_resource.py index d9ba86a5..13d1f298 100644 --- a/service/pixelated/resources/inbox_resource.py +++ b/service/pixelated/resources/inbox_resource.py @@ -15,6 +15,7 @@ # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. import hashlib import os +import pkg_resources from string import Template import pixelated @@ -35,9 +36,8 @@ class InboxResource(BaseResource): def __init__(self, services_factory): BaseResource.__init__(self, services_factory) self._not_quite_the_templates_folder = self._get_not_quite_the_templates_folder() - self._templates_folder = self._get_templates_folder() self._html_template = open(os.path.join(self._not_quite_the_templates_folder, 'index.html')).read() - with open(os.path.join(self._templates_folder, 'Interstitial.html')) as f: + with open(pkg_resources.resource_filename('templates', 'Interstitial.html')) as f: self.interstitial = f.read() self._mode = MODE_STARTUP @@ -48,10 +48,6 @@ class InboxResource(BaseResource): path = os.path.dirname(os.path.abspath(pixelated.__file__)) return os.path.join(path, '..', '..', 'web-ui', 'public') - def _get_templates_folder(self): - path = os.path.dirname(os.path.abspath(pixelated.__file__)) - return os.path.join(path, 'assets') - def _is_starting(self): return self._mode == MODE_STARTUP diff --git a/service/pixelated/resources/login_resource.py b/service/pixelated/resources/login_resource.py index 6300efdb..2ca85af9 100644 --- a/service/pixelated/resources/login_resource.py +++ b/service/pixelated/resources/login_resource.py @@ -15,6 +15,7 @@ # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. import os +import pkg_resources from xml.sax import SAXParseException from pixelated.authentication import Authenticator @@ -71,7 +72,7 @@ def parse_accept_language(all_headers): class DisclaimerElement(Element): - loader = XMLFile(FilePath(os.path.join(_get_startup_folder(), '_login_disclaimer_banner.html'))) + loader = XMLFile(FilePath(pkg_resources.resource_filename('templates', '_login_disclaimer_banner.html'))) def __init__(self, banner): super(DisclaimerElement, self).__init__() @@ -94,7 +95,7 @@ class DisclaimerElement(Element): class LoginWebSite(Element): - loader = XMLFile(FilePath(os.path.join(_get_startup_folder(), 'login.html'))) + loader = XMLFile(FilePath(pkg_resources.resource_filename('templates', 'login.html'))) def __init__(self, error_msg=None, disclaimer_banner_file=None): super(LoginWebSite, self).__init__() @@ -132,7 +133,7 @@ class LoginResource(BaseResource): self.putChild('startup-assets', File(self._startup_folder)) self.putChild('public-assets', File(self._public_folder)) - with open(os.path.join(self._startup_folder, 'Interstitial.html')) as f: + with open(pkg_resources.resource_filename('templates', 'Interstitial.html')) as f: self.interstitial = f.read() def getChild(self, path, request): diff --git a/service/pixelated/resources/root_resource.py b/service/pixelated/resources/root_resource.py index 375f27f6..e6a25e00 100644 --- a/service/pixelated/resources/root_resource.py +++ b/service/pixelated/resources/root_resource.py @@ -15,6 +15,7 @@ # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. import json import os +import pkg_resources from pixelated.resources.users import UsersResource import pixelated @@ -50,9 +51,8 @@ class RootResource(BaseResource): self._assets_folder = self._get_assets_folder() self._startup_assets_folder = self._get_startup_folder() self._static_folder = static_folder - self._html_template = open(os.path.join(templates_folder, 'index.html')).read() self._services_factory = services_factory - with open(os.path.join(self._startup_assets_folder, 'Interstitial.html')) as f: + with open(pkg_resources.resource_filename('templates', 'Interstitial.html')) as f: self.interstitial = f.read() self._redirect_to_login_resource = Redirect('login') self._inbox_resource = InboxResource(services_factory) @@ -60,7 +60,7 @@ class RootResource(BaseResource): def _startup_mode(self): self.putChildProtected('assets', File(self._assets_folder)) - self.putChildPublic('startup-assets', File(self._startup_assets_folder)) + self.putChildPublic('startup-assets', File(pkg_resources.resource_filename('templates', '.'))) self.putChildPublic('static', File(self._static_folder)) self._mode = MODE_STARTUP logger.debug('Root in STARTUP mode. %s' % self) diff --git a/service/pixelated/assets/Interstitial.html b/service/templates/Interstitial.html index bc6cc738..bc6cc738 100644 --- a/service/pixelated/assets/Interstitial.html +++ b/service/templates/Interstitial.html diff --git a/service/pixelated/assets/Interstitial.js b/service/templates/Interstitial.js index ac5a789a..ac5a789a 100644 --- a/service/pixelated/assets/Interstitial.js +++ b/service/templates/Interstitial.js diff --git a/service/pixelated/assets/_login_disclaimer_banner.html b/service/templates/_login_disclaimer_banner.html index dfc63030..dfc63030 100644 --- a/service/pixelated/assets/_login_disclaimer_banner.html +++ b/service/templates/_login_disclaimer_banner.html diff --git a/service/pixelated/assets/favicon.png b/service/templates/favicon.png Binary files differindex e14841c7..e14841c7 100644 --- a/service/pixelated/assets/favicon.png +++ b/service/templates/favicon.png diff --git a/service/pixelated/assets/hive-bg.png b/service/templates/hive-bg.png Binary files differindex 77316967..77316967 100644 --- a/service/pixelated/assets/hive-bg.png +++ b/service/templates/hive-bg.png diff --git a/service/pixelated/assets/index.html b/service/templates/index.html index c095577e..c095577e 100644 --- a/service/pixelated/assets/index.html +++ b/service/templates/index.html diff --git a/service/pixelated/assets/jquery-2.1.3.min.js b/service/templates/jquery-2.1.3.min.js index 25714ed2..25714ed2 100644 --- a/service/pixelated/assets/jquery-2.1.3.min.js +++ b/service/templates/jquery-2.1.3.min.js diff --git a/service/pixelated/assets/login.html b/service/templates/login.html index c2f5e78e..c2f5e78e 100644 --- a/service/pixelated/assets/login.html +++ b/service/templates/login.html diff --git a/service/pixelated/assets/normalize.min.css b/service/templates/normalize.min.css index d3c7f4d5..d3c7f4d5 100644 --- a/service/pixelated/assets/normalize.min.css +++ b/service/templates/normalize.min.css diff --git a/service/pixelated/assets/opensans.css b/service/templates/opensans.css index a42f346c..a42f346c 100644 --- a/service/pixelated/assets/opensans.css +++ b/service/templates/opensans.css diff --git a/service/pixelated/assets/pixelated-logo-orange.svg b/service/templates/pixelated-logo-orange.svg index 7e0ef43d..7e0ef43d 100644 --- a/service/pixelated/assets/pixelated-logo-orange.svg +++ b/service/templates/pixelated-logo-orange.svg diff --git a/service/pixelated/assets/pixelated.css b/service/templates/pixelated.css index b3e1d16e..b3e1d16e 100644 --- a/service/pixelated/assets/pixelated.css +++ b/service/templates/pixelated.css diff --git a/service/pixelated/assets/snap.svg-min.js b/service/templates/snap.svg-min.js index ca9601ab..ca9601ab 100644 --- a/service/pixelated/assets/snap.svg-min.js +++ b/service/templates/snap.svg-min.js diff --git a/service/pixelated/assets/welcome.mail.en-US b/service/templates/welcome.mail.en-US index c8aa1359..c8aa1359 100644 --- a/service/pixelated/assets/welcome.mail.en-US +++ b/service/templates/welcome.mail.en-US diff --git a/service/pixelated/assets/welcome.mail.pt-BR b/service/templates/welcome.mail.pt-BR index 41dc846f..41dc846f 100644 --- a/service/pixelated/assets/welcome.mail.pt-BR +++ b/service/templates/welcome.mail.pt-BR diff --git a/service/pixelated/assets/welcome.mail.pt-BR.txt b/service/templates/welcome.mail.pt-BR.txt index 3a59f51d..3a59f51d 100644 --- a/service/pixelated/assets/welcome.mail.pt-BR.txt +++ b/service/templates/welcome.mail.pt-BR.txt diff --git a/service/test/integration/test_contacts.py b/service/test/integration/test_contacts.py index 946818fd..a890466f 100644 --- a/service/test/integration/test_contacts.py +++ b/service/test/integration/test_contacts.py @@ -16,7 +16,6 @@ from test.support.integration import SoledadTestBase, MailBuilder from twisted.internet import defer import json -import pkg_resources class ContactsTest(SoledadTestBase): diff --git a/service/test/unit/test_welcome_mail.py b/service/test/unit/test_welcome_mail.py index 7eb65903..42e21e8d 100644 --- a/service/test/unit/test_welcome_mail.py +++ b/service/test/unit/test_welcome_mail.py @@ -41,8 +41,7 @@ class TestWelcomeMail(unittest.TestCase): with open(os.path.join(current_path, '..', '..', - 'pixelated', - 'assets', + 'templates', 'welcome.mail.pt-BR')) as mail_template_file: mail_template = message_from_file(mail_template_file) |