def refresh_pacman_databases(self): """ Updates pacman databases """ # Init pyalpm try: pacman = pac.Pac("/etc/pacman.conf", self.callback_queue) except Exception as ex: template = "Can't initialize pyalpm. An exception of type {0} occured. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) logging.error(message) raise InstallError(message) # Refresh pacman databases if not pacman.refresh(): logging.error("Can't refresh pacman databases.") txt = _("Can't refresh pacman databases.") raise InstallError(txt) try: pacman.release() del pacman except Exception as ex: template = "Can't release pyalpm. An exception of type {0} occured. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) logging.error(message) raise InstallError(message)
def initialize_alpm(self): try: self.alpm = pac.Pac() logging.debug("Alpm library initialized") except Exception as err: logging.error("Cannot initialize alpm library") sys.exit(-1)
def prepare_pacman(self): """ Configures pacman and syncs db on destination system """ self.create_pacman_conf_file() self.prepare_pacman_keyring() # Init pyalpm try: self.pacman = pac.Pac("/tmp/pacman.conf", self.callback_queue) except Exception: self.pacman = None logging.error("Can't initialize pyalpm.") raise InstallError(_("Can't initialize pyalpm.")) # Refresh pacman databases if not self.pacman.refresh(): logging.error("Can't refresh pacman databases.") raise InstallError(_("Can't refresh pacman databases."))
def refresh_pacman_databases(self): # Init pyalpm try: pacman = pac.Pac("/etc/pacman.conf", self.callback_queue) except Exception: logging.error("Can't initialize pyalpm.") raise InstallError(_("Can't initialize pyalpm.")) # Refresh pacman databases if not pacman.refresh(): logging.error("Can't refresh pacman databases.") txt = _("Can't refresh pacman databases.") raise InstallError(txt) try: pacman.release() del pacman except Exception as err: logging.error("Can't release pyalpm: %s", err) txt = _("Can't release pyalpm: {0}").format(err) raise InstallError()
def create_metalinks_list(self): """ Creates a downloads list (metalinks) from the package list """ self.queue_event('percent', '0') self.queue_event('info', _('Creating the list of packages to download...')) processed_packages = 0 total_packages = len(self.package_names) self.metalinks = {} try: pacman = pac.Pac(conf_path=self.pacman_conf_file, callback_queue=self.callback_queue) if pacman is None: return None except Exception as ex: self.metalinks = None template = "Can't initialize pyalpm. An exception of type {0} occured. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) logging.error(message) return try: for package_name in self.package_names: metalink = ml.create(pacman, package_name, self.pacman_conf_file) if metalink is None: txt = "Error creating metalink for package %s. Installation will stop" logging.error(txt, package_name) txt = _("Error creating metalink for package {0}. " "Installation will stop").format(package_name) raise misc.InstallError(txt) # Get metalink info metalink_info = ml.get_info(metalink) # Update downloads list with the new info from # the processed metalink for key in metalink_info: if key not in self.metalinks: self.metalinks[key] = metalink_info[key] urls = metalink_info[key]['urls'] if self.settings: # Sort urls based on the mirrorlist # we created earlier sorted_urls = sorted(urls, key=self.url_sort_helper) self.metalinks[key]['urls'] = sorted_urls else: # When testing, settings is not available self.metalinks[key]['urls'] = urls # Show progress to the user processed_packages += 1 percent = round(float(processed_packages / total_packages), 2) self.queue_event('percent', str(percent)) except Exception as ex: template = "Can't create download set. An exception of type {0} occured. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) logging.error(message) self.metalinks = None return try: pacman.release() del pacman except Exception as ex: self.metalinks = None template = "Can't release pyalpm. An exception of type {0} occured. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) logging.error(message) return # Overwrite last event (to clean up the last message) self.queue_event('info', "")
def create_metalinks_list(self): """ Creates a downloads list (metalinks) from the package list """ self.queue_event('percent', '0') self.queue_event('info', _('Creating the list of packages to download...')) processed_packages = 0 total_packages = len(self.package_names) self.metalinks = {} try: pacman = pac.Pac(conf_path=self.pacman_conf_file, callback_queue=self.callback_queue) if pacman is None: return None except Exception as err: logging.error("Can't initialize pyalpm: %s", err) self.metalinks = None return try: for package_name in self.package_names: metalink = ml.create(pacman, package_name, self.pacman_conf_file) if metalink is None: logging.error( "Error creating metalink for package %s. Installation will stop", package_name) txt = _( "Error creating metalink for package {0}. Installation will stop" ).format(package_name) raise misc.InstallError(txt) # Get metalink info metalink_info = ml.get_info(metalink) # Update downloads list with the new info from the processed metalink for key in metalink_info: if key not in self.metalinks: urls = metalink_info[key]['urls'] # Sort urls based on the mirrorlist we created earlier sorted_urls = sorted(urls, key=self.url_sort_helper) self.metalinks[key] = metalink_info[key] # logging.debug(self.metalinks[key]) self.metalinks[key]['urls'] = sorted_urls # logging.debug(self.metalinks[key]) # Show progress to the user processed_packages += 1 percent = round(float(processed_packages / total_packages), 2) self.queue_event('percent', str(percent)) except Exception as err: logging.error("Can't create download set: %s", err) self.metalinks = None return try: pacman.release() del pacman except Exception as err: logging.error("Can't release pyalpm: %s", err) self.metalinks = None return # Overwrite last event (to clean up the last message) self.queue_event('info', "")