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

Function dnf_clean

bleachbit/Unix.py:683–700  ·  view source on GitHub ↗

Run 'dnf clean all' and return size in bytes recovered

()

Source from the content-addressed store, hash-verified

681
682
683def dnf_clean():
684 """Run 'dnf clean all' and return size in bytes recovered"""
685 if os.path.exists('/var/run/dnf.pid'):
686 msg = _(
687 "%s cannot be cleaned because it is currently running. Close it, and try again.") % "Dnf"
688 raise RuntimeError(msg)
689
690 old_size = FileUtilities.getsizedir('/var/cache/dnf')
691 args = ['--enablerepo=*', 'clean', 'all']
692 invalid = ['You need to be root', 'Cannot remove rpmdb file']
693 try:
694 run_cleaner_cmd('dnf', args, '^unused regex$', invalid)
695 except subprocess.CalledProcessError as e:
696 raise RuntimeError(
697 f"Error calling '{' '.join(str(part) for part in e.cmd)}':\n{e.output}") from e
698 new_size = FileUtilities.getsizedir('/var/cache/dnf')
699
700 return old_size - new_size
701
702
703units = {"B": 1, "k": 10**3, "M": 10**6, "G": 10**9}

Callers 1

test_dnf_cleanMethod · 0.90

Calls 2

run_cleaner_cmdFunction · 0.85
joinMethod · 0.80

Tested by 1

test_dnf_cleanMethod · 0.72