def main(): init() get_pngs(TARGET_PATH) dic = {} for path in FILE_PATHS: if path.endswith('html'): continue md5_digest = md5(path) parent_path, filename = os.path.split(path) f_name, suffix = os.path.splitext(filename) new_file_name = md5_digest + suffix new_file_name_path = os.path.join(parent_path, new_file_name) if not os.path.exists(new_file_name_path): os.rename(path, new_file_name_path) relpath = os.path.relpath(path, TARGET_PATH) md5_relpath = os.path.relpath(new_file_name_path, TARGET_PATH) dic[relpath.replace('\\', '/')] = md5_relpath.replace('\\', '/') write_file(json.dumps(dic), os.path.join(MANIFEST_PATH, 'manifest_{ts}.json'.format(ts=str(int(time.time()))))) if INDEX_HTMl_PATH: replace(INDEX_HTMl_PATH, '{{MANIFEST}}', json.dumps(dic))
def entry(): manifest = [] # 处理EXCEl begin = getCurMillSecond() for file_path in config.EXCEL_FILE_NAMES: print("start process:" + file_path) file_type = get_file_type(file_path) if file_type == "xlsx": t = get_ds_from_excel(file_path=file_path) elif file_type == "csv": t = get_ds_from_csv(file_path=file_path) if t is None: continue process_dt(t) manifest.append(t.table_name) print "process success:" + file_path end = getCurMillSecond() print("cost:" + str(end - begin)) print("------------------------>end") all_json_content["cfg_robotname"] = "" all_json_content["cfg_robot"] = "" if config.TARGET_PATHS: for path in config.TARGET_PATHS: write_file(json.dumps(all_json_content, separators=(',', ':')), os.path.join(path, "config.json")) if config.AS3_CLAZZ_TARGET_PATHS: for path in config.AS3_CLAZZ_TARGET_PATHS: write_file(render_manifest(manifest), os.path.join(path, 'manifest.as')) print "{len} documents were processed this time".format(len=len(manifest))
def entry(): manifest = [] # 处理EXCEl begin = getCurMillSecond() # 处理EXCEl for file_path in EXCEL_FILE_NAMES: try: sheets = process_xlsx(file_path=file_path) except Exception as e: raise e print("process error:" + file_path) manifest.extend(sheets) print "process success:" + file_path end = getCurMillSecond() print("cost:" + str(end - begin)) print("------------------------>end") all_json_content["cfg_robotname"] = "" all_json_content["cfg_robot"] = "" if TARGET_PATHS: for path in TARGET_PATHS: write_file(json.dumps(all_json_content, separators=(',', ':')), os.path.join(path, "config.json")) # 导出配表到product文件夹,用于jenkins发布 write_file(json.dumps(all_json_content, separators=(',', ':')), os.path.join(PRODUCT_PATH, "config.json")) if AS3_CLAZZ_TARGET_PATHS: for path in AS3_CLAZZ_TARGET_PATHS: write_file(render_manifest(manifest), os.path.join(path, 'manifest.as')) print '\n--------------------------------------------------------------------' print "{len} documents were processed this time".format(len=len(manifest))
def process_xlsx(file_path): # begin = getCurMillSecond() wb = xlrd.open_workbook(file_path) # end = getCurMillSecond() # print("cost confusion_json:" + str(end - begin)) sheets = [] for s in wb.sheets(): sheet_name = s.name # 跳过测试页面 if not sheet_name.startswith("cfg") and not sheet_name.startswith( "s_cfg"): continue is_server_only = False if sheet_name.startswith("s_cfg"): is_server_only = True sheet_name = sheet_name[2:] sheets.append(sheet_name) # 处理表格 client_content, server_content = process_sheet(s) field_mate = process_sheet_metadata(s) # 混淆代码 confusion_data, confusion_meta = confusion_json( client_content, field_mate) if not is_server_only: all_json_content[sheet_name] = confusion_data # 导出服务端lua数据 if SERVER_PATH: lua_file_name = os.path.join( SERVER_PATH, '{file_name}.lua'.format(file_name=sheet_name)) write_file(render_lua(server_content, field_mate), lua_file_name) # 导出服务端PY数据 if PY_SERVER_PATH: py_file_name = os.path.join( PY_SERVER_PATH, '{file_name}.py'.format(file_name=sheet_name)) write_file(render_py(server_content, field_mate), py_file_name) # 导出服务端JSON数据 if JSON_SERVER_PATH: json_file_name = os.path.join( JSON_SERVER_PATH, '{file_name}.json'.format(file_name=sheet_name)) write_file(server_content, json_file_name) # 导出JSON数据,用于检查表冲突 # json_file_name2 = os.path.join(CACHE_JSON_PATH, '{file_name}.json'.format(file_name=sheet_name)) # write_file(server_content, json_file_name2) if not is_server_only: # 导出AS3配表对象 for path in AS3_CLAZZ_TARGET_PATHS: as3_file_path = os.path.join( path, "{file_name}.as".format(file_name=sheet_name)) if IS_LANG_TEMPLATE: write_file( str_to_as3_class_lang(confusion_meta, CONFIG_MANAGER_PATH), as3_file_path) else: write_file( str_to_as3_class(confusion_meta, CONFIG_MANAGER_PATH), as3_file_path) wb.release_resources() return sheets
def process_dt(t): client_obj = t.to_json("c") server_obj = t.to_json("s") all_obj = t.to_all_json() server_field_mate = t.field_meta("s") client_field_mate = t.field_meta("c") # 混淆代码 confusion_data, confusion_meta = confusion_json(client_obj, client_field_mate) if not t.is_server_only(): all_json_content[t.table_name] = confusion_data # 导出服务端lua数据 会改变server_obj,这里需要copy一个来导出 if config.JSON_SERVER_PATH: json_file_name = os.path.join( config.JSON_SERVER_PATH, '{file_name}.json'.format(file_name=t.table_name)) write_file(json.dumps(all_obj), json_file_name) # 导出服务端lua数据 # 2020-1-9导出服务端lua数据 会改变server_obj,这里需要copy一个来导出 if config.SERVER_PATH: lua_file_name = os.path.join( config.SERVER_PATH, '{file_name}.lua'.format(file_name=t.table_name)) write_file(render_lua(server_obj.copy(), server_field_mate), lua_file_name) if not t.is_server_only(): # 导出AS3配表对象 for path in config.AS3_CLAZZ_TARGET_PATHS: as3_file_path = os.path.join( path, "{file_name}.as".format(file_name=t.table_name)) if config.IS_FUNK_TEMPLATE: if config.IS_LANG_TEMPLATE: write_file( str_to_as3_class_funk_lang(confusion_meta, config.CONFIG_MANAGER_PATH), as3_file_path) else: write_file( str_to_as3_class_funk(confusion_meta, config.CONFIG_MANAGER_PATH), as3_file_path) else: if config.IS_LANG_TEMPLATE: write_file( str_to_as3_class_lang(confusion_meta, config.CONFIG_MANAGER_PATH), as3_file_path) else: write_file( str_to_as3_class(confusion_meta, config.CONFIG_MANAGER_PATH), as3_file_path)
def entry(): manifest = [] # 处理EXCEl begin = getCurMillSecond() for file_path in config.EXCEL_FILE_NAMES: print("start process:" + file_path) file_type = get_file_type(file_path) if file_type == "xlsx": t = get_ds_from_excel(file_path=file_path) elif file_type == "csv": t = get_ds_from_csv(file_path=file_path) if t is None: continue process_dt(t) manifest.append(t.table_name) print "process success:" + file_path end = getCurMillSecond() print("cost:" + str(end - begin)) print("------------------------>end") all_json_content["cfg_robotname"] = "" all_json_content["cfg_robot"] = "" if config.TARGET_PATHS: if config.FIRST_CONFIG: child_first_leaf = {} child_second_leaf = {} first_config = {} for name in config.FIRST_CONFIG: first_config[name] = "" for path in config.TARGET_PATHS: for cfgName in all_json_content: if first_config.has_key(cfgName): print("first json file contents: ", cfgName) child_first_leaf[cfgName] = all_json_content[cfgName] else: child_second_leaf[cfgName] = all_json_content[cfgName] write_file(json.dumps(child_first_leaf, separators=(',', ':')), os.path.join(path, "first_config.json")) write_file(json.dumps(child_second_leaf, separators=(',', ':')), os.path.join(path, "second_config.json")) # 无论是否分表都导出单表 for path in config.TARGET_PATHS: write_file(json.dumps(all_json_content, separators=(',', ':')), os.path.join(path, "config.json")) if config.AS3_CLAZZ_TARGET_PATHS: for path in config.AS3_CLAZZ_TARGET_PATHS: write_file(render_manifest(manifest), os.path.join(path, 'manifest.as')) if config.UNITY_PATH: for path in config.UNITY_PATH: write_file(render_unity_manifest(manifest), os.path.join(path, 'init_table.lua')) print "{len} documents were processed this time".format(len=len(manifest))