def traverse(templates_dir, configuration_context): """ traverse through the folder structure and generate xml files :param templates_dir: path to the template directory in template module :param configuration_context: dictionary containing configurations loaded from module.ini :return None """ log.info("Scanning for templates in %s", templates_dir) carbon_home = ConfigParserUtil.get_carbon_home(configuration_context) for root, dirs, files in os.walk(templates_dir): for filename in files: # generating the relative path of the template template_file_path = os.path.join(root, filename) log.debug("Template file path: %s ", template_file_path) template_relative_path = os.path.splitext(os.path.relpath(os.path.join(root, filename), templates_dir))[0] log.debug("Teplate relative path: %s", template_relative_path) template_file_target = os.path.join(carbon_home, template_relative_path) log.debug("Template file target path: %s ", template_file_target) # populate the template and copy to target location generate_file_from_template(template_file_path, template_file_target, configuration_context)
def configure(): """ Main method :param cli_arguments: command line arguments :return None """ log.info("Scanning the template module directory: %s" % template_module_parent_dir) # traverse through the template directory only_directories = [f for f in os.listdir(template_module_parent_dir) if os.path.isdir(os.path.join(template_module_parent_dir, f))] if len(only_directories) == 0: log.info("No directories found at %s", template_module_parent_dir) for file_name in only_directories: module_settings_file_path = os.path.join(template_module_parent_dir, file_name, constants.CONFIG_FILE_NAME) templates_dir = os.path.join(template_module_parent_dir, file_name, constants.TEMPLATES_FOLDER_NAME) files_dir = os.path.join(template_module_parent_dir, file_name, constants.FILES_FOLDER_NAME) if os.path.isfile(module_settings_file_path): log.info("Module settings file found for template module: %s", file_name) else: log.warn("Could not find module settings file at: %s. Skipping directory...", module_settings_file_path) continue log.info("Populating templates at: %s", templates_dir) configuration_context = generate_context(module_settings_file_path) traverse(templates_dir, configuration_context) # copy files directory if it exists if os.path.exists(files_dir): log.info("Copying files at: %s", files_dir) target = ConfigParserUtil.get_carbon_home(configuration_context) copy_files_to_pack(files_dir, target) log.info("Configuration completed for template module: %s", file_name) log.info("End of WSO2 Private PaaS Configurator")