def generate_template(temp_dir, temp_path, out_dir, out_path, all_content_script=None): gen_in_path = os.path.join(temp_dir, temp_path) gen_out_path = os.path.join(install_abs_prefix, out_dir, out_path) if os.path.exists(gen_in_path): project.render_to(temp_path, gen_out_path, project_install_prefix=os.path.relpath( '.', os.path.join(install_prefix, out_dir)), **ext_options) if all_content_script is not None and all_content_script in all_service_temps: all_service_temps[all_content_script]['content'].append(""" # ==================== {0} ==================== if [ $# -eq 0 ] || [ "0" == "$(is_in_server_list {1} $*)" ]; then bash {2} fi """.format( project.get_server_full_name(), project.get_server_full_name(), os.path.relpath(gen_out_path, script_dir) ))
mat_res = custom_global_rule.match(rule_data) if mat_res is None: common.print_color.cprintf_stderr([ common.print_color.print_style.FC_RED, common.print_color.print_style.FW_BOLD ], '"{0}" is not a valid global rule.\r\n', rule_line) continue tmpl_src = mat_res.group('SRC').strip() tmpl_dst = mat_res.group('DST').strip() if not tmpl_src or not tmpl_dst: continue gen_out_path = os.path.join(project_install_abs_path, tmpl_dst) project.render_to(tmpl_src, gen_out_path, project_install_prefix=os.path.relpath( project_install_abs_path, os.path.dirname(gen_out_path))) for all_svr_temp in all_service_temps: all_temp_cfg = all_service_temps[all_svr_temp] if 'reverse' in all_temp_cfg and all_temp_cfg['reverse']: all_temp_cfg['content'].reverse() open(all_temp_cfg['out'], mode='a').write(os.linesep.join(all_temp_cfg['content'])) common.print_color.cprintf_stdout([ common.print_color.print_style.FC_YELLOW, common.print_color.print_style.FW_BOLD ], 'all jobs done.\r\n')
for rule_line in rules_data.splitlines(): rule_data = rule_line.strip() if not rule_data: continue if rule_data[0:1] == "#" or rule_data[0:1] == ";": continue mat_res = custom_global_rule.match(rule_data) if mat_res is None: common.print_color.cprintf_stderr( [common.print_color.print_style.FC_RED, common.print_color.print_style.FW_BOLD], '"{0}" is not a valid global rule.\r\n', rule_line) continue tmpl_src = mat_res.group('SRC').strip() tmpl_dst = mat_res.group('DST').strip() if not tmpl_src or not tmpl_dst: continue gen_out_path = os.path.join(project_install_abs_path, tmpl_dst) project.render_to(tmpl_src, gen_out_path, project_install_prefix=os.path.relpath(project_install_abs_path, os.path.dirname(gen_out_path)) ) for all_svr_temp in all_service_temps: all_temp_cfg = all_service_temps[all_svr_temp] if 'reverse' in all_temp_cfg and all_temp_cfg['reverse']: all_temp_cfg['content'].reverse() open(all_temp_cfg['out'], mode='a').write(os.linesep.join(all_temp_cfg['content'])) common.print_color.cprintf_stdout( [common.print_color.print_style.FC_YELLOW, common.print_color.print_style.FW_BOLD], 'all jobs done.\r\n')