Esempio n. 1
0
    def __gen_network(self):
        mako_file = os.path.join(self._mako_dir, 'asio', 'tcp_connection.h')
        out_file = os.path.join(self._service_dir, 'network',
                                'tcp_connection.h')
        tool.gen_code_file(
            mako_file,
            out_file,
            framework=self._framework,
            gen_upper_camel=util.gen_upper_camel,
            log=self._log,
            # apis=self.__framework.apis,
        )

        if self._framework.is_server:
            mako_file = os.path.join(self._mako_dir, 'asio',
                                     'tcp_async_server.h')
            out_file = os.path.join(
                self._service_dir, self._framework.service_name,
                '%s_tcp_server.h' % self._framework.service_name)
            tool.gen_code_file(
                mako_file,
                out_file,
                framework=self._framework,
                gen_upper_camel=util.gen_upper_camel,
                log=self._log,
                # apis=self.__framework.apis,
            )
Esempio n. 2
0
 def _gen_cmake(self):
     mako_file = os.path.join(self._cpp_mako_dir, 'CMakeLists.txt')
     out_file = os.path.join(self._service_dir, 'CMakeLists.txt')
     tool.gen_code_file(mako_file, out_file,
                        project_name=self._project_name,
                        frameworks=self._frameworks,
                        )
Esempio n. 3
0
 def nlohmann_json(self):
     tool.gen_code_file(os.path.join(self.__mako_dir, "nlohmann_json.h"),
                        os.path.join(self.__service_dir, "types", "types.h"),
                        nodes=self.__nodes,
                        enums=self.__enums,
                        )
     tool.gen_code_file(os.path.join(self.__mako_dir, "nlohmann_json.cpp"),
                        os.path.join(self.__service_dir, "types", "types.cpp"),
                        nodes=self.__nodes,
                        enums=self.__enums,
                        )
Esempio n. 4
0
 def __gen_network(self):
     mako_file = os.path.join(self._mako_dir, 'beast',
                              'websocket_connection.h')
     out_file = os.path.join(self._service_dir, 'network',
                             'websocket_connection.h')
     tool.gen_code_file(
         mako_file,
         out_file,
         framework=self._framework,
         gen_upper_camel=util.gen_upper_camel,
         log=self._log,
         # apis=self._framework.apis,
     )
Esempio n. 5
0
 def __gen_network_adapt(self):
     mako_file = os.path.join(self._mako_dir, 'adapt', '%s.h' % self._framework.adapt)
     out_file = os.path.join(self._service_dir, self._framework.service_name, '%s.h' % self._framework.adapt_name)
     include_list = ['network/websocket_connection.h']
     tool.gen_code_file(mako_file, out_file,
                        framework=self._framework,
                        apis=self._framework.apis,
                        log=self._log,
                        connection_class_name="WebsocketConnection",
                        server_apis=self._framework.server_apis,
                        client_apis=self._framework.client_apis,
                        include_list=include_list,
                        )
Esempio n. 6
0
 def gen(self):
     tool.gen_code_file(
         self.__mako_file,
         self.__doc_out_file,
         apis=self.__apis,
         dict2json=tool.dict2json,
         url_param2text=tool.url_param2text,
         markdown_full_path=tool.markdown_full_path,
         enums=self.__enums,
         is_enum=tool.is_enum,
         errnos=self.__errnos,
         nodes2fields=tool.nodes2fields,
         markdown_type=tool.markdown_type,
         markdown_note=tool.markdown_note,
     )
Esempio n. 7
0
 def __gen_network_adapt(self):
     mako_file = os.path.join(self._mako_dir, 'adapt',
                              '%s.h' % self._framework.adapt)
     out_file = os.path.join(self._service_dir,
                             self._framework.service_name,
                             '%s.h' % self._framework.adapt_name)
     include_list = ['network/tcp_connection.h']
     tool.gen_code_file(
         mako_file,
         out_file,
         framework=self._framework,
         # apis=self._framework.apis,
         log=self._log,
         connection_class_name="TcpConnection",
         include_list=include_list,
     )
Esempio n. 8
0
    def _gen_config(self):
        mako_file = os.path.join(self._cpp_mako_dir, 'config.h')
        out_file = os.path.join(self._service_dir, 'config', 'config.h')
        std_includes = ['vector', 'string']
        config = {}
        for framework in self._frameworks:
            config = dict(config, **(framework.config))
        print("config:", config)
        node = Node(None, "config", config)
        nodes = tool.to_nodes(node)

        tool.gen_code_file(mako_file, out_file,
                           nodes=nodes,
                           std_includes=std_includes,
                           )
        out_file = os.path.join(self._service_dir, "config.json")
        with open(out_file, "w") as f:
            json.dump(config, f, ensure_ascii=False, indent=4)
Esempio n. 9
0
    def _gen_types(self):
        mako_file = os.path.join(self._cpp_mako_dir, 'common', 'types.h')
        out_file = os.path.join(self._service_dir, 'common', 'types.h')
        std_includes = ['vector', 'string']
        enums = []
        nodes = []
        for framework in self._frameworks:
            nodes += framework.nodes
        nodes = tool.to_nodes(nodes)

        for framework in self._frameworks:
            enums += framework.enums

        enums = util.unique(enums)
        for enum in enums:
            print(enum)
            for value in enum.values:
                print(value)
        tool.gen_code_file(mako_file, out_file,
                           nodes=nodes,
                           std_includes=std_includes,
                           enums=enums,
                           )
Esempio n. 10
0
 def _gen_main(self):
     mako_file = os.path.join(self._cpp_mako_dir, 'main.cpp')
     out_file = os.path.join(self._service_dir, 'main', 'main.cpp')
     tool.gen_code_file(mako_file, out_file,
                        frameworks=self._frameworks,
                        )
Esempio n. 11
0
 def _gen_make(self):
     mako_file = os.path.join(self._cpp_mako_dir, 'makefile')
     out_file = os.path.join(self._service_dir, 'makefile')
     tool.gen_code_file(mako_file, out_file,
                        project_name=self._project_name,
                        )
Esempio n. 12
0
 def _gen_buildsh(self):
     mako_file = os.path.join(self._cpp_mako_dir, 'build.sh')
     out_file = os.path.join(self._service_dir, 'build.sh')
     tool.gen_code_file(mako_file, out_file)
Esempio n. 13
0
    def _gen_apis(self):
        # header

        for framework in self._frameworks:
            server_apis = framework.server_apis
            server_apis = util.unique(server_apis)
            client_apis = framework.client_apis
            client_apis = util.unique(client_apis)

            if type_set.beast_websocket_async == framework.network:
                include_list = ["network/websocket_connection.h"]
                connection_class_name = "WebsocketConnection"
            elif type_set.asio_tcp_async == framework.network:
                include_list = ["network/tcp_connection.h"]
                connection_class_name = "TcpConnection"
            else:
                assert False

            # apis.h
            mako_file = os.path.join(self._cpp_mako_dir, 'service', 'api.h')
            out_file = os.path.join(self._service_dir, framework.service_name, 'api.h')
            tool.gen_code_file(mako_file, out_file,
                               framework=framework,
                               adapt_name=framework.adapt_name,
                               adapt_class_name=framework.adapt_class_name,
                               # no_resp=framework.no_resp,
                               include_list=include_list,
                               connection_class_name=connection_class_name,
                               # server_apis=server_apis,
                               # client_apis=client_apis,
                               )

            # server_apis
            mako_file = os.path.join(self._cpp_mako_dir, 'service', 'server_api.cpp')
            for api in server_apis:
                out_file = os.path.join(self._service_dir, framework.service_name, api.name + '.cpp')
                if not os.path.exists(out_file):
                    tool.gen_code_file(mako_file, out_file,
                                       framework=framework,
                                       # no_resp=framework.no_resp,
                                       api=api,
                                       log=self._log,
                                       )
            # client_apis.h
            mako_file = os.path.join(self._cpp_mako_dir, 'service', 'client_apis.cpp')
            out_file = os.path.join(self._service_dir, framework.service_name, 'client_apis.cpp')
            tool.gen_code_file(mako_file, out_file,
                               framework=framework,
                               # no_resp=framework.no_resp,
                               # server_apis=server_apis,
                               # client_apis=client_apis,
                               )

            # types
            mako_file = os.path.join(self._cpp_mako_dir, 'service', 'types.h')
            out_file = os.path.join(self._service_dir, framework.service_name, 'types.h')
            nodes = framework.nodes
            enums = framework.enums
            std_includes = ['vector', 'string']
            tool.gen_code_file(mako_file, out_file,
                               nodes=nodes,
                               std_includes=std_includes,
                               enums=enums,
                               )

            # doc
            mako_file = os.path.join(self._mako_dir, 'doc_tcp_json.md')
            out_file = os.path.join(self._service_dir, framework.service_name, 'doc', '%s.md' % framework.service_name)
            doc_generator = doc.Doc(mako_file=mako_file,
                                    out_file=out_file,
                                    apis=framework.apis,
                                    enums=framework.enums,
                                    errnos=framework.error_code.errnos)
            doc_generator.gen()