示例#1
0
    def reading_project_route(self):
        for route_path in config(ROUTE_PATH_LIST):
            for route_params in self.__get_valid_routes(route_path):
                url, view, name = route_params
                EdenRouteToWerkzeug.instance.set_route(url, view, name)

        return EdenRouteToWerkzeug.instance.get_route()
示例#2
0
    def __get_valid_routes(self, werkzeug_route):
        """
            Get correct routes or throw exception
        """
        try:
            for routing in config(ROUTE_KEY_IN_CONFIG, werkzeug_route):
                # Check exists
                if not routing.get(URL_KEY_IN_ROUTE_CONFIG):
                    raise exception.RouteUrlNotFoundException

                if not routing.get(VIEW_KEY_IN_ROUTE_CONFIG):
                    raise exception.RouteViewNotFoundException

                if not routing.get(NAME_KEY_ROUTE_CONFIG):
                    raise exception.RouteNameNotFoundException

                # Check duplicate
                if routing[URL_KEY_IN_ROUTE_CONFIG] in self.__urls:
                    raise exception.RouteUrlDuplicatedException

                if routing[NAME_KEY_ROUTE_CONFIG] in self.__names:
                    raise exception.RouteNameDuplicatedException

                self.__urls.append(routing[URL_KEY_IN_ROUTE_CONFIG])
                self.__names.append(routing[NAME_KEY_ROUTE_CONFIG])

                yield routing['url'], routing['view'], routing['name']
        except exception.RoutingException as route_exception:
            # Protected shadow exceptions
            self.__urls, self.__names = [], []
            raise route_exception
示例#3
0
def application():
    app = None
    middleware_list = config(WERKZEUG_MIDDLEWARE)

    if not middleware_list:
        raise MiddlewareNotFound

    for middleware in middleware_list:
        if app:
            app = import_string(middleware)(app)
        else:
            app = import_string(middleware)()

    return app
示例#4
0
    def __check_urls(self):
        jinja_template_urls = config("jinja_template_urls")
        if not jinja_template_urls:
            raise JinjaTemplateUrlEmpty("jinja_template_urls is empty")

        if isinstance(jinja_template_urls, six.string_types):
            if not os.path.isdir(jinja_template_urls):
                raise JinjaTemplateUrlNotExist("%s don't exists correct it!" % jinja_template_urls)
        else:
            for template_url in jinja_template_urls:
                if not os.path.isdir(template_url):
                    raise JinjaTemplateUrlNotExist("%s don't exists correct it!" % template_url)

        return jinja_template_urls
示例#5
0
文件: run.py 项目: myrubapa/edenbase
    def handler(self, *args, **kwargs):
        debug = config('debug')
        host = self.get_host(args, kwargs) or DEFAULT_HOST
        port = self.get_port(args, kwargs) or DEFAULT_PORT

        from werkzeug.serving import run_simple
        from eden.components.werkzeug.application import application
        from eden.components.werkzeug.utils import find_config_files

        run_simple(
            host, int(port), application(),
            use_debugger=debug, use_reloader=debug,
            reloader_type='stat',
            extra_files=find_config_files(('.yml', ))
        )
示例#6
0
    def handler(self, *args, **kwargs):
        debug = config('debug')
        host = self.get_host(args, kwargs) or DEFAULT_HOST
        port = self.get_port(args, kwargs) or DEFAULT_PORT

        from werkzeug.serving import run_simple
        from eden.components.werkzeug.application import application
        from eden.components.werkzeug.utils import find_config_files

        run_simple(host,
                   int(port),
                   application(),
                   use_debugger=debug,
                   use_reloader=debug,
                   reloader_type='stat',
                   extra_files=find_config_files(('.yml', )))
示例#7
0
    def __check_urls(self):
        jinja_template_urls = config('jinja_template_urls')
        if not jinja_template_urls:
            raise JinjaTemplateUrlEmpty('jinja_template_urls is empty')

        if isinstance(jinja_template_urls, six.string_types):
            if not os.path.isdir(jinja_template_urls):
                raise JinjaTemplateUrlNotExist('%s don\'t exists correct it!' %
                                               jinja_template_urls)
        else:
            for template_url in jinja_template_urls:
                if not os.path.isdir(template_url):
                    raise JinjaTemplateUrlNotExist(
                        '%s don\'t exists correct it!' % template_url)

        return jinja_template_urls
示例#8
0
文件: help.py 项目: myrubapa/edenbase
    def __find_modules(self):
            modules_list = []
            for module in config(COMPONENTS):
                import_module_name = module + '.' + COMMAND_DIR
                try:
                    module_import = importlib.import_module(import_module_name)
                    command_dir_path = os.path.dirname(module_import.__file__)
                    for file in os.listdir(command_dir_path):
                        commands = self.__find_commands(file, import_module_name)
                        if commands:
                            modules_list.append({
                                'name': module,
                                'commands': commands
                            })
                except ImportError:
                    pass

            return modules_list
示例#9
0
    def __find_modules(self):
        modules_list = []
        for module in config(COMPONENTS):
            import_module_name = module + '.' + COMMAND_DIR
            try:
                module_import = importlib.import_module(import_module_name)
                command_dir_path = os.path.dirname(module_import.__file__)
                for file in os.listdir(command_dir_path):
                    commands = self.__find_commands(file, import_module_name)
                    if commands:
                        modules_list.append({
                            'name': module,
                            'commands': commands
                        })
            except ImportError:
                pass

        return modules_list
示例#10
0
    def __find_command(self, main_command):
        command = None
        for module in config(COMPONENTS):
            import_module_name = module + '.' + \
                COMMAND_DIR + '.' + main_command

            try:
                module = importlib.import_module(import_module_name)
                if not command and module:
                    command = module
                else:
                    raise DuplicateCommand(
                        'Duplicate command %s please correct it!' %
                        main_command)
            except ImportError:
                pass

        if not command:
            console_command_helper = Help(message='Command %s not found!' %
                                          main_command)
            console_command_helper.show_helper()

        return command
    def __init__(self, app):
        static_url = config(WERKZEUG_STATIC_URL)
        static_root = config(WERKZEUG_STATIC_ROOT)

        super(StaticFilesMiddleware, self)\
            .__init__(app, {static_url: static_root})