Exemple #1
0
def create_wsgi_app(pod, host, port, debug=False):
    podserver_app = PodServer(pod, host, port, debug=debug)
    assets_path = os.path.join(utils.get_grow_dir(), 'ui', 'admin', 'assets')
    ui_path = os.path.join(utils.get_grow_dir(), 'ui', 'dist')
    return wsgi.SharedDataMiddleware(podserver_app, {
        '/_grow/ui': ui_path,
        '/_grow/assets': assets_path,
    })
Exemple #2
0
def create_wsgi_app(pod, host, port, debug=False):
    podserver_app = PodServer(pod, host, port, debug=debug)
    assets_path = os.path.join(utils.get_grow_dir(), 'ui', 'admin', 'assets')
    ui_path = os.path.join(utils.get_grow_dir(), 'ui', 'dist')
    return wsgi.SharedDataMiddleware(podserver_app, {
        '/_grow/ui': ui_path,
        '/_grow/assets': assets_path,
    })
Exemple #3
0
 def render(self, params=None, inject=False):
     root = os.path.join(utils.get_grow_dir(), 'pods', 'templates')
     env = self.pod.get_jinja_env(root=root)
     template = env.get_template('sitemap.xml')
     return template.render({
         'docs': self._list_docs(),
     }).strip()
Exemple #4
0
 def render(self):
   root = os.path.join(utils.get_grow_dir(), 'pods', 'templates')
   env = self.pod.create_template_env(root=root)
   template = env.get_template('sitemap.xml')
   return template.render({
       'docs': self._list_docs(),
   }).strip()
Exemple #5
0
 def render(self, params=None, inject=False):
     root = os.path.join(utils.get_grow_dir(), 'pods', 'templates')
     env = self.pod.get_jinja_env(root=root)
     template = env.get_template('sitemap.xml')
     docs = self._list_docs()
     return template.render({
         'docs': docs,
     }).strip()
Exemple #6
0
 def _compile(self):
     jar = os.path.join(utils.get_grow_dir(), 'pods', 'preprocessors',
                        'closure_lib', 'compiler.jar')
     command = ['java', '-jar', jar] + self.build_flags()
     proc = subprocess.Popen(command,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
     err = proc.stderr.read()
     if err:
         raise base.PreprocessorError(err)
     else:
         return proc.stdout.read()
Exemple #7
0
def create_jinja_env():
    root = os.path.join(utils.get_grow_dir(), 'ui', 'templates')
    loader = storage.FileStorage.JinjaLoader(root)
    return jinja2.Environment(loader=loader,
                              autoescape=True,
                              trim_blocks=True,
                              extensions=[
                                  'jinja2.ext.autoescape',
                                  'jinja2.ext.do',
                                  'jinja2.ext.i18n',
                                  'jinja2.ext.loopcontrols',
                                  'jinja2.ext.with_',
                              ])
Exemple #8
0
 def render(self, params=None, inject=False):
     root = os.path.join(utils.get_grow_dir(), 'pods', 'templates')
     env = self.pod.get_jinja_env(root=root)
     if self.template:
         content = self.pod.read_file(self.template)
         template = env.from_string(content)
     else:
         template = env.get_template('sitemap.xml')
     docs = self._list_docs()
     return template.render({
         'pod': self.pod,
         'docs': docs,
     }).strip()
Exemple #9
0
def create_jinja_env():
    root = os.path.join(utils.get_grow_dir(), 'ui', 'templates')
    loader = storage.FileStorage.JinjaLoader(root)
    return jinja2.Environment(
        loader=loader,
        autoescape=True,
        trim_blocks=True,
        extensions=[
            'jinja2.ext.autoescape',
            'jinja2.ext.do',
            'jinja2.ext.i18n',
            'jinja2.ext.loopcontrols',
            'jinja2.ext.with_',
        ])
Exemple #10
0
Fichier : ui.py Projet : rsau/grow
def create_jinja_env():
    root = os.path.join(utils.get_grow_dir(), 'ui', 'admin')
    loader = storage.FileStorage.JinjaLoader(root)
    env = jinja2.Environment(loader=loader,
                             autoescape=True,
                             trim_blocks=True,
                             extensions=[
                                 'jinja2.ext.autoescape',
                                 'jinja2.ext.do',
                                 'jinja2.ext.i18n',
                                 'jinja2.ext.loopcontrols',
                                 'jinja2.ext.with_',
                             ])
    env.filters.update(filters.create_builtin_filters())
    return env
Exemple #11
0
    def render(self, jinja_env=None):
        """Render the document using the render pool."""

        timer = self.pod.profile.timer(
            'RenderSitemapController.render',
            label='{}'.format(self.serving_path),
            meta=self.route_info.meta,
        ).start_timer()

        # Validate the path with the config filters.
        self.validate_path()

        # Need a custom root for rendering sitemap.
        root = os.path.join(utils.get_grow_dir(), 'pods', 'templates')
        jinja_env = self.pod.render_pool.custom_jinja_env(root=root)

        with jinja_env['lock']:
            if self.route_info.meta.get('template'):
                content = self.pod.read_file(self.route_info.meta['template'])
                template = jinja_env['env'].from_string(content)
            else:
                template = jinja_env['env'].get_template('sitemap.xml')

            try:
                docs = []
                locales = self.route_info.meta.get('locales')
                collections = self.route_info.meta.get('collections')
                for col in list(self.pod.list_collections(collections)):
                    docs += col.list_servable_documents(locales=locales)
                rendered_doc = rendered_document.RenderedDocument(
                    self.serving_path,
                    template.render({
                        'pod': self.pod,
                        'docs': docs,
                    }).lstrip())
                timer.stop_timer()
                return rendered_doc
            except Exception as err:
                text = 'Error building {}: {}'
                if self.pod:
                    self.pod.logger.exception(text.format(self, err))
                exception = errors.BuildError(text.format(self, err))
                exception.traceback = sys.exc_info()[2]
                exception.controller = self
                exception.exception = err
                raise exception
Exemple #12
0
    def render(self, jinja_env=None):
        """Render the document using the render pool."""
        timer = self.pod.profile.timer(
            'RenderSitemapController.render',
            label='{}'.format(self.serving_path),
            meta=self.route_info.meta,
        ).start_timer()

        # Validate the path with the config filters.
        self.validate_path()

        # Need a custom root for rendering sitemap.
        root = os.path.join(utils.get_grow_dir(), 'pods', 'templates')
        jinja_env = self.pod.render_pool.custom_jinja_env(root=root)

        with jinja_env['lock']:
            if self.route_info.meta.get('template'):
                content = self.pod.read_file(self.route_info.meta['template'])
                template = jinja_env['env'].from_string(content)
            else:
                template = jinja_env['env'].get_template('sitemap.xml')

            try:
                docs = []
                locales = self.route_info.meta.get('locales')
                collections = self.route_info.meta.get('collections')
                for col in list(self.pod.list_collections(collections)):
                    docs += col.list_servable_documents(locales=locales)
                rendered_doc = rendered_document.RenderedDocument(
                    self.serving_path, template.render({
                        'pod': self.pod,
                        'docs': docs,
                    }).lstrip())
                timer.stop_timer()
                return rendered_doc
            except Exception as err:
                text = 'Error building {}: {}'
                if self.pod:
                    self.pod.logger.exception(text.format(self, err))
                exception = errors.BuildError(text.format(self, err))
                exception.traceback = sys.exc_info()[2]
                exception.controller = self
                exception.exception = err
                raise exception
Exemple #13
0
def CreateWSGIApplication(pod=None, debug=False):
  podserver_app = WSGIApplication([
      ('/_grow/translations/(.*)', handlers.CatalogHandler),
      ('/_grow/translations', handlers.CatalogsHandler),
      ('/_grow/content', handlers.CollectionsHandler),
      ('/_grow', handlers.ConsoleHandler),
      ('/.*', handlers.PodHandler),
  ], debug=debug)
  podserver_app.registry['pod'] = pod
  api_routes = []
  api_app = service.service_mappings(
      api_routes,
      service_prefix='/_api',
      registry_path='/_api/protorpc',
      append_wsgi_apps=[podserver_app])
  static_path = os.path.join(utils.get_grow_dir(), 'server', 'frontend')
  return wsgi.SharedDataMiddleware(api_app, {
      '/_grow/static': static_path,
  })
Exemple #14
0
    def export_ui(self):
        """Builds the grow ui tools, returning a mapping of paths to content."""
        paths = []
        source_prefix = 'node_modules/'
        destination_root = '_grow/ui/'
        tools_dir = 'tools/'
        tool_prefix = 'grow-tool-'

        # Add the base ui files.
        source_root = os.path.join(utils.get_grow_dir(), 'ui', 'dist')
        for path in ['css/ui.min.css', 'js/ui.min.js']:
            source_path = os.path.join(source_root, path)
            output_path = os.sep + os.path.join(destination_root, path)
            yield rendered_document.RenderedDocument(
                output_path, self.storage.read(source_path))

        # Add the files from each of the tools.
        for tool in self.ui.get('tools', []):
            tool_path = '{}{}{}'.format(source_prefix, tool_prefix,
                                        tool['kind'])
            for root, dirs, files in self.walk(tool_path):
                for directory in dirs:
                    if directory.startswith('.'):
                        dirs.remove(directory)
                pod_dir = root.replace(self.root, '')
                for file_name in files:
                    paths.append(os.path.join(pod_dir, file_name))

        text = 'Building UI Tools: %(value)d/{} (in %(time_elapsed).9s)'
        widgets = [progressbar.FormatLabel(text.format(len(paths)))]
        progress = progressbar_non.create_progressbar("Building UI Tools...",
                                                      widgets=widgets,
                                                      max_value=len(paths))
        progress.start()
        for path in paths:
            output_path = path.replace(
                source_prefix, '{}{}'.format(destination_root, tools_dir))
            yield rendered_document.RenderedDocument(output_path,
                                                     self.read_file(path))
            progress.update(progress.value + 1)
        progress.finish()
Exemple #15
0
    def export_ui(self):
        """Builds the grow ui tools, returning a mapping of paths to content."""
        paths = []
        source_prefix = 'node_modules/'
        destination_root = '_grow/ui/'
        tools_dir = 'tools/'
        tool_prefix = 'grow-tool-'

        # Add the base ui files.
        source_root = os.path.join(utils.get_grow_dir(), 'ui', 'dist')
        for path in ['css/ui.min.css', 'js/ui.min.js']:
            source_path = os.path.join(source_root, path)
            output_path = os.sep + os.path.join(destination_root, path)
            yield rendered_document.RenderedDocument(
                output_path, self.storage.read(source_path))

        # Add the files from each of the tools.
        for tool in self.ui.get('tools', []):
            tool_path = '{}{}{}'.format(
                source_prefix, tool_prefix, tool['kind'])
            for root, dirs, files in self.walk(tool_path):
                for directory in dirs:
                    if directory.startswith('.'):
                        dirs.remove(directory)
                pod_dir = root.replace(self.root, '')
                for file_name in files:
                    paths.append(os.path.join(pod_dir, file_name))

        text = 'Building UI Tools: %(value)d/{} (in %(time_elapsed).9s)'
        widgets = [progressbar.FormatLabel(text.format(len(paths)))]
        progress = progressbar_non.create_progressbar(
            "Building UI Tools...", widgets=widgets, max_value=len(paths))
        progress.start()
        for path in paths:
            output_path = path.replace(
                source_prefix, '{}{}'.format(destination_root, tools_dir))
            yield rendered_document.RenderedDocument(
                output_path, self.read_file(path))
            progress.update(progress.value + 1)
        progress.finish()
Exemple #16
0
from grow.common import utils
from grow.pods import storage
import jinja2
import logging
import os
import webapp2
import webob
import werkzeug

_root = os.path.join(utils.get_grow_dir(), "server", "templates")
_loader = storage.FileStorage.JinjaLoader(_root)
_env = jinja2.Environment(loader=_loader, autoescape=True, trim_blocks=True, extensions=["jinja2.ext.i18n"])


class BaseHandler(webapp2.RequestHandler):
    def handle_exception(self, exception, debug):
        if debug:
            logging.exception(exception)
        else:
            logging.error(str(exception))
        template = _env.get_template("error.html")
        html = template.render({"error": {"title": str(exception)}})
        if isinstance(exception, webob.exc.HTTPException):
            self.response.set_status(exception.code)
        else:
            self.response.set_status(500)
        self.response.write(html)

    def respond_with_controller(self, controller):
        headers = controller.get_http_headers()
        self.response.headers.update(headers)
Exemple #17
0
from . import messages as deployment_messages
from boto.gs import key
from boto.s3 import connection
from gcloud import storage
from grow.common import utils
from grow.pods import env
from protorpc import messages
import boto
import cStringIO
import dns.resolver
import logging
import mimetypes
import os
import webapp2

_certs_path = os.path.join(utils.get_grow_dir(), 'deployments', 'data', 'cacerts.txt')


class TestCase(base.DestinationTestCase):

  def test_domain_cname_is_gcs(self):
    bucket_name = self.deployment.config.bucket
    CNAME = 'c.storage.googleapis.com'

    message = deployment_messages.TestResultMessage()
    message.title = 'CNAME for {} is {}'.format(bucket_name, CNAME)

    dns_resolver = dns.resolver.Resolver()
    dns_resolver.nameservers = ['8.8.8.8']  # Use Google's DNS.

    try:
Exemple #18
0
from ..pods import errors
from grow.common import utils
from grow.pods import storage
import jinja2
import logging
import os
import webapp2
import webob
import werkzeug

_root = os.path.join(utils.get_grow_dir(), 'server', 'templates')
_loader = storage.FileStorage.JinjaLoader(_root)
_env = jinja2.Environment(loader=_loader, autoescape=True, trim_blocks=True,
                          extensions=['jinja2.ext.i18n'])


class BaseHandler(webapp2.RequestHandler):

  def handle_exception(self, exception, debug):
    pod = self.app.registry['pod']
    log_func = logging.exception if debug or not pod else pod.logger.error
    if isinstance(exception, webob.exc.HTTPException):
      status = exception.status_int
      log_func('{}: {}'.format(status, self.request.path))
    else:
      status = 500
      log_func('{}: {} - {}'.format(status, self.request.path, exception))
    kwargs = {
        'exception_type': str(type(exception)),
        'exception': exception,
        'pod': pod,
Exemple #19
0
def create_wsgi_app(pod, debug=False):
    podserver_app = PodServer(pod, debug=debug)
    static_path = os.path.join(utils.get_grow_dir(), 'server', 'frontend')
    return wsgi.SharedDataMiddleware(podserver_app, {
        '/_grow/static': static_path,
    })
from . import messages as deployment_messages
from boto.gs import key
from boto.s3 import connection
from gcloud import storage
from grow.common import utils
from grow.pods import env
from protorpc import messages
import boto
import cStringIO
import dns.resolver
import logging
import mimetypes
import os
import webapp2

_certs_path = os.path.join(utils.get_grow_dir(), 'deployments', 'data', 'cacerts.txt')


class TestCase(base.DestinationTestCase):

  def test_domain_cname_is_gcs(self):
    bucket_name = self.deployment.config.bucket
    CNAME = 'c.storage.googleapis.com'

    message = deployment_messages.TestResultMessage()
    message.title = 'CNAME for {} is {}'.format(bucket_name, CNAME)

    dns_resolver = dns.resolver.Resolver()
    dns_resolver.nameservers = ['8.8.8.8']  # Use Google's DNS.

    try:
Exemple #21
0
    def render(self, jinja_env=None, request=None):
        """Render the document using the render pool."""
        timer = self.pod.profile.timer(
            'RenderSitemapController.render',
            label='{}'.format(self.serving_path),
            meta=self.route_info.meta,
        ).start_timer()

        # Validate the path with the config filters.
        self.validate_path()

        # Duplicate the routes to use the filters without messing up routing.
        temp_router = self.pod.router.__class__(self.pod)
        temp_router.add_all()

        # Sitemaps only show documents...?
        temp_router.filter('whitelist', kinds=['doc'])

        for sitemap_filter in self.route_info.meta.get('filters') or []:
            temp_router.filter(
                sitemap_filter['type'],
                collection_paths=sitemap_filter.get('collections'),
                paths=sitemap_filter.get('paths'),
                locales=sitemap_filter.get('locales'))

        # Need a custom root for rendering sitemap.
        root = os.path.join(utils.get_grow_dir(), 'pods', 'templates')
        jinja_env = self.pod.render_pool.custom_jinja_env(root=root)

        with jinja_env['lock']:
            if self.route_info.meta.get('template'):
                content = self.pod.read_file(self.route_info.meta['template'])
                template = jinja_env['env'].from_string(content)
            else:
                template = jinja_env['env'].get_template('sitemap.xml')

            try:
                docs = []
                for _, value, _ in temp_router.routes.nodes:
                    docs.append(
                        self.pod.get_doc(value.meta['pod_path'],
                                         locale=value.meta['locale']))
                rendered_doc = rendered_document.RenderedDocument(
                    self.serving_path,
                    template.render({
                        'pod': self.pod,
                        'env': self.pod.env,
                        'docs': docs,
                        'podspec': self.pod.podspec,
                    }).lstrip())
                timer.stop_timer()
                return rendered_doc
            except Exception as err:
                text = 'Error building {}: {}'
                if self.pod:
                    self.pod.logger.exception(text.format(self, err))
                exception = errors.BuildError(text.format(self, err))
                exception.traceback = sys.exc_info()[2]
                exception.controller = self
                exception.exception = err
                raise exception
Exemple #22
0
from grow.common import utils
from grow.pods import storage
import jinja2
import logging
import os
import webapp2
import webob
import werkzeug

_root = os.path.join(utils.get_grow_dir(), 'server', 'templates')
_loader = storage.FileStorage.JinjaLoader(_root)
_env = jinja2.Environment(loader=_loader,
                          autoescape=True,
                          trim_blocks=True,
                          extensions=['jinja2.ext.i18n'])


class BaseHandler(webapp2.RequestHandler):
    def handle_exception(self, exception, debug):
        if debug:
            logging.exception(exception)
        else:
            logging.error(str(exception))
        template = _env.get_template('error.html')
        html = template.render({'error': {'title': str(exception)}})
        if isinstance(exception, webob.exc.HTTPException):
            self.response.set_status(exception.code)
        else:
            self.response.set_status(500)
        self.response.write(html)