def _build_event_handlers(context, components_dict):
        """
        Builds the event handlers for the application

        :param context: The template context
        :param components_dict: Dictionary containing components by name (and other info)
        """
        config = context.template.template_config
        app_section = config.application_section

        basic_sample_comp = components_dict["basic_sample_comp"]
        app_file_comp = components_dict["app_file_comp"]
        app_dir = components_dict["app_dir"]

        event_handlers = app_section.event_handlers
        if len(event_handlers) > 0:
            components_dict["has_events"] = True
            register_event_handler_def_comp = CodeTemplateComponent(
                "app/code/register_event_handler_def.code.tmpl")
            register_event_handler_def_comp.indent_level = 1
            app_file_comp.add_child(register_event_handler_def_comp)

            file_comp = FileTemplateComponent("eventhandlers.py",
                                              "app/eventhandlers.py.tmpl")
            app_dir.add_child(file_comp)

            for handler_name in event_handlers:
                handler_section = config.get_event_handler_section(
                    handler_name)
                code_comp = CodeTemplateComponent(
                    "app/code/events_event_callback.code.tmpl", {
                        "className": handler_section.class_name,
                        "name": handler_name,
                        "topic": handler_section.topic
                    })
                file_comp.add_child(code_comp)

                code_comp = CodeTemplateComponent(
                    "app/code/register_event_handler.code.tmpl", {
                        "className": handler_section.class_name,
                        "topic": handler_section.topic,
                        "callbackName": handler_name,
                        "separateThread": handler_section.separate_thread
                    })
                code_comp.indent_level = 1
                register_event_handler_def_comp.add_child(code_comp)

                event_code_comp = CodeTemplateComponent(
                    "sample/basic/code/event.code.tmpl", {
                        "topic": handler_section.topic,
                        "callbackName": handler_name
                    })
                event_code_comp.indent_level = 1
                basic_sample_comp.add_child(event_code_comp)
Ejemplo n.º 2
0
    def _build_client_directory(context, components_dict):
        """
        Builds the client directory components of the output

        :param context: The template context
        :param components_dict: Dictionary containing components by name (and other info)
        :return: The client directory components of the output
        """

        config = context.template.template_config
        client_section = config.client_section
        root = components_dict["root"]

        client_dir = DirTemplateComponent(client_section.name)
        root.add_child(client_dir)
        components_dict["client_dir"] = client_dir

        file_comp = FileTemplateComponent("__init__.py", "../../app/static/app/__init__.py.tmpl",
                                          {"appClassName": client_section.client_class_name,
                                           "relPackage": ".client"})
        client_dir.add_child(file_comp)

        file_comp = FileTemplateComponent("_version.py", "../../app/static/app/_version.py.tmpl",
                                          {"appClassName": client_section.client_class_name,
                                           "relPackage": ".client"})
        client_dir.add_child(file_comp)

        include_example = client_section.include_example_method
        file_comp = FileTemplateComponent("client.py", "client/client.py.tmpl",
                                          {"clientClassName": client_section.client_class_name,
                                           "fullName": client_section.full_name,
                                           "additionalImports":
                                               ("from dxlclient.message import Request\n"
                                                "from dxlbootstrap.util import MessageUtils\n"
                                                if include_example else "")})

        if include_example:
            comp = CodeTemplateComponent("client/code/example_method.code.tmpl")
            comp.indent_level = 1
            file_comp.add_child(comp)

        client_dir.add_child(file_comp)

        config_dir = DirTemplateComponent("_config")
        client_dir.add_child(config_dir)
        blank_init_file_comp = FileTemplateComponent("__init__.py", "../../app/static/app/__init__.py.blank.tmpl")

        config_dir.add_child(blank_init_file_comp)

        config_sample_dir = DirTemplateComponent("sample")
        config_dir.add_child(config_sample_dir)
        config_sample_dir.add_child(blank_init_file_comp)
        ClientTemplate._copy_sample_files(context, components_dict, config_sample_dir)
Ejemplo n.º 3
0
    def _build_sample_directory(context, components_dict):
        """
        Builds the "sample" directory components of the output

        :param context: The template context
        :param components_dict: Dictionary containing components by name (and other info)
        :return: The "sample" directory components of the output
        """
        config = context.template.template_config
        client_section = config.client_section
        root = components_dict["root"]

        sample_dir = DirTemplateComponent("sample")
        root.add_child(sample_dir)

        ClientTemplate._copy_sample_files(context, components_dict, sample_dir)

        file_comp = FileTemplateComponent(
            "common.py", "../../app/static/sample/common.py.tmpl")
        sample_dir.add_child(file_comp)

        sample_basic_dir = DirTemplateComponent("basic")
        sample_dir.add_child(sample_basic_dir)

        include_example = client_section.include_example_method
        basic_sample_comp = FileTemplateComponent(
            "basic_sample.py", "sample/basic/basic_sample.py.tmpl", {
                "clientClassName":
                client_section.client_class_name,
                "name":
                client_section.name,
                "additionalImports":
                ("from dxlbootstrap.util import MessageUtils\n"
                 if include_example else "")
            })
        if include_example:
            comp = CodeTemplateComponent(
                "sample/basic/code/invoke_example_method.code.tmpl")
            comp.indent_level = 1
            basic_sample_comp.add_child(comp)

        sample_basic_dir.add_child(basic_sample_comp)
    def _build_services(context, components_dict):
        """
        Builds the services exposed by the application

        :param context: The template context
        :param components_dict: Dictionary containing components by name (and other info)
        """
        config = context.template.template_config
        app_section = config.application_section

        basic_sample_comp = components_dict["basic_sample_comp"]
        app_file_comp = components_dict["app_file_comp"]
        app_dir = components_dict["app_dir"]

        service_names = app_section.services
        requests_file_comp = None
        if len(service_names) > 0:
            components_dict["has_services"] = True
            register_services_def_comp = CodeTemplateComponent(
                "app/code/register_services_def.code.tmpl")
            register_services_def_comp.indent_level = 1
            app_file_comp.add_child(register_services_def_comp)

            for service_name in service_names:
                service = config.get_service_section(service_name)
                service_create_comp = CodeTemplateComponent(
                    "app/code/service_create.code.tmpl", {
                        "serviceType": service.service_type,
                        "serviceName": service_name
                    })
                service_create_comp.indent_level = 1
                register_services_def_comp.add_child(service_create_comp)

                request_handlers = service.request_handlers
                for handler_name in request_handlers:
                    handler_section = config.get_request_handler_section(
                        handler_name)
                    if requests_file_comp is None:
                        requests_file_comp = FileTemplateComponent(
                            "requesthandlers.py",
                            "app/requesthandlers.py.tmpl")
                        app_dir.add_child(requests_file_comp)
                    code_comp = CodeTemplateComponent(
                        "app/code/requests_request_callback.code.tmpl", {
                            "className": handler_section.class_name,
                            "name": handler_name,
                            "topic": handler_section.topic
                        })
                    requests_file_comp.add_child(code_comp)

                    code_comp = CodeTemplateComponent(
                        "app/code/service_add_topic.code.tmpl", {
                            "topic": handler_section.topic,
                            "className": handler_section.class_name,
                            "separateThread": handler_section.separate_thread,
                            "callbackName": handler_name
                        })
                    code_comp.indent_level = 1
                    register_services_def_comp.add_child(code_comp)

                    request_code_comp = CodeTemplateComponent(
                        "sample/basic/code/request.code.tmpl", {
                            "topic": handler_section.topic,
                            "name": handler_name
                        })
                    request_code_comp.indent_level = 1
                    basic_sample_comp.add_child(request_code_comp)

                code_comp = CodeTemplateComponent(
                    "app/code/service_register.code.tmpl", )
                code_comp.indent_level = 1
                register_services_def_comp.add_child(code_comp)