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 """ del context root = components_dict["root"] sample_dir = DirTemplateComponent("sample") root.add_child(sample_dir) file_comp = FileTemplateComponent("dxlclient.config", "config/dxlclient.config.tmpl") sample_dir.add_child(file_comp) file_comp = FileTemplateComponent("dxlclient.config.dist", "config/dxlclient.config.tmpl") sample_dir.add_child(file_comp) file_comp = FileTemplateComponent("common.py", "sample/common.py.tmpl") sample_dir.add_child(file_comp) sample_basic_dir = DirTemplateComponent("basic") sample_dir.add_child(sample_basic_dir) basic_sample_comp = FileTemplateComponent( "basic_sample.py", "sample/basic/basic_sample.py.tmpl") sample_basic_dir.add_child(basic_sample_comp) components_dict["basic_sample_comp"] = basic_sample_comp
def _build_application_directory(context, components_dict): """ Builds the application directory components of the output :param context: The template context :param components_dict: Dictionary containing components by name (and other info) :return: The application directory components of the output """ def _get_additional_imports(): """ Outputs the imports for the "app.py" file (based on whether event and/or request callbacks have been defined in the configuration) :return: The imports for the "app.py" file (based on whether event and/or request callbacks have been defined in the configuration) """ ret = "" if components_dict["has_events"] or components_dict["has_services"]: ret += "\n" if components_dict["has_services"]: ret += "from dxlclient.service import ServiceRegistrationInfo\n" ret += "from requesthandlers import *\n" if components_dict["has_events"]: ret += "from eventhandlers import *\n" return ret config = context.template.template_config app_section = config.application_section root = components_dict["root"] app_dir = DirTemplateComponent(app_section.name) root.add_child(app_dir) components_dict["app_dir"] = app_dir file_comp = FileTemplateComponent( "__init__.py", "app/__init__.py.tmpl", { "appClassName": app_section.app_class_name, "relPackage": ".app" }) app_dir.add_child(file_comp) app_file_comp = FileTemplateComponent( "app.py", "app/app.py.tmpl", { "appClassName": app_section.app_class_name, "name": app_section.name, "fullName": app_section.full_name, "additionalImports": _get_additional_imports }) components_dict["app_file_comp"] = app_file_comp app_dir.add_child(app_file_comp) file_comp = FileTemplateComponent( "__main__.py", "app/__main__.py.tmpl", { "appClassName": app_section.app_class_name, "name": app_section.name }) app_dir.add_child(file_comp)
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)
def _build_root_directory(self, context, components_dict): """ Builds the "root" directory components of the output :param context: The template context :param components_dict: Dictionary containing components by name (and other info) :return: The "root" directory components of the output """ config = context.template.template_config app_section = config.application_section root = DirTemplateComponent("") components_dict["root"] = root file_comp = FileTemplateComponent( "README", "README.tmpl", { "fullName": app_section.full_name, "fullNameSep": self.create_underline(len(app_section.full_name), "="), "copyright": app_section.copyright }) root.add_child(file_comp) file_comp = FileTemplateComponent("README.md", "README.md.tmpl", { "fullName": app_section.full_name, "copyright": app_section.copyright }) root.add_child(file_comp) file_comp = FileTemplateComponent( "setup.py", "setup.py.tmpl", { "name": app_section.name, "installRequires": self.create_install_requires(app_section.install_requires) }) root.add_child(file_comp) file_comp = FileTemplateComponent("LICENSE", "LICENSE.tmpl") root.add_child(file_comp) file_comp = FileTemplateComponent("MANIFEST.in", "MANIFEST.in.tmpl") root.add_child(file_comp) file_comp = FileTemplateComponent("dist.py", "dist.py.tmpl", {"name": app_section.name}) root.add_child(file_comp) file_comp = FileTemplateComponent("clean.py", "clean.py.tmpl", {"name": app_section.name}) root.add_child(file_comp) file_comp = FileTemplateComponent( "Dockerfile", "Dockerfile.tmpl", { "name": app_section.name, "pipInstall": self.create_pip_install(config) }) root.add_child(file_comp)
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)
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_config_directory(context, components_dict): """ Builds the "config" directory components of the output :param context: The template context :param components_dict: Dictionary containing components by name (and other info) :return: The "config" directory components of the output """ config = context.template.template_config app_section = config.application_section root = components_dict["root"] config_dir = DirTemplateComponent("config") root.add_child(config_dir) file_comp = FileTemplateComponent("logging.config", "config/logging.config.tmpl") config_dir.add_child(file_comp) file_comp = FileTemplateComponent("logging.config.dist", "config/logging.config.tmpl") config_dir.add_child(file_comp) file_comp = FileTemplateComponent("dxlclient.config", "config/dxlclient.config.tmpl") config_dir.add_child(file_comp) file_comp = FileTemplateComponent("dxlclient.config.dist", "config/dxlclient.config.tmpl") config_dir.add_child(file_comp) file_comp = FileTemplateComponent(app_section.name + ".config", "config/app.config.tmpl", {"fullName": app_section.full_name}) config_dir.add_child(file_comp) file_comp = FileTemplateComponent(app_section.name + ".config.dist", "config/app.config.tmpl", {"fullName": app_section.full_name}) config_dir.add_child(file_comp)
def _copy_schema_files(context, components_dict, dir_comp): """ Copies the application schema file to the specified directory :param context: The template context :param components_dict: Dictionary containing components by name (and other info) :param dir_comp: The directory component to copy the files to """ del components_dict config = context.template.template_config app_name = str(config.application_section.name) service_names = config.application_section.services yaml_writer = DxlSchemaWriter(app_name) if service_names: for service_name in service_names: service = config.get_service_section(service_name) service_type = str(service.service_type) yaml_writer.add_service_def_to_schema(service_type) yaml_writer.add_service_ref_to_solution(service_type) request_handlers = service.request_handlers if request_handlers: for request_handler in request_handlers: req_handler_def = config.get_request_handler_section( request_handler) topic = str(req_handler_def.topic) yaml_writer.add_request_def_to_schema(topic) yaml_writer.add_request_ref_to_service( service_type, topic) event_handlers = config.application_section.event_handlers if event_handlers: for event_handler in event_handlers: event_handler_def = config.get_event_handler_section( event_handler) topic = str(event_handler_def.topic) yaml_writer.add_event_def_to_schema(topic) yaml_writer.add_event_ref_to_solution(topic) schema_dict = yaml_writer.schema_dict_yaml file_comp = FileTemplateComponent(app_name + ".yaml", "schema/v0.1/schema.tmpl", {"schemaContent": schema_dict}) dir_comp.add_child(file_comp)
def _copy_sample_files(context, components_dict, dir_comp): """ Copies the sample configuration files to the specified directory :param context: The template context :param components_dict: Dictionary containing components by name (and other info) :param dir_comp: The directory component to copy the files to """ del context del components_dict file_comp = FileTemplateComponent("dxlclient.config", "../../app/static/config/dxlclient.config.tmpl") dir_comp.add_child(file_comp)
def _copy_config_files(context, components_dict, dir_comp): """ Copies the application configuration files to the specified directory :param context: The template context :param components_dict: Dictionary containing components by name (and other info) :param dir_comp: The directory component to copy the files to """ del components_dict config = context.template.template_config app_section = config.application_section file_comp = FileTemplateComponent("logging.config", "config/logging.config.tmpl") dir_comp.add_child(file_comp) file_comp = FileTemplateComponent("dxlclient.config", "config/dxlclient.config.tmpl") dir_comp.add_child(file_comp) file_comp = FileTemplateComponent(app_section.name + ".config", "config/app.config.tmpl", {"fullName": app_section.full_name}) dir_comp.add_child(file_comp)
def _build_root_directory(self, context, components_dict): """ Builds the "root" directory components of the output :param context: The template context :param components_dict: Dictionary containing components by name (and other info) :return: The "root" directory components of the output """ config = context.template.template_config client_section = config.client_section root = DirTemplateComponent("") components_dict["root"] = root file_comp = FileTemplateComponent("README", "../../app/static/README.tmpl", {"fullName": client_section.full_name, "fullNameSep": self.create_underline(len(client_section.full_name), "="), "copyright": client_section.copyright}) root.add_child(file_comp) file_comp = FileTemplateComponent("README.md", "../../app/static/README.md.tmpl", {"fullName": client_section.full_name, "copyright": client_section.copyright}) root.add_child(file_comp) file_comp = FileTemplateComponent("setup.py", "../../app/static/setup.py.tmpl", {"name": client_section.name, "installRequires": self.create_install_requires( client_section.install_requires), "packages": "", "package_data": ""}) root.add_child(file_comp) file_comp = FileTemplateComponent("LICENSE", "../../app/static/LICENSE.tmpl") root.add_child(file_comp) file_comp = FileTemplateComponent("MANIFEST.in", "../../app/static/MANIFEST.in.tmpl") root.add_child(file_comp) file_comp = FileTemplateComponent("dist.py", "dist.py.tmpl", {"name": client_section.name}) root.add_child(file_comp) file_comp = FileTemplateComponent("clean.py", "../../app/static/clean.py.tmpl", {"name": client_section.name}) root.add_child(file_comp)
def _build_docs_directory(self, context, components_dict): """ Builds the "docs" directory components of the output :param context: The template context :param components_dict: Dictionary containing components by name (and other info) :return: The "docs" directory components of the output """ config = context.template.template_config client_section = config.client_section root = components_dict["root"] doc_dir = DirTemplateComponent("doc") root.add_child(doc_dir) file_comp = FileTemplateComponent("conf.py", "../../app/static/doc/conf.py.tmpl", {"copyright": client_section.copyright, "fullName": client_section.full_name, "name": client_section.name}) doc_dir.add_child(file_comp) sdk_dir = DirTemplateComponent("sdk") doc_dir.add_child(sdk_dir) file_comp = FileTemplateComponent("index.rst", "doc/sdk/index.rst.tmpl", {"fullName": client_section.full_name, "fullNameSep": self.create_underline(len(client_section.full_name), "="), "name": client_section.name}) sdk_dir.add_child(file_comp) file_comp = FileTemplateComponent("README.html", "../../app/static/doc/sdk/README.html.tmpl", {"copyright": client_section.copyright, "fullName": client_section.full_name}) sdk_dir.add_child(file_comp) file_comp = FileTemplateComponent("overview.rst", "../../app/static/doc/sdk/overview.rst.tmpl") sdk_dir.add_child(file_comp) file_comp = FileTemplateComponent("installation.rst", "doc/sdk/installation.rst.tmpl", {"name": client_section.name}) sdk_dir.add_child(file_comp) file_comp = FileTemplateComponent("sampleconfig.rst", "../../app/static/doc/sdk/sampleconfig.rst.tmpl", {"fullName": client_section.full_name}) sdk_dir.add_child(file_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)
def _build_docs_directory(self, context, components_dict): """ Builds the "docs" directory components of the output :param context: The template context :param components_dict: Dictionary containing components by name (and other info) :return: The "docs" directory components of the output """ config = context.template.template_config app_section = config.application_section root = components_dict["root"] doc_dir = DirTemplateComponent("doc") root.add_child(doc_dir) file_comp = FileTemplateComponent( "conf.py", "doc/conf.py.tmpl", { "copyright": app_section.copyright, "fullName": app_section.full_name, "name": app_section.name }) doc_dir.add_child(file_comp) sdk_dir = DirTemplateComponent("sdk") doc_dir.add_child(sdk_dir) file_comp = FileTemplateComponent( "index.rst", "doc/sdk/index.rst.tmpl", { "fullName": app_section.full_name, "fullNameSep": self.create_underline(len(app_section.full_name), "="), "name": app_section.name }) sdk_dir.add_child(file_comp) file_comp = FileTemplateComponent( "README.html", "doc/sdk/README.html.tmpl", { "copyright": app_section.copyright, "fullName": app_section.full_name }) sdk_dir.add_child(file_comp) file_comp = FileTemplateComponent("overview.rst", "doc/sdk/overview.rst.tmpl") sdk_dir.add_child(file_comp) file_comp = FileTemplateComponent("installation.rst", "doc/sdk/installation.rst.tmpl", {"name": app_section.name}) sdk_dir.add_child(file_comp) file_comp = FileTemplateComponent("running.rst", "doc/sdk/running.rst.tmpl", {"name": app_section.name}) sdk_dir.add_child(file_comp) config_title = "{0} ({1}.config)".format(app_section.full_name, app_section.name) file_comp = FileTemplateComponent( "configuration.rst", "doc/sdk/configuration.rst.tmpl", { "fullName": app_section.full_name, "name": app_section.name, "configTitle": config_title, "configTitleSep": self.create_underline( len(config_title), "-") }) sdk_dir.add_child(file_comp) file_comp = FileTemplateComponent("sampleconfig.rst", "doc/sdk/sampleconfig.rst.tmpl", {"fullName": app_section.full_name}) sdk_dir.add_child(file_comp)
def _build_docs_directory(self, context, components_dict): """ Builds the "docs" directory components of the output :param context: The template context :param components_dict: Dictionary containing components by name (and other info) :return: The "docs" directory components of the output """ config = context.template.template_config client_section = config.client_section root = components_dict["root"] doc_dir = DirTemplateComponent("doc") root.add_child(doc_dir) copyright_body = re.sub(r"^Copyright ", "", client_section.copyright, flags=re.IGNORECASE) file_comp = FileTemplateComponent( "conf.py", "../../app/static/doc/conf.py.tmpl", { "copyright": copyright_body, "fullName": client_section.full_name, "name": client_section.name }) doc_dir.add_child(file_comp) file_comp = FileTemplateComponent( "docutils.conf", "../../app/static/doc/docutils.conf.tmpl") doc_dir.add_child(file_comp) sdk_dir = DirTemplateComponent("sdk") doc_dir.add_child(sdk_dir) file_comp = FileTemplateComponent( "index.rst", "doc/sdk/index.rst.tmpl", { "fullName": client_section.full_name, "fullNameSep": self.create_underline(len(client_section.full_name), "="), "name": client_section.name }) sdk_dir.add_child(file_comp) file_comp = FileTemplateComponent( "README.html", "../../app/static/doc/sdk/README.html.tmpl", { "copyright": client_section.copyright, "fullName": client_section.full_name }) sdk_dir.add_child(file_comp) file_comp = FileTemplateComponent( "overview.rst", "../../app/static/doc/sdk/overview.rst.tmpl") sdk_dir.add_child(file_comp) file_comp = FileTemplateComponent( "installation.rst", "doc/sdk/installation.rst.tmpl", { "name": client_section.name, "pythonVersion": self.create_installation_doc_version_text( client_section.language_version), "versionTag": self.create_dist_version_tag(client_section.language_version) }) sdk_dir.add_child(file_comp) file_comp = FileTemplateComponent( "sampleconfig.rst", "../../app/static/doc/sdk/sampleconfig.rst.tmpl", {"fullName": client_section.full_name}) sdk_dir.add_child(file_comp)
def _build_root_directory(self, context, components_dict): """ Builds the "root" directory components of the output :param context: The template context :param components_dict: Dictionary containing components by name (and other info) :return: The "root" directory components of the output """ config = context.template.template_config app_section = config.application_section root = DirTemplateComponent("") components_dict["root"] = root file_comp = FileTemplateComponent( "README", "README.tmpl", { "fullName": app_section.full_name, "fullNameSep": self.create_underline(len(app_section.full_name), "="), "copyright": app_section.copyright }) root.add_child(file_comp) file_comp = FileTemplateComponent("README.md", "README.md.tmpl", { "fullName": app_section.full_name, "copyright": app_section.copyright }) root.add_child(file_comp) file_comp = FileTemplateComponent( "setup.py", "setup.py.tmpl", { "name": app_section.name, "installRequires": self.create_install_requires(app_section.install_requires), "pythonRequires": self.create_language_requires(app_section.language_version), "packages": ',\n "' + app_section.name + '._config.app"', "package_data": ',\n "' + app_section.name + "._config.app\" : ['*']", "classifiers": self.create_classifiers(app_section.language_version) }) root.add_child(file_comp) file_comp = FileTemplateComponent("LICENSE", "LICENSE.tmpl") root.add_child(file_comp) file_comp = FileTemplateComponent("MANIFEST.in", "MANIFEST.in.tmpl") root.add_child(file_comp) file_comp = FileTemplateComponent( "dist.py", "dist.py.tmpl", { "name": app_section.name, "versionTag": self.create_dist_version_tag(app_section.language_version) }) root.add_child(file_comp) file_comp = FileTemplateComponent("clean.py", "clean.py.tmpl", {"name": app_section.name}) root.add_child(file_comp) file_comp = FileTemplateComponent( "Dockerfile", "Dockerfile.tmpl", { "name": app_section.name, "pythonVersion": self.create_docker_image_language_version( app_section.language_version) }) root.add_child(file_comp)