def _correct_missing_files(cls, rebase_spec_file, files): """Adds files found in buildroot which are missing in %files sections in the SPEC file. Each file is added to a %files section with the closest matching path. """ macros = [m for m in rebase_spec_file.macros if m['name'] in MacroHelper.MACROS_WHITELIST] macros = MacroHelper.expand_macros(macros) # ensure maximal greediness macros.sort(key=lambda k: len(k['value']), reverse=True) result = collections.defaultdict(lambda: collections.defaultdict(list)) for file in files: section = cls._get_best_matching_files_section(rebase_spec_file, file) substituted_path = MacroHelper.substitute_path_with_macros(file, macros) try: index = [i for i, l in enumerate(rebase_spec_file.spec_content.section(section)) if l][-1] + 1 except IndexError: # section is empty index = 0 rebase_spec_file.spec_content.section(section).insert(index, substituted_path) result['added'][section].append(substituted_path) logger.info("Added %s to '%s' section", substituted_path, section) return result
def _correct_missing_files(cls, rebase_spec_file, files): """Adds files found in buildroot which are missing in %files sections in the SPEC file. Each file is added to a %files section with the closest matching path. """ macros = [ m for m in rebase_spec_file.macros if m['name'] in MacroHelper.MACROS_WHITELIST ] macros = MacroHelper.expand_macros(macros) # ensure maximal greediness macros.sort(key=lambda k: len(k['value']), reverse=True) result = collections.defaultdict(lambda: collections.defaultdict(list)) for file in files: section = cls._get_best_matching_files_section( rebase_spec_file, file) substituted_path = MacroHelper.substitute_path_with_macros( file, macros) try: index = [ i for i, l in enumerate( rebase_spec_file.spec_content.sections[section]) if l ][-1] + 1 except IndexError: # section is empty index = 0 rebase_spec_file.spec_content.sections[section].insert( index, substituted_path) result['added'][section].append(substituted_path) logger.info("Added %s to '%s' section", substituted_path, section) return result
def run(cls, spec_file, rebase_spec_file, **kwargs): macros = [m for m in rebase_spec_file.macros if m['name'] in MacroHelper.MACROS_WHITELIST] macros = MacroHelper.expand_macros(macros) # ensure maximal greediness macros.sort(key=lambda k: len(k['value']), reverse=True) for sec_name, sec_content in rebase_spec_file.spec_content.sections: if sec_name.startswith('%files'): for index, line in enumerate(sec_content): new_path = MacroHelper.substitute_path_with_macros(line, macros) sec_content[index] = new_path rebase_spec_file.save()
def run(cls, spec_file, rebase_spec_file, **kwargs): macros = [m for m in rebase_spec_file.macros if m['name'] in MacroHelper.MACROS_WHITELIST] macros = MacroHelper.expand_macros(macros) # ensure maximal greediness macros.sort(key=lambda k: len(k['value']), reverse=True) for sec_name, sec_content in six.iteritems(rebase_spec_file.spec_content.sections): if sec_name.startswith('%files'): for index, line in enumerate(sec_content): new_path = MacroHelper.substitute_path_with_macros(line, macros) rebase_spec_file.spec_content.sections[sec_name][index] = new_path rebase_spec_file.save()
def _correct_missing_files(cls, rebase_spec_file, files): """Adds files found in buildroot which are missing in %files sections in the SPEC file. Each file is added to a %files section with the closest matching path. """ # get %{name} macro macros = [ m for m in MacroHelper.filter(rebase_spec_file.macros, level=-3) if m['name'] == 'name' ] macros.extend(m for m in rebase_spec_file.macros if m['name'] in MacroHelper.MACROS_WHITELIST) macros = MacroHelper.expand_macros(macros) # ensure maximal greediness macros.sort(key=lambda k: len(k['value']), reverse=True) result: Dict[str, AddedFiles] = collections.defaultdict( lambda: collections.defaultdict(list)) for file in files: section = cls._get_best_matching_files_section( rebase_spec_file, file) if section is None: logger.error( 'The specfile does not contain any %files section, cannot add the missing files' ) break substituted_path = cls._sanitize_path( MacroHelper.substitute_path_with_macros(file, macros)) try: index = [ i for i, l in enumerate( rebase_spec_file.spec_content.section(section)) if l ][-1] + 1 except IndexError: # section is empty index = 0 rebase_spec_file.spec_content.section(section).insert( index, substituted_path) result['added'][section].append(substituted_path) logger.info("Added %s to '%s' section", substituted_path, section) return result