Ejemplo n.º 1
0
    def render(self, request):
        log.debug('Requested path: %s', request.lookup_path)
        lookup_path = request.lookup_path.decode()
        for script_type in ('dev', 'debug', 'normal'):
            scripts = self.__scripts[script_type]['scripts']
            for pattern in scripts:
                if not lookup_path.startswith(pattern):
                    continue

                filepath = scripts[pattern]
                if isinstance(filepath, tuple):
                    filepath = filepath[0]

                path = filepath + lookup_path[len(pattern) :]

                if not os.path.isfile(path):
                    continue

                log.debug('Serving path: %s', path)
                mime_type = mimetypes.guess_type(path)
                request.setHeader(b'content-type', mime_type[0].encode())
                with open(path, 'rb') as _file:
                    data = _file.read()
                return data

        request.setResponseCode(http.NOT_FOUND)
        request.setHeader(b'content-type', b'text/html')
        template = Template(filename=rpath(os.path.join('render', '404.html')))
        return template.render()
Ejemplo n.º 2
0
    def render(self, request):
        log.debug('Requested path: %s', request.lookup_path)

        for script_type in ('dev', 'debug', 'normal'):
            scripts = self.__scripts[script_type]['scripts']
            for pattern in scripts:
                if not request.lookup_path.startswith(pattern):
                    continue

                filepath = scripts[pattern]
                if isinstance(filepath, tuple):
                    filepath = filepath[0]

                path = filepath + request.lookup_path[len(pattern):]

                if not os.path.isfile(path):
                    continue

                log.debug('Serving path: %s', path)
                mime_type = mimetypes.guess_type(path)
                request.setHeader(b'content-type', mime_type[0])
                with open(path, 'rb') as _file:
                    data = _file.read()
                return compress(data, request)

        request.setResponseCode(http.NOT_FOUND)
        request.setHeader(b'content-type', b'text/html')
        template = Template(filename=rpath(os.path.join('render', '404.html')))
        return compress(template.render(), request)
Ejemplo n.º 3
0
    def render(self, request):
        uri_true = ('true', 'yes', 'on', '1')
        uri_false = ('false', 'no', 'off', '0')

        debug_arg = None
        req_dbg_arg = request.args.get('debug', [b''])[-1].decode().lower()
        if req_dbg_arg in uri_true:
            debug_arg = True
        elif req_dbg_arg in uri_false:
            debug_arg = False

        dev_arg = request.args.get('dev',
                                   [b''])[-1].decode().lower() in uri_true
        dev_ver = 'dev' in common.get_version()

        script_type = 'normal'
        if debug_arg is not None:
            # Use debug arg to force switching to normal script type.
            script_type = 'debug' if debug_arg else 'normal'
        elif dev_arg or dev_ver:
            # Also use dev files if development version.
            script_type = 'dev'

        if not self.js.has_script_type_files(script_type):
            if not dev_ver:
                log.warning(
                    'Failed to enable WebUI "%s" mode, script files are missing!',
                    script_type,
                )
            # Fallback to checking other types in order and selecting first with
            # files available. Ordered to start with dev files lookup.
            for alt_script_type in [
                    x for x in ['dev', 'debug', 'normal'] if x != script_type
            ]:
                if self.js.has_script_type_files(alt_script_type):
                    script_type = alt_script_type
                    if not dev_ver:
                        log.warning('WebUI falling back to "%s" mode.',
                                    script_type)
                    break

        scripts = component.get('Scripts').get_scripts(script_type)
        scripts.insert(0, 'gettext.js')

        template = Template(filename=rpath('index.html'))
        request.setHeader(b'content-type', b'text/html; charset=utf-8')

        web_config = component.get('Web').get_config()
        web_config['base'] = request.base.decode()
        config = {key: web_config[key] for key in UI_CONFIG_KEYS}
        js_config = json.dumps(config)
        # Insert the values into 'index.html' and return.
        return template.render(
            scripts=scripts,
            stylesheets=self.stylesheets,
            debug=str(bool(debug_arg)).lower(),
            base=web_config['base'],
            js_config=js_config,
        )
Ejemplo n.º 4
0
    def render(self, request):
        if not hasattr(request, "render_file"):
            request.setResponseCode(http.INTERNAL_SERVER_ERROR)
            return ""

        filename = os.path.join("render", request.render_file)
        template = Template(filename=rpath(filename))
        request.setHeader("content-type", "text/html")
        request.setResponseCode(http.OK)
        return compress(template.render(), request)
Ejemplo n.º 5
0
    def render(self, request):
        if not hasattr(request, "render_file"):
            request.setResponseCode(http.INTERNAL_SERVER_ERROR)
            return ""

        filename = os.path.join("render", request.render_file)
        template = Template(filename=rpath(filename))
        request.setHeader("content-type", "text/html")
        request.setResponseCode(http.OK)
        return compress(template.render(), request)
Ejemplo n.º 6
0
    def render(self, request):
        if not hasattr(request, 'render_file'):
            request.setResponseCode(http.INTERNAL_SERVER_ERROR)
            return ''

        if request.render_file in self.template_files:
            request.setResponseCode(http.OK)
            filename = os.path.join('render', request.render_file)
        else:
            request.setResponseCode(http.NOT_FOUND)
            filename = os.path.join('render', '404.html')

        request.setHeader(b'content-type', b'text/html')
        template = Template(filename=rpath(filename))
        return compress(template.render(), request)
Ejemplo n.º 7
0
    def render(self, request):
        if not hasattr(request, 'render_file'):
            request.setResponseCode(http.INTERNAL_SERVER_ERROR)
            return ''

        if request.render_file in self.template_files:
            request.setResponseCode(http.OK)
            filename = os.path.join('render', request.render_file)
        else:
            request.setResponseCode(http.NOT_FOUND)
            filename = os.path.join('render', '404.html')

        request.setHeader(b'content-type', b'text/html')
        template = Template(filename=rpath(filename))
        return compress(template.render(), request)
Ejemplo n.º 8
0
    def render(self, request):
        uri_true = ('true', 'yes', '1')
        debug_arg = request.args.get('debug', [''])[-1] in uri_true
        dev_arg = request.args.get('dev', [''])[-1] in uri_true
        dev_ver = 'dev' in common.get_version()

        script_type = 'normal'
        if debug_arg:
            script_type = 'debug'
        # Override debug if dev arg or version.
        if dev_arg or dev_ver:
            script_type = 'dev'

        if not self.js.has_script_type_files(script_type):
            if not dev_ver:
                log.warning(
                    'Failed to enable WebUI "%s" mode, script files are missing!',
                    script_type,
                )
            # Fallback to checking other types in order and selecting first with files available.
            for alt_script_type in [
                    x for x in ['normal', 'debug', 'dev'] if x != script_type
            ]:
                if self.js.has_script_type_files(alt_script_type):
                    script_type = alt_script_type
                    if not dev_ver:
                        log.warning('WebUI falling back to "%s" mode.',
                                    script_type)
                    break

        scripts = component.get('Scripts').get_scripts(script_type)
        scripts.insert(0, 'gettext.js')

        template = Template(filename=rpath('index.html'))
        request.setHeader(b'content-type', b'text/html; charset=utf-8')

        web_config = component.get('Web').get_config()
        web_config['base'] = request.base.decode()
        config = {key: web_config[key] for key in UI_CONFIG_KEYS}
        js_config = json.dumps(config)
        # Insert the values into 'index.html' and return.
        return template.render(
            scripts=scripts,
            stylesheets=self.stylesheets,
            debug=str(debug_arg).lower(),
            base=web_config['base'],
            js_config=js_config,
        )
Ejemplo n.º 9
0
    def render(self, request):
        log.debug('Render template file: %s', request.render_file)
        if not hasattr(request, 'render_file'):
            request.setResponseCode(http.INTERNAL_SERVER_ERROR)
            return ''

        request.setHeader(b'content-type', b'text/html')

        tpl_file = request.render_file.decode()
        if tpl_file in self.template_files:
            request.setResponseCode(http.OK)
        else:
            request.setResponseCode(http.NOT_FOUND)
            tpl_file = '404.html'

        template = Template(filename=rpath(os.path.join('render', tpl_file)))
        return template.render()
Ejemplo n.º 10
0
    def render(self, request):
        log.debug('Requested path: %s', request.lookup_path)
        path = os.path.dirname(request.lookup_path).decode()

        if path in self.__paths:
            filename = os.path.basename(request.path).decode()
            for directory in self.__paths[path]:
                path = os.path.join(directory, filename)
                if os.path.isfile(path):
                    log.debug('Serving path: %s', path)
                    mime_type = mimetypes.guess_type(path)
                    request.setHeader(b'content-type', mime_type[0].encode())
                    with open(path, 'rb') as _file:
                        data = _file.read()
                    return data

        request.setResponseCode(http.NOT_FOUND)
        request.setHeader(b'content-type', b'text/html')
        template = Template(filename=rpath(os.path.join('render', '404.html')))
        return template.render()
Ejemplo n.º 11
0
    def render(self, request):
        log.debug('Requested path: %s', request.lookup_path)
        path = os.path.dirname(request.lookup_path)

        if path in self.__paths:
            filename = os.path.basename(request.path)
            for directory in self.__paths[path]:
                if os.path.join(directory, filename):
                    path = os.path.join(directory, filename)
                    log.debug('Serving path: %s', path)
                    mime_type = mimetypes.guess_type(path)
                    request.setHeader(b'content-type', mime_type[0])
                    with open(path, 'rb') as _file:
                        data = _file.read()
                    return compress(data, request)

        request.setResponseCode(http.NOT_FOUND)
        request.setHeader(b'content-type', b'text/html')
        template = Template(filename=rpath(os.path.join('render', '404.html')))
        return compress(template.render(), request)
Ejemplo n.º 12
0
    def render(self, request):
        debug = False
        if 'debug' in request.args:
            debug_arg = request.args.get('debug')[-1]
            if debug_arg in ('true', 'yes', '1'):
                debug = True
            else:
                debug = False

        dev = 'dev' in common.get_version()
        if 'dev' in request.args:
            dev_arg = request.args.get('dev')[-1]
            if dev_arg in ('true', 'yes' '1'):
                dev = True
            else:
                dev = False

        if dev:
            mode = 'dev'
        elif debug:
            mode = 'debug'
        else:
            mode = None

        scripts = component.get("Scripts").get_scripts(mode)
        scripts.insert(0, "gettext.js")

        template = Template(filename=rpath("index.html"))
        request.setHeader("content-type", "text/html; charset=utf-8")

        web_config = component.get("Web").get_config()
        web_config["base"] = request.base
        config = dict([(key, web_config[key]) for key in UI_CONFIG_KEYS])
        js_config = common.json.dumps(config)
        return template.render(scripts=scripts,
                               stylesheets=self.stylesheets,
                               debug=debug,
                               base=request.base,
                               js_config=js_config)
Ejemplo n.º 13
0
    def render(self, request):
        uri_true = ('true', 'yes', '1')
        debug_arg = request.args.get('debug', [''])[-1] in uri_true
        dev_arg = request.args.get('dev', [''])[-1] in uri_true
        dev_ver = 'dev' in common.get_version()

        script_type = 'normal'
        if debug_arg:
            script_type = 'debug'
        # Override debug if dev arg or version.
        if dev_arg or dev_ver:
            script_type = 'dev'

        if not self.js.has_script_type_files(script_type):
            if not dev_ver:
                log.warning('Failed to enable WebUI "%s" mode, script files are missing!', script_type)
            # Fallback to checking other types in order and selecting first with files available.
            for alt_script_type in [x for x in ['normal', 'debug', 'dev'] if x != script_type]:
                if self.js.has_script_type_files(alt_script_type):
                    script_type = alt_script_type
                    if not dev_ver:
                        log.warning('WebUI falling back to "%s" mode.', script_type)
                    break

        scripts = component.get('Scripts').get_scripts(script_type)
        scripts.insert(0, 'gettext.js')

        template = Template(filename=rpath('index.html'))
        request.setHeader(b'content-type', b'text/html; charset=utf-8')

        web_config = component.get('Web').get_config()
        web_config['base'] = request.base
        config = dict([(key, web_config[key]) for key in UI_CONFIG_KEYS])
        js_config = json.dumps(config)
        # Insert the values into 'index.html' and return.
        return template.render(scripts=scripts, stylesheets=self.stylesheets,
                               debug=debug_arg, base=request.base, js_config=js_config)
Ejemplo n.º 14
0
    def render(self, request):
        debug = False
        if 'debug' in request.args:
            debug_arg = request.args.get('debug')[-1]
            if debug_arg in ('true', 'yes', '1'):
                debug = True
            else:
                debug = False

        dev = 'dev' in common.get_version()
        if 'dev' in request.args:
            dev_arg = request.args.get('dev')[-1]
            if dev_arg in ('true', 'yes' '1'):
                dev = True
            else:
                dev = False

        if dev:
            mode = 'dev'
        elif debug:
            mode = 'debug'
        else:
            mode = None

        scripts = component.get("Scripts").get_scripts(mode)
        scripts.insert(0, "gettext.js")

        template = Template(filename=rpath("index.html"))
        request.setHeader("content-type", "text/html; charset=utf-8")

        web_config = component.get("Web").get_config()
        web_config["base"] = request.base
        config = dict([(key, web_config[key]) for key in UI_CONFIG_KEYS])
        js_config = common.json.dumps(config)
        return template.render(scripts=scripts, stylesheets=self.stylesheets,
            debug=debug, base=request.base, js_config=js_config)
Ejemplo n.º 15
0
 def render(self, request):
     request.setHeader("content-type", "text/javascript; encoding=utf-8")
     template = Template(filename=rpath("gettext.js"))
     return compress(template.render(), request)
Ejemplo n.º 16
0
 def render(self, request):
     request.setHeader("content-type", "text/javascript; encoding=utf-8")
     template = Template(filename=rpath("gettext.js"))
     return compress(template.render(), request)
Ejemplo n.º 17
0
 def render(self, request):
     request.setHeader(b'content-type', b'text/javascript; encoding=utf-8')
     template = Template(filename=rpath('js', 'gettext.js'))
     return compress(template.render(), request)
Ejemplo n.º 18
0
 def render(self, request):
     request.setHeader(b'content-type', b'text/javascript; encoding=utf-8')
     template = Template(filename=rpath('js', 'gettext.js'))
     return template.render()