Пример #1
0
    def _process_manifest_pass_two(self, full_name,
                                   manifest=None, plugin_path=None):
        """
        Pass two of processing the manifest data. This maps templates and
        data to API commands and links registers classes and methods as
        hooks here and there. As these things depend both on configuration
        and the URL map, this happens as a second phase.
        """
        if not manifest:
            return

        manifest_path = lambda *p: self._mf_path(manifest, *p)
        manifest_iteritems = lambda *p: self._mf_iteritems(manifest, *p)

        # Register javascript classes
        for fn in manifest.get('code', {}).get('javascript', []):
            class_name = fn.replace('/', '.').rsplit('.', 1)[0]
            # FIXME: Is this a good idea?
            if full_name.endswith('.'+class_name):
                parent, class_name = full_name.rsplit('.', 1)
            else:
                parent = full_name
            self.register_js(parent, class_name,
                             os.path.join(plugin_path, fn))

        # Register CSS files
        for fn in manifest.get('code', {}).get('css', []):
            file_name = fn.replace('/', '.').rsplit('.', 1)[0]
            self.register_css(full_name, file_name,
                              os.path.join(plugin_path, fn))

        # Register web assets
        if plugin_path:
            from mailpile.urlmap import UrlMap
            um = UrlMap(session=self.session, config=self.config)
            for url, info in manifest_iteritems('routes'):
                filename = os.path.join(plugin_path, info['file'])

                # Short-cut for static content
                if url.startswith('/static/'):
                    self.register_web_asset(full_name, url[8:], filename,
                        mimetype=info.get('mimetype', None))
                    continue

                # Finds the right command class and register asset in
                # the right place for that particular command.
                commands = []
                if (not url.startswith('/api/')) and 'api' in info:
                    url = '/api/%d%s' % (info['api'], url)
                    if url[-1] == '/':
                        url += 'as.html'
                for method in ('GET', 'POST', 'PUT', 'UPDATE', 'DELETE'):
                    try:
                        commands = um.map(None, method, url, {}, {})
                        break
                    except UsageError:
                        pass

                output = [o.get_render_mode()
                          for o in commands if hasattr(o, 'get_render_mode')]
                output = output and output[-1] or 'html'
                if commands:
                    command = commands[-1]
                    tpath = command.template_path(output.split('.')[-1],
                                                  template=output)
                    self.register_web_asset(full_name,
                                            'html/' + tpath,
                                            filename)
                else:
                    print 'FIXME: Un-routable URL in manifest %s' % url

        # Register email content/crypto hooks
        s = self
        for which, reg in (
            ('outgoing_content', s.register_outgoing_email_content_transform),
            ('outgoing_crypto', s.register_outgoing_email_crypto_transform),
            ('incoming_crypto', s.register_incoming_email_crypto_transform),
            ('incoming_content', s.register_incoming_email_content_transform)
        ):
            for item in manifest_path('email_transforms', which):
                name = '%3.3d_%s' % (int(item.get('priority', 999)), full_name)
                reg(name, self._get_class(full_name, item['class']))

        # Register search keyword extractors
        s = self
        for which, reg in (
            ('meta', s.register_meta_kw_extractor),
            ('text', s.register_text_kw_extractor),
            ('data', s.register_data_kw_extractor)
        ):
            for item in manifest_path('keyword_extractors', which):
                reg('%s.%s' % (full_name, item),
                    self._get_class(full_name, item))

        # Register contact/vcard hooks
        for which, reg in (
            ('importers', self.register_vcard_importers),
            ('exporters', self.register_contact_exporters),
            ('context', self.register_contact_context_providers)
        ):
            for item in manifest_path('contacts', which):
                reg(self._get_class(full_name, item))

        # Register periodic jobs
        def reg_job(info, spd, register):
            interval, cls = info['interval'], info['class']
            callback = self._get_class(full_name, cls)
            register('%s.%s/%s-%s' % (full_name, cls, spd, interval),
                     interval, callback)
        for info in manifest_path('periodic_jobs', 'fast'):
            reg_job(info, 'fast', self.register_fast_periodic_job)
        for info in manifest_path('periodic_jobs', 'slow'):
            reg_job(info, 'slow', self.register_slow_periodic_job)

        ucfull_name = full_name.capitalize()
        for ui_type, elems in manifest.get('user_interface', {}).iteritems():
            for hook in elems:
                if 'javascript_setup' in hook:
                    js = hook['javascript_setup']
                    if not js.startswith('Mailpile.'):
                       hook['javascript_setup'] = '%s.%s' % (ucfull_name, js)
                if 'javascript_events' in hook:
                    for event, call in hook['javascript_events'].iteritems():
                        if not call.startswith('Mailpile.'):
                            hook['javascript_events'][event] = '%s.%s' \
                                % (ucfull_name, call)
                self.register_ui_element(ui_type, **hook)
Пример #2
0
    def _process_manifest_pass_two(self, full_name,
                                   manifest=None, plugin_path=None):
        """
        Pass two of processing the manifest data. This maps templates and
        data to API commands and links registers classes and methods as
        hooks here and there. As these things depend both on configuration
        and the URL map, this happens as a second phase.
        """
        if not manifest:
            return

        manifest_path = lambda *p: self._mf_path(manifest, *p)
        manifest_iteritems = lambda *p: self._mf_iteritems(manifest, *p)

        # Register javascript classes
        for fn in manifest.get('code', {}).get('javascript', []):
            class_name = fn.replace('/', '.').rsplit('.', 1)[0]
            # FIXME: Is this a good idea?
            if full_name.endswith('.'+class_name):
                parent, class_name = full_name.rsplit('.', 1)
            else:
                parent = full_name
            self.register_js(parent, class_name,
                             os.path.join(plugin_path, fn))

        # Register CSS files
        for fn in manifest.get('code', {}).get('css', []):
            file_name = fn.replace('/', '.').rsplit('.', 1)[0]
            self.register_css(full_name, file_name,
                              os.path.join(plugin_path, fn))

        # Register web assets
        if plugin_path:
            from mailpile.urlmap import UrlMap
            um = UrlMap(session=self.session, config=self.config)
            for url, info in manifest_iteritems('routes'):
                filename = os.path.join(plugin_path, info['file'])

                # Short-cut for static content
                if url.startswith('/static/'):
                    self.register_web_asset(full_name, url[8:], filename,
                        mimetype=info.get('mimetype', None))
                    continue

                # Finds the right command class and register asset in
                # the right place for that particular command.
                commands = []
                if (not url.startswith('/api/')) and 'api' in info:
                    url = '/api/%d%s' % (info['api'], url)
                    if url[-1] == '/':
                        url += 'as.html'
                for method in ('GET', 'POST', 'PUT', 'UPDATE', 'DELETE'):
                    try:
                        commands = um.map(None, method, url, {}, {})
                        break
                    except UsageError:
                        pass

                output = [o.get_render_mode()
                          for o in commands if hasattr(o, 'get_render_mode')]
                output = output and output[-1] or 'html'
                if commands:
                    command = commands[-1]
                    tpath = command.template_path(output.split('.')[-1],
                                                  template=output)
                    self.register_web_asset(full_name,
                                            'html/' + tpath,
                                            filename)
                else:
                    print 'FIXME: Un-routable URL in manifest %s' % url

        # Register email content/crypto hooks
        s = self
        for which, reg in (
            ('outgoing_content', s.register_outgoing_email_content_transform),
            ('outgoing_crypto', s.register_outgoing_email_crypto_transform),
            ('incoming_crypto', s.register_incoming_email_crypto_transform),
            ('incoming_content', s.register_incoming_email_content_transform)
        ):
            for item in manifest_path('email_transforms', which):
                name = '%3.3d_%s' % (int(item.get('priority', 999)), full_name)
                reg(name, self._get_class(full_name, item['class']))

        # Register search keyword extractors
        s = self
        for which, reg in (
            ('meta', s.register_meta_kw_extractor),
            ('text', s.register_text_kw_extractor),
            ('data', s.register_data_kw_extractor)
        ):
            for item in manifest_path('keyword_extractors', which):
                reg('%s.%s' % (full_name, item),
                    self._get_class(full_name, item))

        # Register contact/vcard hooks
        for which, reg in (
            ('importers', self.register_vcard_importers),
            ('exporters', self.register_contact_exporters),
            ('context', self.register_contact_context_providers)
        ):
            for item in manifest_path('contacts', which):
                reg(self._get_class(full_name, item))

        # Register periodic jobs
        def reg_job(info, spd, register):
            interval, cls = info['interval'], info['class']
            callback = self._get_class(full_name, cls)
            register('%s.%s/%s-%s' % (full_name, cls, spd, interval),
                     interval, callback)
        for info in manifest_path('periodic_jobs', 'fast'):
            reg_job(info, 'fast', self.register_fast_periodic_job)
        for info in manifest_path('periodic_jobs', 'slow'):
            reg_job(info, 'slow', self.register_slow_periodic_job)

        ucfull_name = full_name.capitalize()
        for ui_type, elems in manifest.get('user_interface', {}).iteritems():
            for hook in elems:
                if 'javascript_setup' in hook:
                    js = hook['javascript_setup']
                    if not js.startswith('Mailpile.'):
                       hook['javascript_setup'] = '%s.%s' % (ucfull_name, js)
                if 'javascript_events' in hook:
                    for event, call in hook['javascript_events'].iteritems():
                        if not call.startswith('Mailpile.'):
                            hook['javascript_events'][event] = '%s.%s' \
                                % (ucfull_name, call)
                self.register_ui_element(ui_type, **hook)
Пример #3
0
    def _process_manifest_pass_two(self,
                                   full_name,
                                   manifest=None,
                                   plugin_path=None):
        """
        Pass two of processing the manifest data. This maps templates and
        data to API commands and links registers classes and methods as
        hooks here and there. As these things depend both on configuration
        and the URL map, this happens as a second phase.
        """
        if not manifest:
            return

        manifest_path = lambda *p: self._mf_path(manifest, *p)
        manifest_iteritems = lambda *p: self._mf_iteritems(manifest, *p)

        # Register contact/vcard hooks
        for importer in manifest_path('contacts', 'importers'):
            self.register_vcard_importers(self._get_class(full_name, importer))
        for exporter in manifest_path('contacts', 'exporters'):
            self.register_contact_exporters(
                self._get_class(full_name, exporter))
        for context in manifest_path('contacts', 'context'):
            self.register_contact_context_providers(
                self._get_class(full_name, context))

        # Register javascript classes
        for fn in manifest.get('code', {}).get('javascript', []):
            class_name = fn.replace('/', '.').rsplit('.', 1)[0]
            self.register_js(full_name, class_name,
                             os.path.join(plugin_path, fn))

        # Register CSS files
        for fn in manifest.get('code', {}).get('css', []):
            file_name = fn.replace('/', '.').rsplit('.', 1)[0]
            self.register_css(full_name, file_name,
                              os.path.join(plugin_path, fn))

        # Register web assets
        if plugin_path:
            try:
                from mailpile.urlmap import UrlMap
                um = UrlMap(session=self.session, config=self.config)
                for url, info in manifest_iteritems('routes'):
                    filename = os.path.join(plugin_path, info['file'])

                    # Short-cut for static content
                    if url.startswith('/static/'):
                        self.register_web_asset(full_name,
                                                url[8:],
                                                filename,
                                                mimetype=info.get(
                                                    'mimetype', None))
                        continue

                    # Finds the right command class and register asset in
                    # the right place for that particular command.
                    commands = []
                    if (not url.startswith('/api/')) and 'api' in info:
                        url = '/api/%d%s' % (info['api'], url)
                        if url[-1] == '/':
                            url += 'as.html'
                    for method in ('GET', 'POST', 'PUT', 'UPDATE', 'DELETE'):
                        try:
                            commands = um.map(None, method, url, {}, {})
                            break
                        except UsageError:
                            pass

                    output = [
                        o.get_render_mode() for o in commands
                        if hasattr(o, 'get_render_mode')
                    ]
                    output = output and output[-1] or 'html'
                    if commands:
                        command = commands[-1]
                        tpath = command.template_path(output.split('.')[-1],
                                                      template=output)
                        self.register_web_asset(full_name, 'html/' + tpath,
                                                filename)
                    else:
                        print 'FIXME: Un-routable URL in manifest %s' % url
            except:
                import traceback
                traceback.print_exc()
Пример #4
0
    def _process_manifest_pass_two(self, full_name, manifest=None, plugin_path=None):
        """
        Pass two of processing the manifest data. This maps templates and
        data to API commands and links registers classes and methods as
        hooks here and there. As these things depend both on configuration
        and the URL map, this happens as a second phase.
        """
        if not manifest:
            return

        manifest_path = lambda *p: self._mf_path(manifest, *p)
        manifest_iteritems = lambda *p: self._mf_iteritems(manifest, *p)

        # Register javascript classes
        for fn in manifest.get("code", {}).get("javascript", []):
            class_name = fn.replace("/", ".").rsplit(".", 1)[0]
            # FIXME: Is this a good idea?
            if full_name.endswith("." + class_name):
                parent, class_name = full_name.rsplit(".", 1)
            else:
                parent = full_name
            self.register_js(parent, class_name, os.path.join(plugin_path, fn))

        # Register CSS files
        for fn in manifest.get("code", {}).get("css", []):
            file_name = fn.replace("/", ".").rsplit(".", 1)[0]
            self.register_css(full_name, file_name, os.path.join(plugin_path, fn))

        # Register web assets
        if plugin_path:
            from mailpile.urlmap import UrlMap

            um = UrlMap(session=self.session, config=self.config)
            for url, info in manifest_iteritems("routes"):
                filename = os.path.join(plugin_path, info["file"])

                # Short-cut for static content
                if url.startswith("/static/"):
                    self.register_web_asset(full_name, url[8:], filename, mimetype=info.get("mimetype", None))
                    continue

                # Finds the right command class and register asset in
                # the right place for that particular command.
                commands = []
                if (not url.startswith("/api/")) and "api" in info:
                    url = "/api/%d%s" % (info["api"], url)
                    if url[-1] == "/":
                        url += "as.html"
                for method in ("GET", "POST", "PUT", "UPDATE", "DELETE"):
                    try:
                        commands = um.map(None, method, url, {}, {})
                        break
                    except UsageError:
                        pass

                output = [o.get_render_mode() for o in commands if hasattr(o, "get_render_mode")]
                output = output and output[-1] or "html"
                if commands:
                    command = commands[-1]
                    tpath = command.template_path(output.split(".")[-1], template=output)
                    self.register_web_asset(full_name, "html/" + tpath, filename)
                else:
                    print "FIXME: Un-routable URL in manifest %s" % url

        # Register email content/crypto hooks
        s = self
        for which, reg in (
            ("outgoing_content", s.register_outgoing_email_content_transform),
            ("outgoing_crypto", s.register_outgoing_email_crypto_transform),
            ("incoming_crypto", s.register_incoming_email_crypto_transform),
            ("incoming_content", s.register_incoming_email_content_transform),
        ):
            for item in manifest_path("email_transforms", which):
                name = "%3.3d_%s" % (int(item.get("priority", 999)), full_name)
                reg(name, self._get_class(full_name, item["class"]))

        # Register search keyword extractors
        s = self
        for which, reg in (
            ("meta", s.register_meta_kw_extractor),
            ("text", s.register_text_kw_extractor),
            ("data", s.register_data_kw_extractor),
        ):
            for item in manifest_path("keyword_extractors", which):
                reg("%s.%s" % (full_name, item), self._get_class(full_name, item))

        # Register contact/vcard hooks
        for which, reg in (
            ("importers", self.register_vcard_importers),
            ("exporters", self.register_contact_exporters),
            ("context", self.register_contact_context_providers),
        ):
            for item in manifest_path("contacts", which):
                reg(self._get_class(full_name, item))

        # Register periodic jobs
        def reg_job(info, spd, register):
            interval, cls = info["interval"], info["class"]
            callback = self._get_class(full_name, cls)
            register("%s.%s/%s-%s" % (full_name, cls, spd, interval), interval, callback)

        for info in manifest_path("periodic_jobs", "fast"):
            reg_job(info, "fast", self.register_fast_periodic_job)
        for info in manifest_path("periodic_jobs", "slow"):
            reg_job(info, "slow", self.register_slow_periodic_job)

        ucfull_name = full_name.capitalize()
        for ui_type, elems in manifest.get("user_interface", {}).iteritems():
            for hook in elems:
                if "javascript_setup" in hook:
                    js = hook["javascript_setup"]
                    if not js.startswith("Mailpile."):
                        hook["javascript_setup"] = "%s.%s" % (ucfull_name, js)
                if "javascript_events" in hook:
                    for event, call in hook["javascript_events"].iteritems():
                        if not call.startswith("Mailpile."):
                            hook["javascript_events"][event] = "%s.%s" % (ucfull_name, call)
                self.register_ui_element(ui_type, **hook)
Пример #5
0
    def _process_manifest_pass_two(self, full_name,
                                   manifest=None, plugin_path=None):
        """
        Pass two of processing the manifest data. This maps templates and
        data to API commands and links registers classes and methods as
        hooks here and there. As these things depend both on configuration
        and the URL map, this happens as a second phase.
        """
        if not manifest:
            return

        manifest_path = lambda *p: self._mf_path(manifest, *p)
        manifest_iteritems = lambda *p: self._mf_iteritems(manifest, *p)

        # Register contact/vcard hooks
        for importer in manifest_path('contacts', 'importers'):
            self.register_vcard_importers(self._get_class(full_name, importer))
        for exporter in manifest_path('contacts', 'exporters'):
            self.register_contact_exporters(self._get_class(full_name,
                                                            exporter))
        for context in manifest_path('contacts', 'context'):
            self.register_contact_context_providers(self._get_class(full_name,
                                                                    context))

        # Register javascript classes
        for fn in manifest.get('code', {}).get('javascript', []):
            class_name = fn.replace('/', '.').rsplit('.', 1)[0]
            self.register_js(full_name, class_name,
                             os.path.join(plugin_path, fn))

        # Register CSS files
        for fn in manifest.get('code', {}).get('css', []):
            file_name = fn.replace('/', '.').rsplit('.', 1)[0]
            self.register_css(full_name, file_name,
                              os.path.join(plugin_path, fn))

        # Register web assets
        if plugin_path:
          try:
            from mailpile.urlmap import UrlMap
            um = UrlMap(session=self.session, config=self.config)
            for url, info in manifest_iteritems('routes'):
                filename = os.path.join(plugin_path, info['file'])

                # Short-cut for static content
                if url.startswith('/static/'):
                    self.register_web_asset(full_name, url[8:], filename,
                        mimetype=info.get('mimetype', None))
                    continue

                # Finds the right command class and register asset in
                # the right place for that particular command.
                commands = []
                if (not url.startswith('/api/')) and 'api' in info:
                    url = '/api/%d%s' % (info['api'], url)
                    if url[-1] == '/':
                        url += 'as.html'
                for method in ('GET', 'POST', 'PUT', 'UPDATE', 'DELETE'):
                    try:
                        commands = um.map(None, method, url, {}, {})
                        break
                    except UsageError:
                        pass

                output = [o.get_render_mode()
                          for o in commands if hasattr(o, 'get_render_mode')]
                output = output and output[-1] or 'html'
                if commands:
                    command = commands[-1]
                    tpath = command.template_path(output.split('.')[-1],
                                                  template=output)
                    self.register_web_asset(full_name,
                                            'html/' + tpath,
                                            filename)
                else:
                    print 'FIXME: Un-routable URL in manifest %s' % url
          except:
            import traceback
            traceback.print_exc()