def modify_audio_codec(audio_type, audio_codec): if audio_type in codec_dict: for i in codec_dict[audio_type]: index = i[0] audio_codec[index] = string_utils.replace(audio_codec[index], i[1], i[2]) return audio_codec
def find_matching_files(file_pattern, script_output): files = [] separator = re.escape(os_utils.path_sep()) output_patterns = [file_pattern] while len(output_patterns) > 0: output_pattern = output_patterns.pop(0) if '#' in output_pattern: regex_start = output_pattern.find('#') group_number_matches = re.findall('^#\d+#', output_pattern[regex_start:]) if group_number_matches: first_match = group_number_matches[0] group_number = int(first_match[1:-1]) pattern_start = regex_start + len(first_match) - 1 else: group_number = 0 pattern_start = regex_start regex_end = output_pattern.find('#', pattern_start + 1) while (regex_end >= 0) and output_pattern[regex_end:].startswith('#any_path'): regex_end = output_pattern.find('#', regex_end + 1) if regex_end >= 0: regex_pattern = output_pattern[pattern_start + 1:regex_end] if regex_pattern.startswith('#any_path') and (regex_start == 0): if os_utils.is_linux() or os_utils.is_mac(): regex_pattern = '~?' + regex_pattern elif os_utils.is_win(): regex_pattern = '(([^\W\d_]:)|~)' + regex_pattern regex_pattern = regex_pattern.replace( '#any_path', '(' + separator + '([\w.\-]|(\\\ ))+)+') found_matches = re.finditer(regex_pattern, script_output) for match in found_matches: matched_group = match.group(group_number) new_output_pattern = string_utils.replace( output_pattern, matched_group, regex_start, regex_end) output_patterns.append(new_output_pattern) continue if '*' not in output_pattern: files.append(output_pattern) else: recursive = '**' in output_pattern matching_files = file_utils.search_glob(output_pattern, recursive=recursive) files.extend(matching_files) return files
def find_matching_files(file_pattern, script_output): files = [] separator = re.escape(os_utils.path_sep()) output_patterns = [file_pattern] while len(output_patterns) > 0: output_pattern = output_patterns.pop(0) if '#' in output_pattern: regex_start = output_pattern.find('#') group_number_matches = re.findall('^#\d+#', output_pattern[regex_start:]) if group_number_matches: first_match = group_number_matches[0] group_number = int(first_match[1:-1]) pattern_start = regex_start + len(first_match) - 1 else: group_number = 0 pattern_start = regex_start regex_end = output_pattern.find('#', pattern_start + 1) while (regex_end >= 0) and output_pattern[regex_end:].startswith('#any_path'): regex_end = output_pattern.find('#', regex_end + 1) if regex_end >= 0: regex_pattern = output_pattern[pattern_start + 1:regex_end] if regex_pattern.startswith('#any_path') and (regex_start == 0): if os_utils.is_linux() or os_utils.is_mac(): regex_pattern = '~?' + regex_pattern elif os_utils.is_win(): regex_pattern = '(([^\W\d_]:)|~)' + regex_pattern regex_pattern = regex_pattern.replace('#any_path', '(' + separator + '([\w.\-]|(\\\ ))+)+') found_matches = re.finditer(regex_pattern, script_output) for match in found_matches: matched_group = match.group(group_number) new_output_pattern = string_utils.replace(output_pattern, matched_group, regex_start, regex_end) output_patterns.append(new_output_pattern) continue if '*' not in output_pattern: files.append(output_pattern) else: recursive = '**' in output_pattern matching_files = file_utils.search_glob(output_pattern, recursive=recursive) files.extend(matching_files) return files