MCPcopy Create free account
hub / github.com/bleachbit/bleachbit / dnf_autoremove

Function dnf_autoremove

bleachbit/Unix.py:712–733  ·  view source on GitHub ↗

Run 'dnf autoremove' and return size in bytes recovered.

()

Source from the content-addressed store, hash-verified

710
711
712def dnf_autoremove():
713 """Run 'dnf autoremove' and return size in bytes recovered."""
714 if os.path.exists('/var/run/dnf.pid'):
715 msg = _(
716 "%s cannot be cleaned because it is currently running. Close it, and try again.") % "Dnf"
717 raise RuntimeError(msg)
718 cmd = ['dnf', '-y', 'autoremove']
719 (rc, stdout, stderr) = General.run_external(cmd)
720 freed_bytes = 0
721 allout = stdout + stderr
722 if 'Error: This command has to be run under the root user.' in allout:
723 raise RuntimeError('dnf autoremove requires root permissions')
724 if rc > 0:
725 raise RuntimeError(f'dnf autoremove raised error {rc}: {stderr}')
726
727 cregex = re.compile(r"Freed space: ([\d.]+[\s]+[BkMG])")
728 match = cregex.search(allout)
729 if match:
730 freed_bytes = parse_size(match.group(1))
731 logger.debug(
732 'dnf_autoremove >> total freed bytes: %s', freed_bytes)
733 return freed_bytes
734
735
736def pacman_cache():

Callers 2

Calls 1

parse_sizeFunction · 0.85

Tested by 2