def test_replace_string_in_file(self): test_name = 'gbk.txt' ori_data = '这是一个文件,用于进行测试。what are you doing.' file_name = myfile.get_real_dir(__modpath__) + os.sep + test_name expect_data = ori_data file_data = myfile.read_file_content(file_name) msg_format = 'expecte {0}, but {1}' self.assertEqual(expect_data, file_data, msg_format.format(expect_data, file_data)) enc_result = myfile.detect_file_enc(file_name) expect_data = 'gb2312' encoding = enc_result['encoding'].lower() self.assertEqual(expect_data, encoding, msg_format.format(expect_data, encoding)) src_dst_list = list(zip(['what'], ['F**k'])) enc_result = myfile.replace_string_in_file(file_name, src_dst_list) expect_data = '这是一个文件,用于进行测试。F**k are you doing.' file_data = myfile.read_file_content(file_name) self.assertEqual(expect_data, file_data, msg_format.format(expect_data, file_data)) enc_result = myfile.detect_file_enc(file_name) expect_data = 'gb2312' encoding = enc_result['encoding'].lower() self.assertEqual(expect_data, encoding, msg_format.format(expect_data, encoding)) myfile.write_to_file(file_name, ori_data, encoding)
def _update_json_file(self): src = open(self.file_path, encoding='utf-8') with src: obj = json.load(src) if self.is_pure: src_obj = obj else: src_obj = obj["interface"] src_obj = self._sort_array(src_obj) # src_obj.sort(key=self._cmp_item) if src_obj: # output = json.dumps(src_obj, ensure_ascii=False, sort_keys=True, indent=4) # output = re.sub('("describe":\s*"[^"]*")(\s*,\s+)("id":\s*"[^"]*")(\s*,)', self._replace_ptn, output) output = self._join_array(src_obj) # print(output) if not self.is_pure: src_content = myfile.read_file_content(self.file_path) self.array_str = output output = re.sub('("interface":\s*)(\[[^\]]*\])', self._replace_dst_ptn, src_content) # print('-' * 120) # print(output) myfile.write_to_file(self.file_path, output, 'utf-8')
def process(self): if self.to_update: # 先进行代码更新操作 git_util.revert(self.git_root) git_util.update(self.git_root, None, self.branch) if not self.ver_name: setup_content = file_util.read_file_content(self.setup_path) self.ver_name = self._get_version_name(setup_content) # 先校验设置的版本格式是否正确 if not self.is_valid_version(self.ver_name): raise Exception(f'the verion {self.ver_name} is invalid!') self.main_ver = self.get_main_version(self.ver_name) is_updated = self.update_module_version(self.ver_name) if is_updated: print(f'updated version name with {self.ver_name}.') else: print(f'remain version name as {self.ver_name}.') if self.to_clean: self.clean_builds() if self.to_build: self.build_wheel() if self.to_upload: self.upload_to_pypi() if self.to_commit: self.commit_to_repo()
def update_module_version(self, version): setup_content = file_util.read_file_content(self.setup_path) self.module_name = self._get_module_name(setup_content) if not self.module_name: raise Exception('to get module name failed!') return self.update_setup_version(self.setup_path, version)
def get_cardbin_info_with_json_format(self): # 先将原始lua文件读进来,并存储关键信息便于接下来进处理 self.content = myfile.read_file_content(self.file_path, encoding_='utf-8') # 获取原始cardbin信息 self.ori_card_info = self._get_card_info(self.content) # print(self.ori_card_info) # 转换成正常的json格式代码,先保留,后续有需要再使用 # dst_array = [] # for i in self.ori_card_info: # item = {} # for k in i: # if i[k]: # item[SIMPLIFY_MAP[k]] = i[k] # dst_array.append(item) # if with_format: # json_str = json.dumps(dst_array, ensure_ascii=False, sort_keys=True, indent=4) # else: # json_str = json.dumps(dst_array, ensure_ascii=False) json_str = self._generate_card_info_table_with_js_format( self.ori_card_info) myfile.write_to_file(self.dst_path, json_str, encoding='utf-8')
def parse(self): doc = xmltodict.parse(file_util.read_file_content(self.config_path)) root = doc[SourceConfigParser.CONFIG_FLAG] base_url_items = root[SourceConfigParser.BASE_URL_FLAG][ SourceConfigParser._BASE_FLAG] # 获取基址 base_urls = {} for item in base_url_items: base_urls[item[SourceConfigParser.NAME_FLAG]] = item[ SourceConfigParser.VALUE_FLAG] self.base_urls = base_urls # 获取相对地址 relative_url_items = root[SourceConfigParser._RELATIVE_URL_FLAG][ SourceConfigParser._RELATIVE_FLAG] url_info = {} for item in relative_url_items: map_info = {} map_info[SourceConfigParser.URL_FLAG] = self.base_urls[item[ SourceConfigParser._BASE_FLAG]] + '/' + item[ SourceConfigParser.NAME_FLAG] map_info[SourceConfigParser.TYPE_FLAG] = item[ SourceConfigParser.TYPE_FLAG] url_info[item[SourceConfigParser.NAME_FLAG]] = map_info self.url_info = url_info
def __init__(self, src_root): self.work_path = os.path.abspath(src_root) sftp_config_path = ['config', 'base', 'sftp_config.xml'] sftp_config_path = os.sep.join(sftp_config_path) self.sftp_config_path = self.work_path + os.sep + sftp_config_path # 解析配置 doc = xmltodict.parse(file_util.read_file_content(self.sftp_config_path)) self.data = doc[SFTPConfigFile.CONFIG_FLAG]
def parse(self): doc = xmltodict.parse(myfile.read_file_content(self.config_path)) root = doc[ChanInfoParser.CONFIG_FLAG] items = root[ChanInfoParser.ITEM_FLAG] for item in items: self.result[item[ChanInfoParser.NAME_FLAG]] = None
def process(self): content = myfile.read_file_content(self.src, encoding_='utf-8') # content = open(self.src).read().decode('gb18030', 'ignore') # content = myfile.read_file_content(self.src) print(content) content = content.replace('\t', '|') content = content.replace('\r\n', '|\r\n|') content = '|' + content + '|' myfile.write_to_file(self.src, content, encoding='utf-8')
def test_read_file_content(self): # GB2312 编码格式文件验证 ori_content = '这只是一个测试文件。' test_name = r'for_test.txt' file_name = myfile.get_real_dir(__modpath__) + os.sep + test_name readed_content = myfile.read_file_content(file_name) msg_format = 'expecte {0}, but {1}' self.assertEqual(ori_content, readed_content, msg_format.format(ori_content, readed_content)) # UTF8 with BOM 编码格式文件验证 ori_content = 'utf-8-sig及中文验证;' test_name = r'utf_8_sig.txt' file_name = myfile.get_real_dir(__modpath__) + os.sep + test_name readed_content = myfile.read_file_content(file_name) msg_format = 'expecte {0}, but {1}' self.assertEqual(ori_content, readed_content, msg_format.format(ori_content, readed_content))
def update_setup_version(self, file_path, version): # example: version='0.0.2' re_ptn = '(version\s*=\s*[\'\"])([^\'\"]*)([\'\"])' src_data = file_util.read_file_content(file_path) new_data = re.sub(re_ptn, '\g<1>{}\g<3>'.format(version), src_data) if new_data != src_data: file_util.write_to_file(file_path, new_data, 'utf-8') return True else: return False
def update_init_version(self, file_path, version): # example: version_info = (0, 0, 9) re_ptn = '(version_info\s*=\s*\()(\d+(?:,\s*\d+){2})(\))' src_data = file_util.read_file_content(file_path) target_version = ', '.join(re.split('\.\s*', version)) new_data = re.sub(re_ptn, f'\g<1>{target_version}\g<3>', src_data) if new_data != src_data: file_util.write_to_file(file_path, new_data, 'utf-8') return True else: return False
def __init__(self, config_path): self.config_path = config_path self.config_data = myfile.read_file_content(self.config_path) self.config_modified = False env_ptn = re.compile(EnvironmentUpdater.CONFIG_PATTERN, flags=(re.M)) config_match = env_ptn.search(self.config_data) if config_match: self.config = config_match.group(2) else: self.config = ''
def test_write_to_file(self): content = "info to write" dst_name = r'file_output.txt' dst_file = myfile.get_real_dir(__modpath__) + os.sep + dst_name myfile.write_to_file(dst_file, content) readed_content = myfile.read_file_content(dst_file) msg_format = 'expecte {0}, but {1}' self.assertEqual(content, readed_content, msg_format.format(content, readed_content))
def _get_code_api_ver(self, file_path, target_key): file_data = file_util.read_file_content(file_path) ptn_str_format = '({}\s*=\s*)([^\s]*)' ptn_str = ptn_str_format.format(target_key) ptn = re.compile(ptn_str, flags=(re.I | re.M)) result = ptn.search(file_data) if result: return result.group(2) else: return None
def update_coverage_switch(self, env_mode): file_path = os.path.join(self.prj_path, 'build.gradle') content = file_util.read_file_content(file_path, 'utf-8') coverage_label = 'testCoverageEnabled' ptn_str = '({}\s*=\s*)\w+(\s+)'.format(coverage_label) ptn = re.compile(ptn_str, flags=(re.I | re.M)) value = self.info[ProjectBuilder.COVERAGE_FLAG][ ProjectBuilder.COMPILE_FLAG][env_mode] new_content = ptn.sub('\\1{}\\2'.format(value), content) if new_content != content: file_util.write_to_file(file_path, new_content, 'utf-8') print('update {} with value {}.'.format(coverage_label, value)) else: print('{} remain as {}.'.format(coverage_label, value))
def get_exception_info(file_path): begin_tag = '----- Exception Begin -----' end_tag = '----- Exception End -----' FIND_FAILED_INDEX = -1 content = myfile.read_file_content(file_path, encoding_='utf-8') begin = content.find(begin_tag) if begin != FIND_FAILED_INDEX: exception_info = content[begin + len(begin_tag):] end = exception_info.find(end_tag) if end != FIND_FAILED_INDEX: exception_info = exception_info[:end] return exception_info return None
def __init__(self, config_path): self.config_path = config_path self.config_data = myfile.read_file_content(self.config_path) self.config_modified = False ver_code_ptn = re.compile(GradleVerInfoUpdater.VER_CODE_PATTERN, flags=(re.I | re.M)) ver_code_match = ver_code_ptn.search(self.config_data) if ver_code_match: self.version_code = ver_code_match.group(2) else: self.version_code = '' ver_name_ptn = re.compile(GradleVerInfoUpdater.VER_NAME_PATTERN, flags=(re.I | re.M)) ver_name_match = ver_name_ptn.search(self.config_data) if ver_name_match: self.version_name = ver_name_match.group(2) else: self.version_name = ''
def change_podspec_version(self, tag_version, source_path): source_path = git.get_git_root(source_path) file_list = file.get_file_list(source_path) for file_name in file_list: if file_name.endswith('.podspec'): spec_file = os.path.join(source_path, file_name) file_data = file.read_file_content(spec_file) spec_version_line = re.search( r'([a-z]*).version\s+=\s+\W([0-9].+)', file_data).group() new_spec_version_line = re.sub(r'([0-9]\.|[0-9])+', tag_version, spec_version_line) src_dst_list = list( zip([spec_version_line], [new_spec_version_line])) file.replace_string_in_file(spec_file, src_dst_list) try: git.push_to_remote([spec_file], '[other]: 提交{}版本'.format(tag_version), repository=None, refspecs=None, _dir=source_path) git.git_push_tag(source_path, tag_version) except Exception as e: raise Exception(e)
def get_ver_info(filepath): ver_info = file_util.read_file_content(filepath) return ver_info.strip()
def parse(self): doc = xmltodict.parse(file_util.read_file_content(self.config_path)) self.data = doc[BuildConfigLabel.ROOT_FLAG]
def parse(self): doc = xmltodict.parse(myfile.read_file_content(self.config_path)) self.data = doc[BuildConfigParser.ROOT_FLAG]
def process(self): git_flag = 'use_git' if not hasattr(self, git_flag): self.use_git = False # 进行代码更新操作 if self.to_update: code_url = self.app_build_cofig[BuildConfigParser.CODE_URL_FLAG] if self.use_git: self.sftp_config_path = ['config', 'base', 'sftp_config.xml'] self.sftp_config_path = os.sep.join(self.sftp_config_path) self.sftp_config_path = self.work_path + os.sep + self.sftp_config_path doc = xmltodict.parse( myfile.read_file_content(self.sftp_config_path)) sftp_config_data = doc['config'] self.temp_username = sftp_config_data['username'] self.temp_password = sftp_config_data['password'] git.checkout_or_update(self.project_path, code_url, self.code_ver, self.branch) git.revert_temporary(self.project_path) else: # 根据参数配置svn用户名和密码 username_flag = 'svn_user' password_flag = 'svn_pwd' if hasattr(self, username_flag) and hasattr( self, password_flag): # print('{}: {}'.format(username_flag, self.svn_user)) # print('{}: {}'.format(password_flag, self.svn_pwd)) svn.set_user_info(getattr(self, username_flag), getattr(self, password_flag)) svn.checkout_or_update(self.project_path, code_url, self.code_ver) # 获取当前代码版本号 if self.use_git: git_root = git.get_git_root(self.project_path) self.code_ver = git.get_revision(git_root) else: self.code_ver = svn.get_revision(self.project_path) print('current code version is ' + str(self.code_ver)) # 进行版本编译操作 if self.to_build: to_check_vals = ['ver_name', 'ver_code', 'ver_env', 'ver_type'] for name in to_check_vals: value = getattr(self, name) if not value: info = 'Please specify the {}.'.format(name) print(info) exit(1) # 参数非空判断验证通过开始进行正式业务逻辑 self.pro_build_config = self._get_pro_build_config() self.pre_build() self.build(self.pro_build_config) if os.path.isfile(self.ipa_output_path): # 将编译信息写文件 build_info_format = self.ori_build_config[ BuildConfigParser.BUILD_INFO_TEMPLET_FLAG] build_info = build_info_format.format(ver_name=self.ver_name, code_ver=self.code_ver, ver_code=self.ver_code) build_info_path = self.output_directory + os.sep + 'readme-{}-{}.txt'.format( self.ver_name, self.ver_code) myfile.write_to_file(build_info_path, build_info, encoding='utf-8') str_info = 'Build success, current code version is {}.'.format( self.code_ver) print(str_info) else: str_info = 'Build failed, current code version is {}.'.format( self.code_ver) raise Exception(str_info) # 将*.ipa包上传到sftp服务器 if self.to_upload_sftp: doc = ET.parse(self.sftp_config_path) root = doc.getroot() username = root.find('username') username.text = self.temp_username password = root.find('password') password.text = self.temp_password doc.write(self.sftp_config_path) print('----------change it--------') # 复制podfile.lock 到目标文件夹 pods_lock_file = self.pods_path + os.sep + 'Podfile.lock' shutil.copy(pods_lock_file, self.output_directory) # 为防止上传的东西太多,将部分文件打成zip包 print('Archiving data file') tmp_folder = tempfile.mkdtemp() dst_zip_file = self.output_directory + os.sep + '%s_data.zip' % ( self.ipa_name) myfile.process_dir_src_to_dst(self.output_directory, tmp_folder, self.process_func) myzip.zip_dir(tmp_folder, dst_zip_file) shutil.rmtree(tmp_folder) for file in os.listdir(self.output_directory): if os.path.splitext(file)[1] == '.xcarchive': xcarchive_file_path = os.path.join( self.output_directory, file) shutil.rmtree(xcarchive_file_path) sftp.upload_to_sftp(self.work_path, self.ver_name, self.ver_env, self.code_ver, self.app_code, self.output_directory, 'IOS', '', self.ipa_name, self.ipa_name) # 复制文件到document ipa_file_path = self.output_directory + os.sep + self.ipa_name ipa_dir_path = myfile.normalpath('/Users/caifh/Documents/ipa') if os.path.exists(ipa_dir_path): shutil.copy(ipa_file_path, ipa_dir_path) # 更新工程文件 print('更新工程文件') print(self.project_path) new_project_path = self.project_path allfilelist = os.listdir(self.project_path) for file in allfilelist: filepath = os.path.join(self.project_path, file) if os.path.isdir(filepath): new_project_path = myfile.normalpath(filepath) break dst_dir = os.path.abspath(new_project_path) os.chdir(dst_dir) rtn_str = subprocess.check_output( 'git diff --name-only --diff-filter=ACM', shell=True, universal_newlines=True) if rtn_str: info_arr = rtn_str.split('\n') new_info_arr = [] for item in info_arr: if len(item) > 0: new_info_arr.append(item) try: source_path = git.get_git_root(self.project_path) git.push_to_remote(new_info_arr, '[other]: 提交打包版本信息', repository=None, refspecs=None, _dir=source_path) git.revert_temporary(source_path) except Exception as e: raise Exception(e)
def __init__(self, src_path): self.src_path = src_path self.src_data = myfile.read_file_content(self.src_path) self.modify_flag = False
def process(self, new_data): if self.content == None: # 先将原始lua文件读进来,并存储关键信息便于接下来进处理 self.content = myfile.read_file_content(self.file_path, encoding_='utf-8') # 获取银行信息 self.bank_map = self._get_bank_map(self.content) # print(self.bank_map) # 获取银行卡类型信息 self.card_type_map = self._get_card_type_map(self.content) # print(self.card_type_map) self.card_type_map_revert = self._get_revert_map( self.card_type_map) # print(self.card_type_map_revert) # 获取原始cardbin信息 self.ori_card_info = self._get_card_info(self.content) # print(self.ori_card_info) is_consistent = self._verify_cardtype_consistency(new_data) if not is_consistent: raise Exception( '{} and original card type is not consistency!'.format( Label.nature)) # 将新旧两个表合并成最终的表 self.card_info = self._combine_card_info(self.ori_card_info, new_data) # 计算cardbin最大长度 min_len = 3 max_len = 6 curr_min_len, curr_max_len = self._get_max_cardbin_len_range( self.card_info) if curr_min_len < min_len: raise Exception( 'curr_min_len {} is lesser than the expected min_len {}!'. format(curr_max_len, max_len)) if curr_max_len > max_len: raise Exception( 'curr_max_len {} is greater than the expected max_len {}!'. format(curr_max_len, max_len)) # 验证carbin是否存在包含关系,即长的carbin是以短的cardbin开头的(已经验证存在,代码逻辑本身有处理这类情况) # self._check_cardbin_prefix_duplicate(self.card_info) # 生成具体的表数据并更新到文件中 card_info_table_str = self._generate_card_info_table( self.card_info) card_info_index_table_str = self._generate_card_info_index_table( self.card_info) new_content = self._update_card_info(self.content, card_info_table_str) new_content = self._update_card_info_index( new_content, card_info_index_table_str) # for i in self.card_info: # print(i) myfile.write_to_file(self.dst_path, new_content, encoding='utf-8') return True return True
def parse(self): doc = xmltodict.parse(file_util.read_file_content(self.config_path)) self.data = doc[self.root_tag]
def __init__(self, config_path): self.config_path = config_path self.config_data = myfile.read_file_content(self.config_path) self.config_modified = False
def process(self): temp_branch_dict = {} temp_tag_dict = {} if self.branch_dict: temp_branch_dict = ast.literal_eval(self.branch_dict) if self.tag_dict: temp_tag_dict = ast.literal_eval(self.tag_dict) for pod_name in self.pod_name: branch_name = 'master' if pod_name in temp_branch_dict.keys(): branch_name = temp_branch_dict[pod_name] if pod_name in temp_tag_dict.keys(): self.tag_info[pod_name] = temp_tag_dict[pod_name] break temp_source_path = self.work_path + os.sep + 'podFolder' source_path = temp_source_path + os.sep + pod_name source_path = file.normalpath(source_path) print('代码更新本地路径:') print(source_path) git.checkout_or_update(source_path, self.get_remote_url(pod_name), branch=branch_name) git_root = git.get_git_root(source_path) os.chdir(git_root) subprocess.call(['git', 'fetch', '--tags']) new_push_version = git.get_revision(git_root) new_tags_info = git.get_newest_tag_revision(git_root) new_push_tag = '' # 当前仓库有没有打过tag if new_tags_info: new_push_tag = new_tags_info[1] # 最新提交的版本没有打过tag print(new_push_version, new_tags_info) if new_push_version != new_tags_info[0]: new_tag = new_tags_info[1].split('.') tag_num = int(new_tag[len(new_tag) - 1]) + 1 temp_tag = [] for i, val in enumerate(new_tag): if i != len(new_tag) - 1: temp_tag.append(val) else: temp_tag.append(format(tag_num)) new_tag = '.'.join(temp_tag) new_push_tag = new_tag self.change_podspec_version(new_tag, source_path) # 获取远程pod库版本信息 os.chdir(git_root) rtn_str = subprocess.check_output(['pod', 'search', pod_name], universal_newlines=True) version_str = re.search(r'\s+-\s+Versions:.+[PYPodSpec repo]]', rtn_str).group() is_revision_upload = False for detail_ver in version_str.split(','): if new_push_tag in detail_ver.strip(): is_revision_upload = True if not is_revision_upload: try: ret_code = subprocess.check_call(['sh', 'push.sh']) print(ret_code) except Exception as e: raise Exception(e) self.tag_info[pod_name] = new_push_tag if self.podfile_path: for pod_name_key in self.tag_info.keys(): file_data = file.read_file_content(self.podfile_path) version_line_arr = re.search( r"(pod\s+\'({}|{}.+)\'\,\s+\'([0-9]|\.)+\')".format( pod_name_key, pod_name_key), file_data) if version_line_arr: pod_version_line = version_line_arr.group() new_spec_version_line = re.sub(r'([0-9]\.|[0-9])+', self.tag_info[pod_name_key], pod_version_line) src_dst_list = list( zip([pod_version_line], [new_spec_version_line])) file.replace_string_in_file(self.podfile_path, src_dst_list) dir_name = os.path.dirname(os.path.dirname(self.podfile_path)) git_root = git.get_git_root(dir_name) os.chdir(git_root) if git.has_change(git_root): git.push_to_remote([self.podfile_path], '[other]: Podfile文件更新', repository=None, refspecs=None, _dir=git_root)
def testSwitch_commit_with_file(self): service = SvnService(self.temp_dir, normal=self.normal, refuse=self.refuse, target=self.target) target_path = self.target_path normal_str = self.normal_str refuse_str = self.refuse_str svn_name = self.svn_name # 验证原本可正常提交情况,当前要切换为可提交情况 file_util.write_to_file(target_path, normal_str, encoding='utf-8') time.sleep(1) target_m_time = os.path.getmtime(target_path) service.switch_commit_with_file(svn_name, True) new_target_m_time = os.path.getmtime(target_path) content = file_util.read_file_content(target_path, encoding_='utf-8') self.assertEqual( target_m_time, new_target_m_time, f'target_c_time: {target_m_time}, new_target_c_time: {new_target_m_time}' ) self.assertEqual(content, normal_str, f'content: {content}, normal_str: {normal_str}') # 验证原本非正常提交情况,当前要切换为可提交情况 file_util.write_to_file(target_path, refuse_str, encoding='utf-8') time.sleep(1) target_m_time = os.path.getmtime(target_path) service.switch_commit_with_file(svn_name, True) new_target_m_time = os.path.getmtime(target_path) content = file_util.read_file_content(target_path, encoding_='utf-8') self.assertNotEqual( target_m_time, new_target_m_time, f'target_c_time: {target_m_time}, new_target_c_time: {new_target_m_time}' ) self.assertEqual(content, normal_str, f'content: {content}, normal_str: {normal_str}') # 验证原本可正常提交情况,当前要切换为不可提交情况 file_util.write_to_file(target_path, normal_str, encoding='utf-8') time.sleep(1) target_m_time = os.path.getmtime(target_path) service.switch_commit_with_file(svn_name, False) new_target_m_time = os.path.getmtime(target_path) content = file_util.read_file_content(target_path, encoding_='utf-8') self.assertNotEqual( target_m_time, new_target_m_time, f'target_c_time: {target_m_time}, new_target_c_time: {new_target_m_time}' ) self.assertEqual(content, refuse_str, f'content: {content}, refuse_str: {refuse_str}') # 验证原本非正常提交情况,当前要切换为不可提交情况 file_util.write_to_file(target_path, refuse_str, encoding='utf-8') time.sleep(1) target_m_time = os.path.getmtime(target_path) service.switch_commit_with_file(svn_name, False) new_target_m_time = os.path.getmtime(target_path) content = file_util.read_file_content(target_path, encoding_='utf-8') self.assertEqual( target_m_time, new_target_m_time, f'target_c_time: {target_m_time}, new_target_c_time: {new_target_m_time}' ) self.assertEqual(content, refuse_str, f'content: {content}, refuse_str: {refuse_str}')
def process(src_dir, dst_dir, _type=_PACK_TYPE_ALL, filter_folders=[], _upload_type=_UPLOAD_TYPE_NONE, filter_file_dict=None): # 进行提取,过滤,更新操作 temp_root = tempfile.gettempdir() pack_root = temp_root + os.sep + 'pytxxy_config' try: if os.path.isdir(pack_root): shutil.rmtree(pack_root) os.makedirs(pack_root) # 先获取当前svn目录的版本号 ver_base = 0 ver_base_path = src_dir + os.sep + _PACK_VER_BASE_FILE ver_base_str = file_util.read_file_content(ver_base_path) match = re.match('^\s*(\d+)\s*$', ver_base_str, re.S) if match: ver_base = int(match.group(1)) print('version base is {}.'.format(ver_base)) svn_ver_code = int(svn.get_revision(src_dir)) ver_code = ver_base + svn_ver_code print('subversion code is {} and version code is {}.'.format( svn_ver_code, ver_code)) dst_ver_dir = dst_dir + os.sep + str(ver_code) upload_target_path_dict = {} # 进行整体或单项提取打包操作 filter_dir_file = [] if _type == _PACK_TYPE_ALL: for item in _PACK_SUB_DIRS: temp_dir = pack_root + os.sep + _PACK_SUB_DIRS[item] target_dir = dst_ver_dir + os.sep + _PACK_SUB_DIRS[item] if _PACK_SUB_DIRS[item] in filter_file_dict: filter_dir_file = filter_file_dict[ _PACK_SUB_DIRS[item]].split(',') process_item(src_dir, target_dir, temp_dir, item, ver_code, filter_folders, filter_file=filter_dir_file) target_file = _PACK_TARGET_FILE target_path = target_dir + os.sep + target_file upload_target_path_dict[_PACK_SUB_DIRS[item]] = target_path else: temp_dir = pack_root + os.sep + _PACK_SUB_DIRS[_type] target_dir = dst_ver_dir + os.sep + _PACK_SUB_DIRS[_type] if _type == _PACK_TYPE_IOS: filter_dir_file = filter_file_dict[_PACK_TYPE_IOS].split(',') process_item(src_dir, target_dir, temp_dir, _type, ver_code, filter_folders, filter_file=filter_dir_file) target_file = _PACK_TARGET_FILE target_path = target_dir + os.sep + target_file upload_target_path_dict[_PACK_SUB_DIRS[_type]] = target_path commitmanager = CommitManager(args) if _upload_type == _UPLOAD_TYPE_ALL: for item in _UPLOAD_SUB_DIRS: item_key = _UPLOAD_SUB_DIRS[item] config_info = commitmanager.get_item_info(item_key) if config_info: commitmanager.commit(item_key, config_info, upload_target_path_dict[item_key]) elif _upload_type != _UPLOAD_TYPE_NONE: item_key = _UPLOAD_SUB_DIRS[_upload_type] config_info = commitmanager.get_item_info(item_key) if config_info: commitmanager.commit(item_key, config_info, upload_target_path_dict[item_key]) finally: # 清空临时文件夹内容 if os.path.isdir(pack_root): shutil.rmtree(pack_root)