def _get_bin_rpm_depend(self, dbs): """ Get one-level install dependency of all binary packages in the database :param dbs: Database to be queried :return: """ for database in dbs: # First,query all binary rpm name of specify database. all_bin_rpm = self.query_pkg.get_bin_info( binary_list=None, database=database, page_num=DEFAULT_PAGE_NUM, page_size=MAXIMUM_PAGE_SIZE, command_line=True) all_bin_rpm_name = list() for bin_rpm in all_bin_rpm.get('data'): all_bin_rpm_name.extend(bin_rpm.keys()) LOGGER.info( f'The number of binary packages in the {database} database is {len(all_bin_rpm_name)}' ) # Second, query the one-level install dependencies of all packages based on the package name. install_query_engine = InstallRequires([database]) all_binary_rpm_depend = install_query_engine.get_install_req( binary_list=all_bin_rpm_name) # Third, format build dependencies format_binary_rpm_depend = self._format_depend( all_binary_rpm_depend, key_word=self.BINARY_NAME) self.result.append({database: format_binary_rpm_depend})
def _get_source_rpm_depend(self, dbs): """ Get one-level compilation dependency of all source packages in the database :param dbs: Database to be queried :return: None """ for database in dbs: # First,query all source rpm name of specify database. all_source_rpm = self.query_pkg.get_src_info( src_list=None, database=database, page_num=DEFAULT_PAGE_NUM, page_size=MAXIMUM_PAGE_SIZE, command_line=True) all_source_rpm_name = list() for source_rpm in all_source_rpm.get('data'): all_source_rpm_name.extend(source_rpm.keys()) LOGGER.info( f'The number of source packages in the {database} database is {len(all_source_rpm_name)}' ) # Second, query the one-level build dependencies of all packages based on the package name. build_query_engine = BuildRequires([database]) all_source_rpm_depend = build_query_engine.get_build_req( source_list=all_source_rpm_name) # Third, format build dependencies format_source_rpm_depend = self._format_depend( all_source_rpm_depend, key_word=self.SOURCE_NAME) self.result.append({database: format_source_rpm_depend})
def all_depend_info(self, depend_type, dbs): """ Get all rpm info ,include source rpm(query build depend) and binary rpm (query install rpm) :param depend_type: :param dbs: :return: """ if depend_type == BUILD_DEPEND_TYPE: LOGGER.info("Start to query all source rpm dependency information") self._get_source_rpm_depend(dbs) elif depend_type == INSTALL_DEPEND_TYPE: LOGGER.info("Start to query all binary rpm dependency information") self._get_bin_rpm_depend(dbs) return self.result
def _write_data_to_csv(self, depend_info, depend_info_dict): """ Write dependent data to csv file :param depend_info: {database:[{rpm_name:{rpm_depend_info}}]} :param depend_info_dict: Record the relationship between the package name and the package dependency to facilitate subsequent comparisons :return: None """ field_names = [ FIELD.DEPENDENCY, FIELD.DEPENDENCY_PACKAGE, FIELD.DEPENDENCY_VERSION, FIELD.DEPENDING_PACKAGE, FIELD.DEPENDING_VERSION ] for database, depend_data in depend_info.items(): LOGGER.info(f'Save data of {database} to csv') csv_file = os.path.join(self.out_path, f'{database}.csv') with open(csv_file, 'w', encoding='utf-8') as file: csv_writer = csv.DictWriter(file, fieldnames=field_names) csv_writer.writeheader() self._write_data(csv_writer, depend_data, depend_info_dict)
def dbs_compare(self, dbs_depend_info): """ Compare the dependent information in different databases, write it into a csv file and convert it to excel。 :param dbs_depend_info: the dependent information in different databases :return: True/False """ LOGGER.info( 'Start to compare the dependent information in different databases' ) if not dbs_depend_info: print('[ERROR] No data in all databases') return False try: # The first database is recorded separately as the benchmark database base_database = dbs_depend_info[0] base_depend_dict = defaultdict(list) self._write_data_to_csv(base_database, base_depend_dict) # The latter database is used as a comparison database record compare_depend_list = list() for compare_database in dbs_depend_info[1:]: compare_depend_dict = defaultdict(list) self._write_data_to_csv(compare_database, compare_depend_dict) compare_depend_list.append(compare_depend_dict) # Compare the dependency difference between base database and other databases self._compare_data(base_depend_dict, compare_depend_list) # Set file permissions self._set_file_permissions() return True except (ValueError, AttributeError) as e: print( '[ERROR] Failed to save the data by comparing the difference, please check the log location' ) LOGGER.error( f'Failed to save the data by comparing the difference, message is {str(e)}' ) return False