def walk_dir_add_magic_tag_to_files(some_path, pattern = '*.go'): for root, dirs, files in os.walk(some_path): for filename in fnmatch.filter(files, pattern): if filename.startswith("."): print_error("invalid:" + one_filename ) continue #check magic tag #if yes , continue #else read content then add tag #backup original file and create new file file_path = os.path.join(root, filename) if sub_gene_comm.check_is_go_file_have_meta_flag( file_path ): continue all_file_conent = "" contents_list = comm_funcs.get_file_content_as_list( file_path ) all_original_code = "" line_num = 0 for line in contents_list: if 0 == line_num: line_num = line_num + 1 continue line_num = line_num + 1 all_original_code = all_original_code + line all_file_conent = all_file_conent + contents_list[0] + "\n" # add empty line all_file_conent = all_file_conent + "\n" all_file_conent = all_file_conent + GoTemplateMagicSecondLine + "\n" all_file_conent = all_file_conent + GoTemplateAutoPartBegin + "\n" all_file_conent = all_file_conent + GoTemplateAutoPartEnd + "\n" all_file_conent = all_file_conent + GoTemplateCustomPartBegin + "\n" all_file_conent = all_file_conent + all_original_code all_file_conent = all_file_conent + GoTemplateCustomPartEnd + "\n" sub_gene_comm.backup_go_file_in_curr_dir_and_touch_new_one( file_path ) comm_funcs.add_to_exist_file( file_path , all_file_conent )
def generate_apiwebmodule_show_file(profile_instance, model_domain): """ apiwebmodule """ print_ok("begin save to apiwebmodule") FullPathApiWebModuleFile = godroid_helper.get_apiwebmodule_file_name_full_path( profile_instance, model_domain) contents_list = comm_funcs.get_file_content_as_list( FullPathApiWebModuleFile) part_one = __self_call_get_package(contents_list) #---- begin part_begin = sub_gene_comm.GoTemplateAutoPartBegin part_package_import = ____self_call_get_imports(profile_instance, model_domain) part_curd = ____self_call_get_curds(profile_instance, model_domain) part_end = sub_gene_comm.GoTemplateAutoPartEnd #---- end part_auto_full = part_begin + "\n" + part_package_import + "\n" + part_curd + "\n" + part_end part_custom = __self_call_get_custom_part(contents_list) all_file_conent = part_one + "\n" + part_auto_full + "\n" + part_custom sub_gene_comm.backup_go_file_in_curr_dir_and_touch_new_one( FullPathApiWebModuleFile) comm_funcs.add_to_exist_file(FullPathApiWebModuleFile, all_file_conent) pass
def generate_funcs_of_gorp_file(profile_instance, model_domain): FullPathFuncsOfGorpFile = godroid_helper.get_model_funcs_of_gorp_file_name_full_path( profile_instance, model_domain) contents_list = comm_funcs.get_file_content_as_list( FullPathFuncsOfGorpFile) part_one = __self_call_get_package(contents_list) comm_funcs.print_ok("gorp funcs part one:" + part_one) # part_begin = sub_gene_comm.GoTemplateAutoPartBegin # part_two = __self_call_get_import(contents_list, profile_instance, model_domain) part_three = __self_call_get_class_def(contents_list, profile_instance) part_four = __self_call_get_func_for_sql_tri_pairs(contents_list, profile_instance) part_five = __self_call_get_gorp_map(contents_list, profile_instance) # part_end = sub_gene_comm.GoTemplateAutoPartEnd # part_six = __self_call_get_custom_part(contents_list) all_file_conent = part_one + "\n" + part_begin + "\n" + part_two + "\n" + part_three + "\n" + part_four + "\n" + part_five + "\n" + part_end + "\n" + part_six sub_gene_comm.backup_go_file_in_curr_dir_and_touch_new_one( FullPathFuncsOfGorpFile) comm_funcs.print_ok("begin save to gorp:" + FullPathFuncsOfGorpFile) comm_funcs.add_to_exist_file(FullPathFuncsOfGorpFile, all_file_conent) pass
def generate_revelcurdfuncs_show_file(profile_instance, model_domain): """ revelcurdfuncs """ print_ok("begin save to revelcurdfuncs") FullPathRevelCurdFuncsFile = godroid_helper.get_revelcurdfuncs_file_name_full_path( profile_instance, model_domain) contents_list = comm_funcs.get_file_content_as_list( FullPathRevelCurdFuncsFile) part_one = __self_call_get_package(contents_list) #---- begin part_begin = sub_gene_comm.GoTemplateAutoPartBegin part_package_import = ____self_call_get_imports(profile_instance, model_domain) part_curd = ____self_call_get_curds(profile_instance, model_domain) part_end = sub_gene_comm.GoTemplateAutoPartEnd #---- end part_auto_full = part_begin + "\n" + part_package_import + "\n" + part_curd + "\n" + part_end part_custom = __self_call_get_custom_part(contents_list) part_custom = part_custom.replace("CLASSNAME", profile_instance.ClassName) all_file_conent = part_one + "\n" + part_auto_full + "\n" + part_custom sub_gene_comm.backup_go_file_in_curr_dir_and_touch_new_one( FullPathRevelCurdFuncsFile) comm_funcs.add_to_exist_file(FullPathRevelCurdFuncsFile, all_file_conent)
def generate_api_file(profile_instance, model_domain): """ first , save contents which outside of meta flag then , generate new content third , combine them and generate new file """ FullPathApiFile = godroid_helper.get_api_file_name_full_path( profile_instance, model_domain) contents_list = comm_funcs.get_file_content_as_list(FullPathApiFile) part_one = __self_call_get_package(contents_list) comm_funcs.print_ok("api part one:" + part_one) part_begin = sub_gene_comm.GoTemplateAutoPartBegin part_two = __self_call_get_stands_methods(profile_instance, model_domain) #() part_three = "" #(profile_instance, model_domain) part_four = "" part_five = "" part_end = sub_gene_comm.GoTemplateAutoPartEnd part_six = __self_call_get_custom_part(contents_list) all_file_conent = part_one + "\n" + part_begin + "\n" + part_two + "\n" + part_three + "\n" + part_four + "\n" + part_five + "\n" + part_end + "\n" + part_six sub_gene_comm.backup_go_file_in_curr_dir_and_touch_new_one(FullPathApiFile) comm_funcs.print_ok("begin save to api:" + FullPathApiFile) comm_funcs.add_to_exist_file(FullPathApiFile, all_file_conent) pass
def generate_controller_show_file(profile_instance, model_domain): comm_funcs.print_ok("begin save to controllers") FullPathControllerFile = godroid_helper.get_controller_file_name_full_path( profile_instance, model_domain) contents_list = comm_funcs.get_file_content_as_list(FullPathControllerFile) part_one = __self_call_get_package(contents_list) comm_funcs.print_ok("controller part one:" + part_one) #---- begin part_begin = sub_gene_comm.GoTemplateAutoPartBegin part_package_import = __self_call_get_packages_part( profile_instance, model_domain) part_curd = __self_call_get_CURD_part(profile_instance, model_domain) part_auto_empty_test = __self_call_get_auto_empty_test_part( profile_instance, model_domain) part_end = sub_gene_comm.GoTemplateAutoPartEnd #---- end part_auto_full = part_begin + "\n" + part_package_import + "\n" + part_curd + "\n" + part_auto_empty_test + "\n" + part_end part_custom = __self_call_get_custom_part(contents_list) all_file_conent = part_one + "\n" + part_auto_full + "\n" + part_custom sub_gene_comm.backup_go_file_in_curr_dir_and_touch_new_one( FullPathControllerFile) comm_funcs.add_to_exist_file(FullPathControllerFile, all_file_conent) pass
def touch_and_create_empty_controller_file(file_full_path, profile_instance): """ controllers alwayz is controllers """ comm_funcs.touch(file_full_path) template_lines = sub_gene_comm.GoEmptyFileTemplate template_lines = template_lines.replace( "PACKAGENAME", "controllers" ) comm_funcs.add_to_exist_file(file_full_path, template_lines) pass
def touch_and_create_revelcurdfuncs_file(file_full_path, profile_instance): """ package curdfuncs """ comm_funcs.touch(file_full_path) template_lines = sub_gene_comm.GoEmptyFileTemplate template_lines = template_lines.replace( "PACKAGENAME", "curdfuncs" ) comm_funcs.add_to_exist_file(file_full_path, template_lines) pass
def generate_model_class_file(profile_instance, model_domain): FullPathModelFile = godroid_helper.get_model_class_file_name_full_path(profile_instance, model_domain) contents_list = comm_funcs.get_file_content_as_list( FullPathModelFile ) part_one = __self_call_get_package(contents_list) comm_funcs.print_ok( "class part one:" + part_one ) #---- begin part_begin = sub_gene_comm.GoTemplateAutoPartBegin part_two = __self_call_get_table_name_const(contents_list, profile_instance) part_three = __self_call_get_class(profile_instance) part_four = __self_call_get_GetColumnsMap(profile_instance) part_five = __self_call_get_GetGorpRenameMap(profile_instance) part_end = sub_gene_comm.GoTemplateAutoPartEnd #---- end part_six = __self_call_get_custom_part(contents_list) all_file_conent = part_one + "\n" + part_begin + "\n" + part_two + "\n" + part_three + "\n" + part_four + "\n" + part_five + "\n" + part_end + "\n" + part_six sub_gene_comm.backup_go_file_in_curr_dir_and_touch_new_one( FullPathModelFile ) comm_funcs.add_to_exist_file( FullPathModelFile , all_file_conent ) pass
def touch_and_create_empty_file(file_full_path, profile_instance): """ by default , should check 3 files : model , funcs of gorp and api the name of each file should not changed check include: 1. magic header package xxxx //magic version: xxxx generatedby: xxxx 2. //meta flag begin //meta flag end """ #touch #create empty file with meta flags comm_funcs.touch(file_full_path) template_lines = sub_gene_comm.GoEmptyFileTemplate template_lines = template_lines.replace( "PACKAGENAME", profile_instance.PackageName ) comm_funcs.add_to_exist_file(file_full_path, template_lines)
if os.path.exists(debug_conf_routes): os.remove(debug_conf_routes) # step two print "step2 : touch a new conf file" # step theree print "step 3 : generate self header ( copy from prebuild-conf ) " self_header_lines = extract_self_headers( prebuild_conf_debug_conf_routes_file) common_part_lines = extract_common_part( prebuild_conf_debug_conf_routes_file) self_part_lines = extract_self_part( prebuild_conf_instance_conf_routes_file) all_lines = self_header_lines + "\n" + common_part_lines + "\n" + self_part_lines + "\n" print "step 4: write to " os.system("touch " + debug_conf_routes) comm_funcs.add_to_exist_file(debug_conf_routes, all_lines) pass if "rollback" == direction: self_header_lines = extract_self_headers( prebuild_conf_instance_conf_routes_file) common_part_lines = extract_common_part(debug_conf_routes) self_part_lines = extract_self_part(debug_conf_routes) all_lines = self_header_lines + "\n" + common_part_lines + "\n" + self_part_lines + "\n" # # os.system("rm -f " + prebuild_conf_instance_conf_routes_file) os.system("touch " + prebuild_conf_instance_conf_routes_file) comm_funcs.add_to_exist_file(prebuild_conf_instance_conf_routes_file, all_lines) # comm_funcs.print_ok("back up each time changing of :" +
def generate_htmlcurl_show_file(profile_instance, model_domain): FullPathApiWebModuleNOFILEJUSTDIR = godroid_helper.get_htmlfunc_instance_full_path( profile_instance, model_domain) if not os.path.exists(FullPathApiWebModuleNOFILEJUSTDIR): comm_funcs.print_ok("api_web_module TIPS:") comm_funcs.print_ok("......create for :" + FullPathApiWebModuleNOFILEJUSTDIR) os.makedirs(FullPathApiWebModuleNOFILEJUSTDIR) else: if len(FullPathApiWebModuleNOFILEJUSTDIR) > 0: print_error(" remove all html file in dir :" + FullPathApiWebModuleNOFILEJUSTDIR + "/*.html") comm_funcs.remove_all_html_files_in_dir( FullPathApiWebModuleNOFILEJUSTDIR + "/*.html ") print_ok(" generate new ") tmp_comm_file = FullPathApiWebModuleNOFILEJUSTDIR + "/new.html" sub_gene_comm.touch_new_file(tmp_comm_file) content = __self_call_generate_file_new(profile_instance, model_domain) comm_funcs.add_to_exist_file(tmp_comm_file, content) print_ok(" generate save new ") tmp_comm_file = FullPathApiWebModuleNOFILEJUSTDIR + "/save_new.html" sub_gene_comm.touch_new_file(tmp_comm_file) content = __self_call_generate_file_save_new(profile_instance, model_domain) comm_funcs.add_to_exist_file(tmp_comm_file, content) print_ok(" generate m_new ") tmp_comm_file = FullPathApiWebModuleNOFILEJUSTDIR + "/m_new.html" sub_gene_comm.touch_new_file(tmp_comm_file) content = __self_call_generate_file_m_new(profile_instance, model_domain) comm_funcs.add_to_exist_file(tmp_comm_file, content) print_ok(" generate edit ") tmp_comm_file = FullPathApiWebModuleNOFILEJUSTDIR + "/edit.html" sub_gene_comm.touch_new_file(tmp_comm_file) content = __self_call_generate_file_edit(profile_instance, model_domain) comm_funcs.add_to_exist_file(tmp_comm_file, content) print_ok(" generate save edit ") tmp_comm_file = FullPathApiWebModuleNOFILEJUSTDIR + "/save_edit.html" sub_gene_comm.touch_new_file(tmp_comm_file) content = __self_call_generate_file_save_edit(profile_instance, model_domain) comm_funcs.add_to_exist_file(tmp_comm_file, content) print_ok(" generate show ") tmp_comm_file = FullPathApiWebModuleNOFILEJUSTDIR + "/show.html" sub_gene_comm.touch_new_file(tmp_comm_file) content = __self_call_generate_file_show(profile_instance, model_domain) comm_funcs.add_to_exist_file(tmp_comm_file, content) print_ok(" generate m_show ") tmp_comm_file = FullPathApiWebModuleNOFILEJUSTDIR + "/m_show.html" sub_gene_comm.touch_new_file(tmp_comm_file) content = __self_call_generate_file_m_show(profile_instance, model_domain) comm_funcs.add_to_exist_file(tmp_comm_file, content) print_ok(" generate delete ") tmp_comm_file = FullPathApiWebModuleNOFILEJUSTDIR + "/delete.html" sub_gene_comm.touch_new_file(tmp_comm_file) content = __self_call_generate_file_delete(profile_instance, model_domain) comm_funcs.add_to_exist_file(tmp_comm_file, content) #print_ok(" generate save delete ") #tmp_comm_file = FullPathApiWebModuleNOFILEJUSTDIR + "/save_delete.html" #sub_gene_comm.touch_new_file( tmp_comm_file ) #content = __self_call_generate_file_save_delete(profile_instance, model_domain) #comm_funcs.add_to_exist_file( tmp_comm_file , content ) print_ok(" generate remove ") tmp_comm_file = FullPathApiWebModuleNOFILEJUSTDIR + "/remove.html" sub_gene_comm.touch_new_file(tmp_comm_file) content = __self_call_generate_file_remove(profile_instance, model_domain) comm_funcs.add_to_exist_file(tmp_comm_file, content) #print_ok(" generate save remove ") #tmp_comm_file = FullPathApiWebModuleNOFILEJUSTDIR + "/save_remove.html" #sub_gene_comm.touch_new_file( tmp_comm_file ) #content = __self_call_generate_file_save_remove(profile_instance, model_domain) #comm_funcs.add_to_exist_file( tmp_comm_file , content ) print_ok(" generate list ") tmp_comm_file = FullPathApiWebModuleNOFILEJUSTDIR + "/list.html" sub_gene_comm.touch_new_file(tmp_comm_file) content = __self_call_generate_file_list(profile_instance, model_domain) comm_funcs.add_to_exist_file(tmp_comm_file, content) print_ok(" generate index ") tmp_comm_file = FullPathApiWebModuleNOFILEJUSTDIR + "/index.html" sub_gene_comm.touch_new_file(tmp_comm_file) content = __self_call_generate_file_index(profile_instance, model_domain) comm_funcs.add_to_exist_file(tmp_comm_file, content) print_ok(" generate m_list ") tmp_comm_file = FullPathApiWebModuleNOFILEJUSTDIR + "/m_list.html" sub_gene_comm.touch_new_file(tmp_comm_file) content = __self_call_generate_file_m_list(profile_instance, model_domain) comm_funcs.add_to_exist_file(tmp_comm_file, content) pass
""" print "step 1 : delete DEBUG routes : " , debug_conf_routes if os.path.exists( debug_conf_routes ): os.remove( debug_conf_routes ) # step two print "step2 : touch a new conf file" # step theree print "step 3 : generate self header ( copy from prebuild-conf ) " self_header_lines = extract_self_headers( prebuild_conf_debug_conf_routes_file ) common_part_lines = extract_common_part( prebuild_conf_debug_conf_routes_file ) self_part_lines = extract_self_part( prebuild_conf_instance_conf_routes_file ) all_lines = self_header_lines + "\n" + common_part_lines + "\n" + self_part_lines + "\n" print "step 4: write to " os.system( "touch " + debug_conf_routes ) comm_funcs.add_to_exist_file( debug_conf_routes , all_lines ) pass if "rollback" == direction: self_header_lines = extract_self_headers( prebuild_conf_instance_conf_routes_file ) common_part_lines = extract_common_part( debug_conf_routes ) self_part_lines = extract_self_part( debug_conf_routes ) all_lines = self_header_lines + "\n" + common_part_lines + "\n" + self_part_lines + "\n" # # os.system( "rm -f " + prebuild_conf_instance_conf_routes_file ) os.system( "touch " + prebuild_conf_instance_conf_routes_file ) comm_funcs.add_to_exist_file( prebuild_conf_instance_conf_routes_file , all_lines ) # comm_funcs.print_ok( "back up each time changing of :" + debug_conf_routes); unique_file_name = str( time.time() ) + "_routes.bak" comm_funcs.print_ok( unique_file_name )