def _files(self, entropy_server): """ Actual Eit files code. """ exit_st = 0 for package in self._packages: pkg_id, pkg_repo = entropy_server.atom_match(package) if pkg_id == -1: exit_st = 1 if not self._quiet: entropy_server.output( "%s: %s" % ( purple(_("Not matched")), teal(package)), level="warning", importance=1) continue entropy_repository = entropy_server.open_repository(pkg_repo) files = entropy_repository.retrieveContent( pkg_id, order_by="file") atom = entropy_repository.retrieveAtom(pkg_id) if self._quiet: for path in files: entropy_server.output(path, level="generic") else: for path in files: entropy_server.output(path) entropy_server.output( "[%s] %s: %s %s" % ( purple(pkg_repo), darkgreen(atom), bold(str(len(files))), teal(_("files found")))) return exit_st
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 _disable_repo(self, entropy_client, repo): """ Solo Repo Disable for given repository. """ disabled = False try: disabled = entropy_client.disable_repository(repo) except ValueError: entropy_client.output("[%s] %s" % ( purple(repo), blue(_("cannot disable repository")), ), level="warning", importance=1) return 1 if disabled: entropy_client.output("[%s] %s" % ( teal(repo), blue(_("repository disabled")), )) return 0 entropy_client.output("[%s] %s" % ( purple(repo), blue(_("cannot disable repository")), ), level="warning", importance=1) return 1
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 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 _files(self, entropy_server): """ Actual Eit files code. """ exit_st = 0 for package in self._packages: pkg_id, pkg_repo = entropy_server.atom_match(package) if pkg_id == -1: exit_st = 1 if not self._quiet: entropy_server.output( "%s: %s" % (purple(_("Not matched")), teal(package)), level="warning", importance=1) continue entropy_repository = entropy_server.open_repository(pkg_repo) files = entropy_repository.retrieveContent(pkg_id, order_by="file") atom = entropy_repository.retrieveAtom(pkg_id) if self._quiet: for path in files: entropy_server.output(path, level="generic") else: for path in files: entropy_server.output(path) entropy_server.output( "[%s] %s: %s %s" % (purple(pkg_repo), darkgreen(atom), bold(str( len(files))), teal(_("files found")))) return exit_st
def _disable_repo(self, entropy_client, repo): """ Solo Repo Disable for given repository. """ disabled = False try: disabled = entropy_client.disable_repository(repo) except ValueError: entropy_client.output( "[%s] %s" % ( purple(repo), blue(_("cannot disable repository")),), level="warning", importance=1) return 1 if disabled: entropy_client.output( "[%s] %s" % ( teal(repo), blue(_("repository disabled")),)) return 0 entropy_client.output( "[%s] %s" % ( purple(repo), blue(_("cannot disable repository")),), level="warning", importance=1) return 1
def _remove(self, entropy_server): """ Eit Repo Remove command. """ current_repos = entropy_server.repositories() exit_st = 0 for repository_id in self._nsargs.id: if repository_id not in current_repos: entropy_server.output( "[%s] %s" % ( purple(repository_id), blue(_("repository not available")),), level="warning", importance=1) exit_st = 1 continue parser = RepositoryConfigParser() removed = parser.remove(repository_id) if not removed: exit_st = 1 entropy_server.output( "[%s] %s" % ( purple(repository_id), blue(_("cannot remove repository")),), level="warning", importance=1) else: entropy_server.output( "[%s] %s" % ( purple(repository_id), blue(_("repository removed succesfully")),)) return exit_st
def _disable(self, entropy_client): """ Solo Repo Disable command. """ exit_st = 0 settings = entropy_client.Settings() excluded_repos = settings['repositories']['excluded'] available_repos = settings['repositories']['available'] for repo in self._nsargs.repo: if repo in excluded_repos: entropy_client.output( "[%s] %s" % ( purple(repo), blue(_("repository already disabled")),), level="warning", importance=1) exit_st = 1 continue if repo not in available_repos: entropy_client.output( "[%s] %s" % ( purple(repo), blue(_("repository not available")),), level="warning", importance=1) exit_st = 1 continue _exit_st = self._disable_repo(entropy_client, repo) if _exit_st != 0: exit_st = _exit_st return exit_st
def _scan_installed_packages(self, entropy_client, inst_repo, packages): """ Scan the Installed Packages repository for matches and return a list of matched package identifiers. """ package_ids = [] for package in packages: package_id, _result = inst_repo.atomMatch(package) if package_id != -1: package_ids.append(package_id) continue # support file paths and convert them to package_ids file_package_ids = inst_repo.isFileAvailable(package, get_id=True) if file_package_ids: package_ids.extend(file_package_ids) continue mytxt = "!!! %s: %s %s." % ( purple(_("Warning")), teal(const_convert_to_unicode(package)), purple(_("is not installed")), ) entropy_client.output("!!!", level="warning") entropy_client.output(mytxt, level="warning") entropy_client.output("!!!", level="warning") if len(package) > 3: self._show_did_you_mean(entropy_client, package, True) entropy_client.output("!!!", level="warning") return package_ids
def _scan_packages(self, entropy_client, inst_repo, packages): """ Scan the list of package names filtering out unmatched entries. """ found_pkgs = [] for package in packages: package_id, _pkg_rc = inst_repo.atomMatch(package) if package_id == -1: mytxt = "!!! %s: %s %s." % ( purple(_("Warning")), teal(const_convert_to_unicode(package)), purple(_("is not available")), ) entropy_client.output( "!!!", level="warning", importance=1) entropy_client.output( mytxt, level="warning", importance=1) entropy_client.output( "!!!", level="warning", importance=1) continue found_pkgs.append(package_id) return found_pkgs
def _scan_packages(self, entropy_client, packages, installed=False): """ Scan the list of package names filtering out unmatched entries. """ found_pkgs = [] for package in packages: if installed: repo = entropy_client.installed_repository() repo_id = repo.repository_id() package_id, _pkg_rc = repo.atomMatch(package) else: package_id, repo_id = entropy_client.atom_match(package) if package_id == -1: mytxt = "!!! %s: %s %s." % ( purple(_("Warning")), teal(const_convert_to_unicode(package)), purple(_("is not available")), ) entropy_client.output( "!!!", level="warning", importance=1) entropy_client.output( mytxt, level="warning", importance=1) entropy_client.output( "!!!", level="warning", importance=1) continue found_pkgs.append((package_id, repo_id)) return found_pkgs
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 _inject(self, entropy_server): """ Actual Eit inject code. """ extensions = entropy_server.Spm_class().binary_packages_extensions() etp_pkg_files = [] for pkg_path in self._packages: pkg_path = os.path.realpath(pkg_path) if not const_file_readable(pkg_path): entropy_server.output( "%s: %s" % (purple(pkg_path), teal(_("no such file or directory"))), importance=1, level="error") return 1 found = False for ext in extensions: if pkg_path.endswith("." + ext): etp_pkg_files.append(pkg_path) found = True break if not found: entropy_server.output( "%s: %s" % (purple(pkg_path), teal(_("unsupported extension"))), importance=1, level="error") return 1 if not etp_pkg_files: entropy_server.output(teal(_("no valid package paths")), importance=1, level="error") return 1 # in this case, no split package files are provided repository_id = entropy_server.repository() etp_pkg_files = [( [x], True, ) for x in etp_pkg_files] package_ids = entropy_server.add_packages_to_repository( repository_id, etp_pkg_files, ask=self._ask, reset_revision=self._reset_revision) if package_ids: # checking dependencies and print issues entropy_server.extended_dependencies_test([repository_id]) entropy_server.commit_repositories() if package_ids: return 0 return 1
def _move_copy(self, entropy_server): """ Execute package move or copy (depending on self._copy) from source repository and destination repository. If deps is true, also dependencies are pulled in. """ package_ids = [] if self._source == self._dest: entropy_server.output( "%s: %s" % (purple(_("source equals destination")), teal(self._dest)), importance=1, level="error") return 1 if self._dest not in entropy_server.repositories(): # destination repository not available entropy_server.output( "%s: %s" % (purple(_("repository not available")), teal(self._dest)), importance=1, level="error") return 1 # match for package in self._packages: p_matches, p_rc = entropy_server.atom_match(package, match_repo = [self._source], multi_match = True) if not p_matches: entropy_server.output( "%s: %s" % ( purple(_("Not matched")), teal(package)), level="warning", importance=1) else: package_ids += [pkg_id for pkg_id, r_id in p_matches if \ (pkg_id not in package_ids)] if (not self._packages) and (not package_ids): entropy_server.output( purple(_("Considering all the packages")), importance=1, level="warning") repo = entropy_server.open_repository(self._source) package_ids = repo.listAllPackageIds() if not package_ids: return 1 rc = False if self._copy: rc = entropy_server.copy_packages(package_ids, self._source, self._dest, pull_dependencies = self._deps) else: rc = entropy_server.move_packages(package_ids, self._source, self._dest, pull_dependencies = self._deps) if rc: return 0 return 1
def _inject(self, entropy_server): """ Actual Eit inject code. """ extensions = entropy_server.Spm_class( ).binary_packages_extensions() etp_pkg_files = [] for pkg_path in self._packages: pkg_path = os.path.realpath(pkg_path) if not const_file_readable(pkg_path): entropy_server.output( "%s: %s" % (purple(pkg_path), teal(_("no such file or directory"))), importance=1, level="error") return 1 found = False for ext in extensions: if pkg_path.endswith("."+ext): etp_pkg_files.append(pkg_path) found = True break if not found: entropy_server.output( "%s: %s" % (purple(pkg_path), teal(_("unsupported extension"))), importance=1, level="error") return 1 if not etp_pkg_files: entropy_server.output( teal(_("no valid package paths")), importance=1, level="error") return 1 # in this case, no split package files are provided repository_id = entropy_server.repository() etp_pkg_files = [([x], True,) for x in etp_pkg_files] package_ids = entropy_server.add_packages_to_repository( repository_id, etp_pkg_files, ask=self._ask, reset_revision=self._reset_revision) if package_ids: # checking dependencies and print issues entropy_server.extended_dependencies_test([repository_id]) entropy_server.commit_repositories() if package_ids: return 0 return 1
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 enlightenatom(atom): """ Colorize package atoms with standard colors. @param atom: atom string @type atom: string @return: colorized string @rtype: string """ entropy_rev = entropy.dep.dep_get_entropy_revision(atom) if entropy_rev is None: entropy_rev = '' else: entropy_rev = '~%s' % (str(entropy_rev),) entropy_tag = entropy.dep.dep_gettag(atom) if entropy_tag is None: entropy_tag = '' else: entropy_tag = '#%s' % (entropy_tag,) slot = entropy.dep.dep_getslot(atom) slot_pfx = "" if slot is None: slot = "" else: slot_pfx = etpConst['entropyslotprefix'] clean_atom = entropy.dep.remove_entropy_revision(atom) clean_atom = entropy.dep.remove_tag(clean_atom) clean_atom = entropy.dep.remove_slot(atom) only_cpv = entropy.dep.dep_getcpv(clean_atom) cpv_split = entropy.dep.catpkgsplit(only_cpv) if cpv_split is None: cat, name = only_cpv.split("/", 1) pv = "" rev = "r0" operator = "" else: operator = clean_atom[:len(clean_atom)-len(only_cpv)] cat, name, pv, rev = cpv_split pv = "-" + pv if rev == "r0": rev = '' else: rev = '-%s' % (rev,) return "%s%s%s%s%s%s%s%s%s" % ( purple(operator), teal(cat + "/"), darkgreen(name), purple(pv), bold(slot_pfx), darkred(slot), purple(rev), brown(entropy_tag), teal(entropy_rev),)
def _delete(self, entropy_server): """ Actual Eit key delete code. """ repo_sec = self._get_gpg(entropy_server) if repo_sec is None: return 1 repo = entropy_server.repository() entropy_server.output("%s: %s" % ( blue(_("Deleting keys for repository")), purple(repo),)) if not repo_sec.is_keypair_available(repo): entropy_server.output("%s: %s" % ( blue(_("No keys available for given repository")), purple(repo), ), level = "warning" ) return 0 answer = entropy_server.ask_question(_("Are you really sure?")) if answer == _("No"): return 1 try: key_meta = repo_sec.get_key_metadata(repo) except KeyError: entropy_server.output("%s: %s" % ( darkgreen(_("Keys metadata not available for")), bold(repo), ), level = "error" ) return 1 # remove signatures from repository database dbconn = entropy_server.open_server_repository( repo, read_only = False) dbconn.dropGpgSignatures() repo_sec.delete_keypair(repo) entropy_server.output("%s: %s" % ( darkgreen(_("Deleted GPG key with fingerprint")), bold(key_meta['fingerprint']), ), level = "info" ) 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 _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 _extract(self, entropy_client): """ Solo Pkg Extract command. """ files = self._nsargs.files 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 for _file in files: entropy_client.output( "%s: %s" % ( teal(_("working on package file")), purple(_file)), header=darkred(" @@ "), back=True) file_name = os.path.basename(_file) package_path = os.path.join( savedir, file_name + ".db") ext_rc = entropy.tools.dump_entropy_metadata( _file, package_path) if not ext_rc: entropy_client.output( "%s: %s" % ( teal(_("error during metadata extraction")), purple(_file)), header=darkred(" @@ "), level="error", importance=1) return 1 entropy_client.output( "%s: %s" % ( teal(_("metadata file generated")), purple(package_path)), header=darkred(" @@ ")) return 0
def _show_config_files_update(self, entropy_client): """ Inform User about configuration file updates, if any. """ entropy_client.output( blue(_("Scanning configuration files to update")), header=darkgreen(" @@ "), back=True) updates = entropy_client.ConfigurationUpdates() scandata = updates.get() if not scandata: entropy_client.output( blue(_("No configuration files to update.")), header=darkgreen(" @@ ")) return mytxt = ngettext( "There is %s configuration file needing update", "There are %s configuration files needing update", len(scandata)) % (len(scandata),) entropy_client.output( darkgreen(mytxt), level="warning") mytxt = "%s: %s" % ( purple(_("Please run")), bold("equo conf update")) entropy_client.output( darkgreen(mytxt), level="warning")
def _show_preserved_libraries(self, entropy_client): """ Inform User about preserved libraries living on the filesystem. This method is process and thread safe. """ inst_repo = entropy_client.installed_repository() with inst_repo.shared(): preserved_mgr = PreservedLibraries(inst_repo, None, frozenset(), root=etpConst['systemroot']) preserved = preserved_mgr.list() if preserved: mytxt = ngettext("There is %s preserved library on the system", "There are %s preserved libraries on the system", len(preserved)) % (len(preserved), ) entropy_client.output(darkgreen(mytxt), level="warning") for library, elfclass, path, atom in preserved: entropy_client.output("%s [%s:%s -> %s]" % ( darkred(path), purple(library), teal(const_convert_to_unicode(elfclass)), enlightenatom(atom), ))
def _show_help(self, *args): # equo help <foo> <bar> if len(self._args) > 1: # syntax error return -10 parser = argparse.ArgumentParser( description=_("Entropy Command Line Client, Equo"), epilog="http://www.sabayon.org", formatter_class=ColorfulFormatter) # filtered out in solo.main. Will never get here parser.add_argument( "--color", action="store_true", default=None, help=_("force colored output")) descriptors = SoloCommandDescriptor.obtain() descriptors.sort(key = lambda x: x.get_name()) group = parser.add_argument_group("command", "available commands") for descriptor in descriptors: if descriptor.get_class().HIDDEN: continue aliases = descriptor.get_class().ALIASES aliases_str = ", ".join([teal(x) for x in aliases]) if aliases_str: aliases_str = " [%s]" % (aliases_str,) name = "%s%s" % (purple(descriptor.get_name()), aliases_str) desc = descriptor.get_description() group.add_argument(name, help=darkgreen(desc), action="store_true") parser.print_help() if not self._args: return 1 return 0
def _upgrade_respawn(self, entropy_client): """ Respawn the upgrade activity if required. """ # It might be an Entropy bug and Entropy was proritized in the # install queue, ignoring the rest of available packages. # So, respawning myself again using execvp() should be a much # better idea. outcome = entropy_client.calculate_updates() if outcome['update']: entropy_client.output( "%s." % ( purple(_("There are more updates to install, " "reloading Entropy")),), header=teal(" @@ ")) # then spawn a new process entropy_client.shutdown() # hack to tell the resurrected equo to block on # locking acquisition os.environ['__EQUO_LOCKS_BLOCKING__'] = "1" # we will acquire them again in blocking mode, cross # fingers entropy.tools.release_entropy_locks(entropy_client) os.execvp("equo", sys.argv)
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_preserved_libraries(self, entropy_client): """ Inform User about preserved libraries living on the filesystem. This method is process and thread safe. """ inst_repo = entropy_client.installed_repository() with inst_repo.shared(): preserved_mgr = PreservedLibraries( inst_repo, None, frozenset(), root=etpConst['systemroot']) preserved = preserved_mgr.list() if preserved: mytxt = ngettext( "There is %s preserved library on the system", "There are %s preserved libraries on the system", len(preserved)) % (len(preserved),) entropy_client.output( darkgreen(mytxt), level="warning") for library, elfclass, path, atom in preserved: entropy_client.output( "%s [%s:%s -> %s]" % ( darkred(path), purple(library), teal(const_convert_to_unicode(elfclass)), enlightenatom(atom), ))
def _remove(self, entropy_client): """ Solo Repo Remove command. """ exit_st = 0 settings = entropy_client.Settings() excluded_repos = settings['repositories']['excluded'] available_repos = settings['repositories']['available'] repos = set(list(excluded_repos.keys()) + \ list(available_repos.keys())) for repo in self._nsargs.repo: if repo not in repos: entropy_client.output("[%s] %s" % ( purple(repo), blue(_("repository id not available")), ), level="warning", importance=1) exit_st = 1 continue _exit_st = self._remove_repo(entropy_client, repo) if _exit_st != 0: exit_st = _exit_st return exit_st
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 _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(self, entropy_server): """ Actual Eit notice show code. """ if self._repository_id is None: self._repository_id = entropy_server.repository() data = entropy_server.Mirrors.read_notice_board( self._repository_id) if data is None: entropy_server.output( purple(_("Notice board not available")), importance=1, level="error") return 1 items, counter = data while True: try: sel = self._show_notice_selector(entropy_server, '', items) except KeyboardInterrupt: return 0 if (sel >= 0) and (sel <= counter): self._show_notice(entropy_server, sel, items.get(sel)) elif sel == -1: return 0 return 0
def _normal_update(self, entropy_client): """ Execute update from this instance. """ repos = self._repositories[:] settings = entropy_client.Settings() if not repos: repos = list(settings['repositories']['available'].keys()) repo_conf = settings.get_setting_files_data()['repositories'] try: repo_intf = entropy_client.Repositories(repos, force=self._force) except AttributeError: entropy_client.output("%s%s %s" % ( darkred(" * "), purple(_("No repositories specified in")), repo_conf, ), level="error", importance=1) return 127 rc = repo_intf.sync() if not rc: for repository in repos: self._show_notice_board_summary(entropy_client, repository) return rc
def search(self, entropy_client, inst_repo): """ Solo Search command. """ if not self._quiet: entropy_client.output("%s..." % (darkgreen(_("Searching")), ), header=darkred(" @@ ")) matches_found = 0 for string in self._packages: results = self._search(entropy_client, inst_repo, string) matches_found += len(results) if not self._quiet: toc = [] toc.append(("%s:" % (blue(_("Keywords")), ), purple(', '.join(self._packages)))) toc.append(("%s:" % (blue(_("Found")), ), "%s %s" % ( matches_found, brown(ngettext("entry", "entries", matches_found)), ))) print_table(entropy_client, toc) if not matches_found: return 1 return 0
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 _search(self, entropy_server): """ Actual Eit search code. """ if self._repository_id is None: repository_ids = entropy_server.repositories() else: repository_ids = [self._repository_id] for repository_id in repository_ids: repo = entropy_server.open_repository(repository_id) count = 0 for package in self._packages: results = repo.searchPackages( package, order_by = "atom") for result in results: count += 1 print_package_info( result[1], entropy_server, repo, installed_search = True, extended = True, quiet = self._quiet ) if not count and not self._quiet: entropy_server.output( purple(_("Nothing found")), importance=1, level="warning") return 0
def warn_live_system(): print_warning("") print_warning(purple(_("Entropy is running off a Live System"))) print_warning( teal(_("Performance and stability could get" " severely compromised"))) print_warning("")
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(self, entropy_server): """ Actual Eit notice show code. """ if self._repository_id is None: self._repository_id = entropy_server.repository() data = entropy_server.Mirrors.read_notice_board(self._repository_id) if data is None: entropy_server.output(purple(_("Notice board not available")), importance=1, level="error") return 1 items, counter = data while True: try: sel = self._show_notice_selector(entropy_server, '', items) except KeyboardInterrupt: return 0 if (sel >= 0) and (sel <= counter): self._show_notice(entropy_server, sel, items.get(sel)) elif sel == -1: return 0 return 0
def _show_help(self, *args): # equo help <foo> <bar> if len(self._args) > 1: # syntax error return -10 parser = argparse.ArgumentParser( description=_("Entropy Command Line Client, Equo"), epilog="http://www.sabayon.org", formatter_class=ColorfulFormatter) # filtered out in solo.main. Will never get here parser.add_argument("--color", action="store_true", default=None, help=_("force colored output")) descriptors = SoloCommandDescriptor.obtain() descriptors.sort(key=lambda x: x.get_name()) group = parser.add_argument_group("command", "available commands") for descriptor in descriptors: if descriptor.get_class().HIDDEN: continue aliases = descriptor.get_class().ALIASES aliases_str = ", ".join([teal(x) for x in aliases]) if aliases_str: aliases_str = " [%s]" % (aliases_str, ) name = "%s%s" % (purple(descriptor.get_name()), aliases_str) desc = descriptor.get_description() group.add_argument(name, help=darkgreen(desc), action="store_true") parser.print_help() if not self._args: return 1 return 0
def _trigger_infofile_install(self): info_exec = Trigger.INSTALL_INFO_EXEC if not os.path.isfile(info_exec): self._entropy.logger.log( "[Trigger]", etpConst['logging']['normal_loglevel_id'], "[POST] %s is not available" % (info_exec,) ) return 0 env = os.environ.copy() for info_file in self._pkgdata['affected_infofiles']: self._entropy.output( "%s: %s" % ( teal(_("Installing info")), info_file,), importance = 0, header = purple(" # ") ) info_root = os.path.dirname(info_file) args = ( info_exec, "--dir-file=%s/dir" % (info_root,), info_file) proc = subprocess.Popen( args, stdout = sys.stdout, stderr = sys.stderr, env = env) proc.wait() # ignore any error return 0
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_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 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 _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 _match(self, entropy_server): """ Actual Eit match code. """ count = 0 for package in self._packages: pkg_id, pkg_repo = entropy_server.atom_match(package) if pkg_id == -1: continue count += 1 print_package_info( pkg_id, entropy_server, entropy_server.open_repository(pkg_repo), installed_search = True, extended = True, quiet = self._quiet ) if not count and not self._quiet: entropy_server.output( purple(_("Nothing found")), importance=1, level="warning") return 0