def _show_package_dependencies(self, entropy_server, atom, orig_deps, partial = False): """ Print package dependencies for atom. """ if not partial: entropy_server.output( "%s, %s" % ( blue(atom), darkgreen(_("package dependencies"))), header=brown(" @@ ")) else: entropy_server.output("") for dep_str, dep_id in orig_deps: entropy_server.output( "[%s: %s] %s" % ( brown(_("type")), darkgreen(str(dep_id+1)), purple(dep_str)), header=brown(" #")) if not orig_deps: entropy_server.output( _("No dependencies"), header=brown(" # ")) else: self._show_dependencies_legend(entropy_server, " ") if partial: entropy_server.output("")
def _selfile(self, entropy_client): entropy_client.output( darkred( _("Please choose a file to update by typing " "its identification number."))) entropy_client.output(darkred(_("Other options are:"))) entropy_client.output(" (%s) %s" % ( blue(const_convert_to_unicode("-1")), darkgreen(_("Exit")), )) entropy_client.output(" (%s) %s" % ( blue(const_convert_to_unicode("-3")), brown(_("Automerge all the files asking you one by one")), )) entropy_client.output(" (%s) %s" % ( blue(const_convert_to_unicode("-5")), darkred(_("Automerge all the files without questioning")), )) entropy_client.output(" (%s) %s" % ( blue(const_convert_to_unicode("-7")), brown(_("Discard all the files asking you one by one")), )) entropy_client.output(" (%s) %s" % ( blue(const_convert_to_unicode("-9")), darkred(_("Discard all the files without questioning")), )) # wait user interaction try: action = readtext( _("Your choice (type a number and press enter):") + " ") except EOFError: action = None return action
def _update_progress(self, force = False): if self._silent: # stfu ! return upload_percent = 100.0 upload_size = round(self.__filekbcount, 1) if self.__filesize >= 1: kbcount_round = round(self.__filekbcount, 1) upload_percent = round((kbcount_round / self.__filesize) * 100, 1) delta_secs = 0.5 cur_t = time.time() if (cur_t > (self.__oldprogress_t + delta_secs)) or force: upload_percent = str(upload_percent)+"%" # create text mytxt = _("Transfer status") current_txt = brown(" <-> %s: " % (mytxt,)) + \ darkgreen(str(upload_size)) + "/" + \ red(str(self.__filesize)) + " kB " + \ brown("[") + str(upload_percent) + brown("]") + \ " " + self.__time_remaining + " " + \ bytes_into_human(self.__datatransfer) + \ "/" + _("sec") self.output(current_txt, back = True) self.__oldprogress_t = cur_t
def _trigger_call_ext_generic(self): try: return self._do_trigger_call_ext_generic() except Exception as err: mykey = self._pkgdata['category']+"/"+self._pkgdata['name'] tback = entropy.tools.get_traceback() self._entropy.output(tback, importance = 0, level = "error") self._entropy.logger.write(tback) self._entropy.logger.log( "[Trigger]", etpConst['logging']['normal_loglevel_id'], "[POST] ATTENTION Cannot run External trigger for " + \ mykey + "!! " + str(Exception) + ": " + repr(err) ) mytxt = "%s: %s %s. %s." % ( bold(_("QA")), brown(_("Cannot run External trigger for")), bold(mykey), brown(_("Please report it")), ) self._entropy.output( mytxt, importance = 0, header = red(" ## ") ) return 0
def _parse_progress_line(self, line): line_data = line.strip().split() if len(line_data) < 5: const_debug_write(__name__, "_parse_progress_line: cannot parse: %s" % (line_data,)) # mmh... not possible to properly parse data self.output(line.strip(), back = True) return const_debug_write(__name__, "_parse_progress_line: parsing: %s" % (line_data,)) file_name = line_data[0] percent = line_data[1] tx_speed = line_data[3] tx_size = line_data[2] eta = line_data[4] # create text mytxt = _("Transfer status") current_txt = "<-> (%s) %s: " % (teal(file_name), brown(mytxt),) + \ darkgreen(tx_size) + " " + \ brown("[") + str(percent) + brown("]") + \ " " + eta + " " + tx_speed self.output(current_txt, back = True, header = " ")
def _show_notice_board_summary(self, entropy_client, repository): """ Show NoticeBoard information to user after repository update. """ mytxt = "%s %s: %s" % ( darkgreen(" @@ "), brown(_("Notice board")), bold(repository), ) entropy_client.output(mytxt) mydict = self._check_notice_board_availability(entropy_client, repository) if not mydict: return for key in sorted(mydict.keys()): mydata = mydict.get(key) mytxt = " [%s] [%s] %s: %s" % ( blue(str(key)), brown(mydata['pubDate']), _("Title"), darkred(mydata['title']), ) entropy_client.output(mytxt)
def _vacuum(self, entropy_client, inst_repo): """ Solo Smart Vacuum command. """ entropy_client.output( "%s..." % ( brown(_("Compacting the Installed Packages repository")), ), importance=1, level="info", header=darkgreen(" @@ "), back=True ) inst_repo.dropAllIndexes() inst_repo.vacuum() inst_repo.commit() entropy_client.output( "%s." % ( brown(_("Compaction complete")), ), importance=1, level="info", header=darkgreen(" @@ ") ) return 0
def _update_progress(self, force=False): if self._silent: # stfu ! return upload_percent = 100.0 upload_size = round(self.__filekbcount, 1) if self.__filesize >= 1: kbcount_round = round(self.__filekbcount, 1) upload_percent = round((kbcount_round / self.__filesize) * 100, 1) delta_secs = 0.5 cur_t = time.time() if (cur_t > (self.__oldprogress_t + delta_secs)) or force: upload_percent = str(upload_percent) + "%" # create text mytxt = _("Transfer status") current_txt = brown(" <-> %s: " % (mytxt,)) + \ darkgreen(str(upload_size)) + "/" + \ red(str(self.__filesize)) + " kB " + \ brown("[") + str(upload_percent) + brown("]") + \ " " + self.__time_remaining + " " + \ bytes_into_human(self.__datatransfer) + \ "/" + _("sec") self.output(current_txt, back=True) self.__oldprogress_t = cur_t
def _status(self, entropy_server): """ Actual Eit lock|unlock --status code. Just show repo status. """ repositories = entropy_server.repositories() if self._repository_id not in repositories: entropy_server.output( "%s: %s" % ( _("Invalid Repository"), self._repository_id), level="error", importance=1) return 1 if not self._quiet: entropy_server.output( "%s:" % (darkgreen(_("Mirrors status")),), header=brown(" * ")) dbstatus = entropy_server.Mirrors.mirrors_status( self._repository_id) for uri, server_lock, client_lock in dbstatus: host = EntropyTransceiver.get_uri_name(uri) if not self._quiet: entropy_server.output( "[%s]" % (purple(host),), header=darkgreen(" @@ ")) if server_lock: lock_str = darkred(_("Locked")) quiet_lock_str = "locked" else: lock_str = darkgreen(_("Unlocked")) quiet_lock_str = "unlocked" if self._quiet: entropy_server.output( "%s server %s" % (host, quiet_lock_str), level="generic") else: entropy_server.output( "%s: %s" % (blue(_("server")), lock_str), header=brown(" # ")) if client_lock: lock_str = darkred(_("Locked")) quiet_lock_str = "locked" else: lock_str = darkgreen(_("Unlocked")) quiet_lock_str = "unlocked" if self._quiet: entropy_server.output( "%s client %s" % (host, quiet_lock_str), level="generic") else: entropy_server.output( "%s: %s" % (blue(_("client")), lock_str), header=brown(" # ")) return 0
def _garbage_collect_preserved_libs(self, preserved_mgr): """ Garbage collect (and remove) libraries preserved on the system no longer available or no longer needed by any installed package. """ preserved_libs = preserved_mgr.collect() inst_repo = preserved_mgr.installed_repository() for library, elfclass, path in preserved_libs: self._entropy.output( "%s: %s [%s, %s]" % ( brown(_("Removing library")), darkgreen(path), purple(library), teal(const_convert_to_unicode("%s" % (elfclass,))), ), importance = 0, level = "warning", header = darkgreen(" :: ") ) self._entropy.logger.log( "[Package]", etpConst['logging']['normal_loglevel_id'], "%s %s [%s:%s]" % ( const_convert_to_unicode("Removing library"), path, library, elfclass,) ) # This will also check if path and it's destinations (in case of # symlink) is owned by other packages. # If this is the case, removal will fail for that specific path. # This may be the case for packages like vmware-workstation, # containing symlinks pointing to system libraries. # See Sabayon bug #5182. remove_failed = preserved_mgr.remove(path) for failed_path, err in remove_failed: self._entropy.output( "%s: %s, %s" % ( purple(_("Failed to remove the library")), darkred(failed_path), err, ), importance = 1, level = "warning", header = brown(" ## ") ) self._entropy.logger.log( "[Package]", etpConst['logging']['normal_loglevel_id'], "Error during %s removal: %s" % (failed_path, err) ) preserved_mgr.unregister(library, elfclass, path) # commit changes to repository if collected if preserved_libs: inst_repo.commit()
def _execute_package_phase(self, action_metadata, package_metadata, action_name, phase_name): """ Wrapper against Source Package Manager's execute_package_phase. This method handles both fatal and non-fatal exceptions. """ self._entropy.output( "%s: %s" % (brown(_("Package phase")), teal(phase_name),), importance = 0, header = red(" ## ")) spm = self._spm try: spm.execute_package_phase( action_metadata, package_metadata, action_name, phase_name) except spm.PhaseFailure as err: txt = "%s: %s %s, %s. %s." % ( bold(_("QA")), brown(_("Cannot run phase")), bold(phase_name), err.message, brown(_("Please report it")), ) self._entropy.output( txt, importance = 1, header = red(" ## "), level = "warning") return 0 # non-fatal except spm.OutdatedPhaseError as err: err_msg = "%s: %s" % ( brown(_("Source Package Manager is too old, " "please update it")), err) self._entropy.output( err_msg, importance = 1, header = darkred(" ## "), level = "error" ) return 1 except spm.PhaseError as err: err_msg = "%s: %s" % ( brown(_("Source Package Manager phase error")), err) self._entropy.output( err_msg, importance = 1, header = darkred(" ## "), level = "error" ) return 1 return 0
def _remove_packages(self, entropy_server, package_matches): """ Remove the given Entropy packages from their repositories. """ def show_rm(pkg_id, pkg_repo): repo = entropy_server.open_repository(pkg_repo) atom = repo.retrieveAtom(pkg_id) exp_string = '' pkg_expired = entropy_server._is_match_expired( (pkg_id, pkg_repo,)) if pkg_expired: exp_string = "|%s" % (purple(_("expired")),) entropy_server.output( "[%s%s] %s" % ( blue(pkg_repo), exp_string, darkred(atom),), header=brown(" # ")) def asker(package_match): pkg_id, pkg_repo = package_match show_rm(pkg_id, pkg_repo) rc = entropy_server.ask_question( _("Remove this package?")) return rc == _("Yes") if self._interactive: entropy_server.output( blue(_("Select packages for removal")), header=brown(" @@ ")) package_matches = list(filter(asker, package_matches)) if not package_matches: return entropy_server.output( blue(_("These would be removed from repository")), header=brown(" @@ ")) for package_id, repository_id in package_matches: show_rm(package_id, repository_id) if self._ask: rc = entropy_server.ask_question( _("Would you like to remove them now ?") ) if rc == _("No"): return remdata = {} for package_id, repository_id in package_matches: obj = remdata.setdefault(repository_id, set()) obj.add(package_id) for repository_id, packages in remdata.items(): entropy_server.remove_packages(repository_id, packages) entropy_server.commit_repositories()
def _get_installed_kernels(self, installed_repository): """ Return a set of kernel packages that are installed on the system. """ installed_package_ids = set() # Resolve the target kernel using the installed packages repository. # First, locate the virtual kernel package (if new virtuals are in # use.) latest_kernel, _k_rc = installed_repository.atomMatch( KERNEL_BINARY_VIRTUAL) if latest_kernel == -1: # Virtual package is not installed. # This happens when kernel packages have been moved to the new # virtual and PROVIDE is broken or no longer supported (EAPI=7?). print_warning("%s: %s %s" % ( red(_("Attention")), KERNEL_BINARY_VIRTUAL, brown( _("is not installed. Unable to resolve kernel " "packages correctly. Please use --from-running or install" "the package. Is your system up-to-date?")))) return installed_package_ids # If we have resolved the package to the virtual, we need to go # one level deep and retrieve the list of available kernel packages. # Do not assume that we hit only one kernel package when scanning, we # may have different packages in the dependency list. virtual_key = entropy.dep.dep_getkey(KERNEL_BINARY_VIRTUAL) latest_key_slot = installed_repository.retrieveKeySlot(latest_kernel) if latest_key_slot: latest_key, _unused = latest_key_slot else: # Cannot find installed package, give up. print_warning("%s: %s" % ( red(_("Attention")), brown( _("Unable to resolve the latest kernel metadata. Try again later." )))) return installed_package_ids if virtual_key == latest_key: print_info("%s: %s" % ( red(_("Resolving virtual kernel package")), KERNEL_BINARY_VIRTUAL, )) # New virtual package support. virtual_deps = installed_repository.retrieveRuntimeDependencies( latest_kernel) for virtual_dep in virtual_deps: virtual_pkg_id, _v_rc = installed_repository.atomMatch( virtual_dep) if virtual_pkg_id != -1: installed_package_ids.add(virtual_pkg_id) else: # Old virtual package detected (pre EAPI=7). Assume it's a kernel # binary. installed_package_ids.add(latest_kernel) return installed_package_ids
def _list(self, entropy_client): """ Solo Security List command. """ affected = self._nsargs.affected unaffected = self._nsargs.unaffected sec = entropy_client.Security() if not (affected or unaffected): advisory_ids = sec.list() elif affected: advisory_ids = sec.vulnerabilities() else: advisory_ids = sec.fixed_vulnerabilities() if not advisory_ids: entropy_client.output( "%s." % ( darkgreen(_("No advisories available or applicable")), ), header=brown(" :: ")) return 0 for advisory_id in sorted(advisory_ids): affected_deps = sec.affected_id(advisory_id) if affected and not affected_deps: continue if unaffected and affected_deps: continue if affected_deps: affection_string = darkred("A") else: affection_string = darkgreen("N") advisory = sec.advisory(advisory_id) if advisory is None: continue affected_data = advisory['affected'] if not affected_data: continue for a_key in list(affected_data.keys()): k_data = advisory['affected'][a_key] vulnerables = ', '.join(k_data[0]['vul_vers']) description = "[Id:%s:%s][%s] %s: %s" % ( darkgreen(advisory_id), affection_string, brown(vulnerables), darkred(a_key), blue(advisory['title'])) entropy_client.output(description) return 0
def _get_installed_kernels(self, installed_repository): """ Return a set of kernel packages that are installed on the system. """ installed_package_ids = set() # Resolve the target kernel using the installed packages repository. # First, locate the virtual kernel package (if new virtuals are in # use.) latest_kernel, _k_rc = installed_repository.atomMatch(KERNEL_BINARY_VIRTUAL) if latest_kernel == -1: # Virtual package is not installed. # This happens when kernel packages have been moved to the new # virtual and PROVIDE is broken or no longer supported (EAPI=7?). print_warning("%s: %s %s" % ( red(_("Attention")), KERNEL_BINARY_VIRTUAL, brown(_("is not installed. Unable to resolve kernel " "packages correctly. Please use --from-running or install" "the package. Is your system up-to-date?")))) return installed_package_ids # If we have resolved the package to the virtual, we need to go # one level deep and retrieve the list of available kernel packages. # Do not assume that we hit only one kernel package when scanning, we # may have different packages in the dependency list. virtual_key = entropy.dep.dep_getkey(KERNEL_BINARY_VIRTUAL) latest_key_slot = installed_repository.retrieveKeySlot(latest_kernel) if latest_key_slot: latest_key, _unused = latest_key_slot else: # Cannot find installed package, give up. print_warning("%s: %s" % ( red(_("Attention")), brown(_("Unable to resolve the latest kernel metadata. Try again later.")) )) return installed_package_ids if virtual_key == latest_key: print_info("%s: %s" % ( red(_("Resolving virtual kernel package")), KERNEL_BINARY_VIRTUAL, )) # New virtual package support. virtual_deps = installed_repository.retrieveRuntimeDependencies( latest_kernel) for virtual_dep in virtual_deps: virtual_pkg_id, _v_rc = installed_repository.atomMatch(virtual_dep) if virtual_pkg_id != -1: installed_package_ids.add(virtual_pkg_id) else: # Old virtual package detected (pre EAPI=7). Assume it's a kernel # binary. installed_package_ids.add(latest_kernel) return installed_package_ids
def _configure_package_unlocked(self, metadata): """ Configure the package. """ spm = self._entropy.Spm() self._entropy.output( "SPM: %s" % ( brown(_("configuration phase")), ), importance = 0, header = red(" ## ") ) try: spm.execute_package_phase( metadata, metadata, self.NAME, "configure") except spm.PhaseFailure as err: self._entropy.logger.log( "[Package]", etpConst['logging']['normal_loglevel_id'], "Phase execution failed with %s, %d" % ( err.message, err.code)) return err.code except spm.OutdatedPhaseError as err: self._entropy.logger.log( "[Package]", etpConst['logging']['normal_loglevel_id'], "Source Package Manager is too old: %s" % ( err)) err_msg = "%s: %s" % ( brown(_("Source Package Manager is too old, please update it")), err) self._entropy.output( err_msg, importance = 1, header = darkred(" ## "), level = "error" ) return 1 except spm.PhaseError as err: self._entropy.logger.log( "[Package]", etpConst['logging']['normal_loglevel_id'], "Phase execution error: %s" % ( err)) return 1 return 0
def _execute_package_phase(self, action_metadata, package_metadata, action_name, phase_name): """ Wrapper against Source Package Manager's execute_package_phase. This method handles both fatal and non-fatal exceptions. """ self._entropy.output("%s: %s" % ( brown(_("Package phase")), teal(phase_name), ), importance=0, header=red(" ## ")) spm = self._spm try: spm.execute_package_phase(action_metadata, package_metadata, action_name, phase_name) except spm.PhaseFailure as err: txt = "%s: %s %s, %s. %s." % ( bold(_("QA")), brown(_("Cannot run phase")), bold(phase_name), err.message, brown(_("Please report it")), ) self._entropy.output(txt, importance=1, header=red(" ## "), level="warning") return 0 # non-fatal except spm.OutdatedPhaseError as err: err_msg = "%s: %s" % (brown( _("Source Package Manager is too old, " "please update it")), err) self._entropy.output(err_msg, importance=1, header=darkred(" ## "), level="error") return 1 except spm.PhaseError as err: err_msg = "%s: %s" % (brown( _("Source Package Manager phase error")), err) self._entropy.output(err_msg, importance=1, header=darkred(" ## "), level="error") return 1 return 0
def _quickpkg(self, entropy_client, inst_repo): """ Solo Pkg Quickpkg command. """ packages = self._nsargs.packages savedir = self._nsargs.savedir if not os.path.isdir(savedir) and not os.path.exists(savedir): # this is validated by the parser # but not in case of no --savedir provided const_setup_directory(savedir) if not os.path.exists(savedir): entropy_client.output( "%s: %s" % ( brown(_("broken directory path")), savedir,), level="error", importance=1) return 1 package_ids = self._scan_packages(entropy_client, inst_repo, packages) if not package_ids: return 1 for package_id in package_ids: atom = inst_repo.retrieveAtom(package_id) entropy_client.output( "%s: %s" % ( teal(_("generating package")), purple(atom),), header=brown(" @@ "), back=True) pkg_data = inst_repo.getPackageData(package_id) file_path = entropy_client.generate_package( pkg_data, save_directory=savedir) if file_path is None: entropy_client.output( "%s: %s" % ( darkred(_("package file creation error")), blue(atom),), level="error", importance=1) return 3 entropy_client.output( "[%s] %s: %s" % ( darkgreen(atom), teal(_("package generated")), purple(file_path),), header=brown(" ## ")) return 0
def _clean(self, entropy_client, _inst_repo): """ Solo Cache Clean command. """ entropy_client.output(blue( _("Cleaning Entropy cache, please wait ...")), level="info", header=brown(" @@ "), back=True) entropy_client.clear_cache() entropy_client.output(darkgreen(_("Entropy cache cleaned.")), level="info", header=brown(" @@ ")) return 0
def _status(self, entropy_server): """ Actual Eit lock|unlock --status code. Just show repo status. """ repositories = entropy_server.repositories() if self._repository_id not in repositories: entropy_server.output( "%s: %s" % (_("Invalid Repository"), self._repository_id), level="error", importance=1) return 1 if not self._quiet: entropy_server.output("%s:" % (darkgreen(_("Mirrors status")), ), header=brown(" * ")) dbstatus = entropy_server.Mirrors.mirrors_status(self._repository_id) for uri, server_lock, client_lock in dbstatus: host = EntropyTransceiver.get_uri_name(uri) if not self._quiet: entropy_server.output("[%s]" % (purple(host), ), header=darkgreen(" @@ ")) if server_lock: lock_str = darkred(_("Locked")) quiet_lock_str = "locked" else: lock_str = darkgreen(_("Unlocked")) quiet_lock_str = "unlocked" if self._quiet: entropy_server.output("%s server %s" % (host, quiet_lock_str), level="generic") else: entropy_server.output("%s: %s" % (blue(_("server")), lock_str), header=brown(" # ")) if client_lock: lock_str = darkred(_("Locked")) quiet_lock_str = "locked" else: lock_str = darkgreen(_("Unlocked")) quiet_lock_str = "unlocked" if self._quiet: entropy_server.output("%s client %s" % (host, quiet_lock_str), level="generic") else: entropy_server.output("%s: %s" % (blue(_("client")), lock_str), header=brown(" # ")) return 0
def _remove(self, entropy_server): """ Actual Eit remove code. """ repository_id = entropy_server.repository() repo = entropy_server.open_repository(repository_id) pkg_matches = [] for package in self._packages: pkg = repo.atomMatch(package, multiMatch = True) for pkg_id in pkg[0]: pkg_match = (pkg_id, repository_id) if pkg_match not in pkg_matches: pkg_matches.append(pkg_match) if not pkg_matches: entropy_server.output( purple(_("No packages found")), importance=1, level="error") return 1 if not self._nodeps: pkg_matches = entropy_server.get_reverse_queue(pkg_matches, system_packages = False) entropy_server.output( darkgreen( _("These are the packages that would be removed") + ":"), importance=1, header=brown(" @@ ")) repo_map = {} for pkg_id, repo_id in pkg_matches: repo = entropy_server.open_repository(repo_id) pkgatom = repo.retrieveAtom(pkg_id) entropy_server.output( "[%s] %s" % (teal(repo_id), purple(pkgatom)), header=brown(" # ")) obj = repo_map.setdefault(repo_id, []) obj.append(pkg_id) if self._ask: resp = entropy_server.ask_question( _("Would you like to continue ?")) if resp == _("No"): return 0 for repo_id, pkg_ids in repo_map.items(): entropy_server.remove_packages(repo_id, pkg_ids) return 0
def _show_removal_info(self, entropy_client, package_ids, manual=False): """ Show packages removal information. """ if manual: entropy_client.output( "%s:" % ( blue(_("These are the packages that " "should be MANUALLY removed")),), header=darkred(" @@ ")) else: entropy_client.output( "%s:" % ( blue(_("These are the packages that " "would be removed")),), header=darkred(" @@ ")) total = len(package_ids) inst_repo = entropy_client.installed_repository() for count, package_id in enumerate(package_ids, 1): atom = inst_repo.retrieveAtom(package_id) installedfrom = inst_repo.getInstalledPackageRepository( package_id) if installedfrom is None: installedfrom = _("Not available") on_disk_size = inst_repo.retrieveOnDiskSize(package_id) pkg_size = inst_repo.retrieveSize(package_id) extra_downloads = inst_repo.retrieveExtraDownload(package_id) for extra_download in extra_downloads: pkg_size += extra_download['size'] on_disk_size += extra_download['disksize'] disksize = entropy.tools.bytes_into_human(on_disk_size) disksize_info = "%s%s%s" % ( bold("["), brown("%s" % (disksize,)), bold("]")) repo_info = bold("[") + brown(installedfrom) + bold("]") mytxt = "%s %s %s" % ( repo_info, enlightenatom(atom), disksize_info) entropy_client.output(mytxt, header=darkred(" ## "))
def _spmuids(self, entropy_client, inst_repo): """ Solo Smart Spmuids command. """ entropy_client.output("%s..." % (purple(_("Re-generating packages mapping")), ), header=brown(" @@ "), back=True) inst_repo.regenerateSpmUidMapping() entropy_client.output("%s..." % (purple(_("Packages mapping re-generated")), ), header=brown(" @@ ")) return 0
def _compress_packages(self, entropy_server, repository_id, packages): """ Compress (and generate package tarball) the list of given spm package names inside the given Entropy repository. """ entropy_server.output( blue(_("Compressing packages")), header=brown(" @@ ")) generated_packages = collections.deque() store_dir = entropy_server._get_local_store_directory(repository_id) if not os.path.isdir(store_dir): try: os.makedirs(store_dir) except (IOError, OSError) as err: entropy_server.output( "%s: %s" % (_("Cannot create store directory"), err), header=brown(" !!! "), importance=1, level="error") return generated_packages, 1 for count, spm_name in enumerate(packages, 1): entropy_server.output( teal(spm_name), header=brown(" # "), count=(count, len(packages))) try: pkg_list = entropy_server.Spm().generate_package(spm_name, store_dir) generated_packages.append(pkg_list) except OSError: entropy.tools.print_traceback() entropy_server.output( bold(_("Ignoring broken Spm entry, please recompile it")), header=brown(" !!! "), importance=1, level="warning") if not generated_packages: entropy_server.output( red(_("Nothing to do, check later.")), header=brown(" * ")) return generated_packages, 0 return generated_packages, None
def _advise_packages_update(self, entropy_client): """ Warn user about critical package updates, if any. """ client_settings = entropy_client.ClientSettings() misc_settings = client_settings['misc'] splitdebug = misc_settings['splitdebug'] forced_updates = misc_settings.get('forcedupdates') if forced_updates: crit_atoms, crit_matches = \ entropy_client.calculate_critical_updates() if crit_atoms: entropy_client.output("") entropy_client.output("") update_msg = _("Please update the following " "critical packages") entropy_client.output("%s:" % (purple(update_msg), ), level="warning") for name in sorted(crit_atoms): entropy_client.output(brown(name), header=darkred(" # "), level="warning") entropy_client.output(darkgreen( _("You should install them as " "soon as possible")), header=darkred(" !!! "), level="warning") entropy_client.output("") entropy_client.output("")
def _read_lic_selection(): entropy_client.output(darkred(_("Please select an option")), header=" ") entropy_client.output("(%d) %s" % (1, darkgreen(_("Read the license"))), header=" ") entropy_client.output( "(%d) %s" % (2, brown(_("Accept the license (I've read it)"))), header=" ") entropy_client.output("(%d) %s" % (3, darkred( _("Accept the license and don't " "ask anymore (I've read it)"))), header=" ") entropy_client.output("(%d) %s" % (0, bold(_("Quit"))), header=" ") # wait user interaction try: action = readtext( " %s: " % (_("Your choice (type a number and press enter)"), )) except EOFError: action = None return action
def notify(self): """ Overridden from BaseAntiMatterResult """ for package in self._result: if self._nsargs.extended: cp = package.key() slot = package.slot() from_ver = "x" inst = package.installed() if inst is not None: from_ver = inst.version to_ver = "x" avail = package.available() if avail is not None: to_ver = avail.version name = "%s:%s [%s->%s]" % (darkgreen(cp), brown(slot), teal(from_ver), purple(to_ver)) elif self._nsargs.verbose: name = package.target() else: name = package.keyslot() if self._nsargs.quiet: print_generic(name) else: print_info(name)
def graph_packages(packages, entropy_client, complete = False, repository_ids = None, quiet = False): found = False for package in packages: match = entropy_client.atom_match(package, match_repo = repository_ids) if match[0] == -1: continue if not quiet: entropy_client.output( darkgreen("%s %s..." % ( _("Graphing"), purple(package),) ), header=brown(" @@ ")) found = True pkg_id, repo_id = match repodb = entropy_client.open_repository(repo_id) g_pkg = repodb.retrieveAtom(pkg_id) _graph_package(match, g_pkg, entropy_client, show_complete = complete, quiet = quiet) if not found: entropy_client.output( purple(_("No packages found")), level="warning", importance=1) return 1 return 0
def show_successful_download(down_list, data_transfer): for _pkg_id, repository_id, fname, _cksum, _signatures in down_list: best_mirror = get_best_mirror(repository_id) mirrorcount = repo_uris[repository_id].index(best_mirror) + 1 basef = os.path.basename(fname) txt = "( mirror #%s ) [%s] %s %s %s" % ( mirrorcount, brown(basef), darkred(_("success")), blue("@"), red(self._get_url_name(best_mirror)), ) self._entropy.output( txt, importance = 1, level = "info", header = red(" ## ") ) if data_transfer: txt = " %s: %s%s%s" % ( blue(_("Aggregated transfer rate")), bold(entropy.tools.bytes_into_human(data_transfer)), darkred("/"), darkblue(_("second")), ) self._entropy.output( txt, importance = 1, level = "info", header = red(" ## ") )
def _advise_packages_update(self, entropy_client): """ Warn user about critical package updates, if any. """ client_settings = entropy_client.ClientSettings() misc_settings = client_settings['misc'] splitdebug = misc_settings['splitdebug'] forced_updates = misc_settings.get('forcedupdates') if forced_updates: crit_atoms, crit_matches = \ entropy_client.calculate_critical_updates() if crit_atoms: entropy_client.output("") entropy_client.output("") update_msg = _("Please update the following " "critical packages") entropy_client.output("%s:" % (purple(update_msg),), level="warning") for name in sorted(crit_atoms): entropy_client.output( brown(name), header=darkred(" # "), level="warning") entropy_client.output( darkgreen(_("You should install them as " "soon as possible")), header=darkred(" !!! "), level="warning") entropy_client.output("") entropy_client.output("")
def _show_notice(self, entropy_server, key, mydict): """ Print notice board entry content """ mytxt = "[%s] [%s]" % ( blue(str(key)), brown(mydict['pubDate']), ) entropy_server.output(mytxt) entropy_server.output("", level="generic") entropy_server.output( "%s: %s" % (darkgreen(_("Title")), purple(mydict['title'])), level="generic") entropy_server.output("", level="generic") entropy_server.output(mydict['description'], level="generic") entropy_server.output("", level="generic") mytxt = "%s: %s" % ( darkgreen(_("URL")), blue(mydict['link']), ) entropy_server.output(mytxt) def fake_callback(dummy_s): return True input_params = [ ('idx', _('Press Enter to continue'), fake_callback, False) ] data = entropy_server.input_box( '', input_params, cancel_button = True)
def asker(spm_name): entropy_server.output( darkred(spm_name), header=brown(" # ")) rc = entropy_server.ask_question( _("Add this package?")) return rc == _("Yes")
def _restore(self, entropy_client, inst_repo): """ Solo Smart Restore command. """ path = entropy_client.installed_repository_path() repo_list = entropy_client.installed_repository_backups() if not repo_list: entropy_client.output(darkred(_("No backups found")), header=brown(" @@ "), level="warning", importance=1) return 1 repo_list_new = [] repo_data = [] for repo_path in repo_list: try: ts = os.path.getmtime(repo_path) except OSError as err: entropy.tools.print_traceback() continue h_ts = entropy.tools.convert_unix_time_to_human_time(ts) repo_list_new.append("[%s] %s" % ( h_ts, repo_path, )) repo_data.append(repo_path) def fake_cb(s): return s input_params = [('db', ( 'combo', (_('Select the repository to restore'), repo_list_new), ), fake_cb, True)] while True: data = entropy_client.input_box(darkred( _("Entropy Installed Packages Repository backups")), input_params, cancel_button=True) if data is None: return 1 myid, dbx = data['db'] try: backup_path = repo_data.pop(myid - 1) except IndexError: continue if not os.path.isfile(backup_path): continue break inst_repo.commit() status, err_msg = entropy_client.restore_repository( backup_path, path, inst_repo.repository_id()) if status: return 0 return 1
def _show_graph_legend(entropy_client): entropy_client.output("%s:" % (purple(_("Legend")),)) entropy_client.output("[%s] %s" % (blue("x"), blue(_("packages passed as arguments")),)) entropy_client.output("[%s] %s" % (darkgreen("x"), darkgreen(_("packages with no further dependencies")),)) entropy_client.output("[%s] %s" % (purple("x"), purple(_("packages with further dependencies (node)")),)) entropy_client.output("[%s] %s" % (brown("x"), brown(_("packages already pulled in as dependency in upper levels (circularity)")),)) entropy_client.output("="*40, level="generic")
def revgraph_packages(packages, entropy_client, complete = False, repository_ids = None, quiet = False): if repository_ids is None: repository_ids = [entropy_client.installed_repository( ).repository_id()] found = False for repository_id in repository_ids: entropy_repository = entropy_client.open_repository(repository_id) for package in packages: pkg_id, pkg_rc = entropy_repository.atomMatch(package) if pkg_rc == 1: continue if not quiet: entropy_client.output( darkgreen("%s %s..." % ( _("Reverse graphing installed package"), purple(package),) ), header=brown(" @@ ")) found = True g_pkg = entropy_repository.retrieveAtom(pkg_id) _revgraph_package(entropy_client, pkg_id, g_pkg, entropy_repository, show_complete = complete, quiet = quiet) if not found: entropy_client.output( purple(_("No packages found")), level="warning", importance=1) return 1 return 0
def __show_download_files_info(self): count = 0 pl = self._url_path_list[:] TextInterface.output( "%s: %s %s" % ( darkblue(_("Aggregated download")), darkred(str(len(pl))), darkblue(ngettext("item", "items", len(pl))), ), importance = 0, level = "info", header = purple(" ## ") ) for url, save_path in pl: count += 1 fname = os.path.basename(url) uri = spliturl(url)[1] TextInterface.output( "[%s] %s => %s" % ( darkblue(str(count)), darkgreen(uri), blue(fname), ), importance = 0, level = "info", header = brown(" # ") )
def _show_did_you_mean(self, entropy_client, package, from_installed): """ Show "Did you mean?" results for the given package name. """ items = entropy_client.get_meant_packages( package, from_installed=from_installed) if not items: return mytxt = "%s %s %s %s %s" % ( bold(const_convert_to_unicode(" ?")), teal(_("When you wrote")), bold(const_convert_to_unicode(package)), darkgreen(_("You Meant(tm)")), teal(_("one of these below?")), ) entropy_client.output(mytxt) _cache = set() for pkg_id, repo_id in items: if from_installed: repo = entropy_client.installed_repository() else: repo = entropy_client.open_repository(repo_id) key_slot = repo.retrieveKeySlotAggregated(pkg_id) if key_slot not in _cache: entropy_client.output( enlightenatom(key_slot), header=brown(" # ")) _cache.add(key_slot)
def _show_notice(self, entropy_client, key, mydict): """ Show Notice Board element. """ mytxt = "[%s] [%s] %s: %s" % ( blue(str(key)), brown(mydict['pubDate']), _("Title"), darkred(mydict['title']), ) entropy_client.output(mytxt) mytxt = "%s:\n\n%s\n" % ( darkgreen(_("Content")), mydict['description'], ) entropy_client.output(mytxt) mytxt = "%s: %s" % ( darkgreen(_("Link")), blue(mydict['link']), ) entropy_client.output(mytxt) def fake_callback(s): return True input_params = [ ('idx', _("Press Enter to continue"), fake_callback, False)] entropy_client.input_box('', input_params, cancel_button = True)
def _show_notice(self, entropy_client, key, mydict): """ Show Notice Board element. """ mytxt = "[%s] [%s] %s: %s" % ( blue(str(key)), brown(mydict['pubDate']), _("Title"), darkred(mydict['title']), ) entropy_client.output(mytxt) mytxt = "%s:\n\n%s\n" % ( darkgreen(_("Content")), mydict['description'], ) entropy_client.output(mytxt) mytxt = "%s: %s" % ( darkgreen(_("Link")), blue(mydict['link']), ) entropy_client.output(mytxt) def fake_callback(s): return True input_params = [('idx', _("Press Enter to continue"), fake_callback, False)] entropy_client.input_box('', input_params, cancel_button=True)
def __export_key(self, entropy_server, repo_sec, is_pubkey, repo, store_path): """ Internal key export logic. """ key_msg = _("Exporting private key for repository") func_check = repo_sec.is_privkey_available if is_pubkey: func_check = repo_sec.is_pubkey_available key_msg = _("Exporting public key for repository") try: if not func_check(repo): entropy_server.output("%s: %s" % ( blue(_("No keypair available for repository")), purple(repo), ), level = "error" ) return 1 except repo_sec.KeyExpired: entropy_server.output("%s: %s" % ( darkred(_("Keypair is EXPIRED for repository")), purple(repo), ), level = "error" ) return 1 entropy_server.output("%s: %s" % (blue(key_msg), purple(repo),)) if is_pubkey: key_stream = repo_sec.get_pubkey(repo) else: key_stream = repo_sec.get_privkey(repo) # write to file try: with open(store_path, "w") as dest_w: dest_w.write(key_stream) dest_w.flush() except IOError as err: entropy_server.output("%s: %s [%s]" % ( darkgreen( _("Unable to export GPG key for repository")), bold(repo), err, ), level = "error" ) return 1 entropy_server.output("%s: %s [%s]" % ( darkgreen(_("Exported GPG key for repository")), bold(repo), brown(store_path), ), level = "info" ) return 0
def _info(self, entropy_client): """ Solo Security Info command. """ advisory_ids = self._nsargs.ids sec = entropy_client.Security() exit_st = 1 for advisory_id in advisory_ids: advisory = sec.advisory(advisory_id) if advisory is None: entropy_client.output( "%s: %s." % ( darkred(_("Advisory does not exist")), blue(advisory_id),), header=brown(" :: ")) continue self._print_advisory_information( entropy_client, advisory, key=advisory_id) exit_st = 0 return exit_st
def _list(self, entropy_client): """ Solo Repo List command. """ settings = entropy_client.Settings() excluded_repos = settings['repositories']['excluded'] available_repos = settings['repositories']['available'] default_repo = settings['repositories']['default_repository'] repositories = entropy_client.repositories() quiet = self._nsargs.quiet for repository in repositories: repo_data = available_repos.get(repository) desc = _("N/A") if repo_data is None: repo_data = excluded_repos.get(repository) if repo_data is not None: desc = repo_data.get('description', desc) if quiet: entropy_client.output(repository, level="generic") else: repo_str = " " if repository == default_repo: repo_str = purple("* ") entropy_client.output("%s%s\n %s" % ( repo_str, darkgreen(repository), brown(desc), ), level="generic") return 0
def _list(self, entropy_client): """ Solo Repo List command. """ settings = entropy_client.Settings() excluded_repos = settings['repositories']['excluded'] available_repos = settings['repositories']['available'] default_repo = settings['repositories']['default_repository'] repositories = entropy_client.repositories() quiet = self._nsargs.quiet for repository in repositories: repo_data = available_repos.get(repository) desc = _("N/A") if repo_data is None: repo_data = excluded_repos.get(repository) if repo_data is not None: desc = repo_data.get('description', desc) if quiet: entropy_client.output( repository, level="generic") else: repo_str = " " if repository == default_repo: repo_str = purple("* ") entropy_client.output( "%s%s\n %s" % ( repo_str, darkgreen(repository), brown(desc),), level="generic") return 0
def _show_notice(self, entropy_server, key, mydict): """ Print notice board entry content """ mytxt = "[%s] [%s]" % ( blue(str(key)), brown(mydict['pubDate']), ) entropy_server.output(mytxt) entropy_server.output("", level="generic") entropy_server.output("%s: %s" % (darkgreen(_("Title")), purple(mydict['title'])), level="generic") entropy_server.output("", level="generic") entropy_server.output(mydict['description'], level="generic") entropy_server.output("", level="generic") mytxt = "%s: %s" % ( darkgreen(_("URL")), blue(mydict['link']), ) entropy_server.output(mytxt) def fake_callback(dummy_s): return True input_params = [('idx', _('Press Enter to continue'), fake_callback, False)] data = entropy_server.input_box('', input_params, cancel_button=True)
def _read_lic_selection(): entropy_client.output( darkred(_("Please select an option")), header=" ") entropy_client.output( "(%d) %s" % ( 1, darkgreen(_("Read the license"))), header=" ") entropy_client.output( "(%d) %s" % ( 2, brown(_("Accept the license (I've read it)"))), header=" ") entropy_client.output( "(%d) %s" % ( 3, darkred(_("Accept the license and don't " "ask anymore (I've read it)"))), header=" ") entropy_client.output( "(%d) %s" % (0, bold(_("Quit"))), header=" ") # wait user interaction try: action = readtext( " %s: " % ( _("Your choice (type a number and press enter)"),) ) except EOFError: action = None return action