Run 'dnf clean all' and return size in bytes recovered
()
| 681 | |
| 682 | |
| 683 | def 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 | |
| 703 | units = {"B": 1, "k": 10**3, "M": 10**6, "G": 10**9} |