­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ """ Support for Gentoolkit """ import os HAS_GENTOOLKIT = False try: from gentoolkit.eclean import clean, cli from gentoolkit.eclean import exclude as excludemod from gentoolkit.eclean import search HAS_GENTOOLKIT = True except ImportError: pass # Define the module's virtual name __virtualname__ = "gentoolkit" def __virtual__(): """ Only work on Gentoo systems with gentoolkit installed """ if __grains__["os"] == "Gentoo" and HAS_GENTOOLKIT: return __virtualname__ return ( False, "The gentoolkitmod execution module cannot be loaded: either the system is not" " Gentoo or the gentoolkit.eclean python module not available", ) def revdep_rebuild(lib=None): """ Fix up broken reverse dependencies lib Search for reverse dependencies for a particular library rather than every library on the system. It can be a full path to a library or basic regular expression. CLI Example: .. code-block:: bash salt '*' gentoolkit.revdep_rebuild """ cmd = "revdep-rebuild -i --quiet --no-progress" if lib is not None: cmd += f" --library={lib}" return __salt__["cmd.retcode"](cmd, python_shell=False) == 0 def _pretty_size(size): """ Print sizes in a similar fashion as eclean """ units = [" G", " M", " K", " B"] while units and size >= 1000: size = size / 1024.0 units.pop() return f"{round(size, 1)}{units[-1]}" def _parse_exclude(exclude_file): """ Parse an exclude file. Returns a dict as defined in gentoolkit.eclean.exclude.parseExcludeFile """ if os.path.isfile(exclude_file): exclude = excludemod.parseExcludeFile(exclude_file, lambda x: None) else: exclude = dict() return exclude def eclean_dist( destructive=False, package_names=False, size_limit=0, time_limit=0, fetch_restricted=False, exclude_file="/etc/eclean/distfiles.exclude", ): """ Clean obsolete portage sources destructive Only keep minimum for reinstallation package_names Protect all versions of installed packages. Only meaningful if used with destructive=True size_limit Don't delete distfiles bigger than . is a size specification: "10M" is "ten megabytes", "200K" is "two hundreds kilobytes", etc. Units are: G, M, K and B. time_limit