Run 'yum clean all' and return size in bytes recovered
()
| 662 | |
| 663 | |
| 664 | def yum_clean(): |
| 665 | """Run 'yum clean all' and return size in bytes recovered""" |
| 666 | if os.path.exists('/var/run/yum.pid'): |
| 667 | msg = _( |
| 668 | "%s cannot be cleaned because it is currently running. Close it, and try again.") % "Yum" |
| 669 | raise RuntimeError(msg) |
| 670 | |
| 671 | old_size = FileUtilities.getsizedir('/var/cache/yum') |
| 672 | args = ['--enablerepo=*', 'clean', 'all'] |
| 673 | invalid = ['You need to be root', 'Cannot remove rpmdb file'] |
| 674 | try: |
| 675 | run_cleaner_cmd('yum', args, '^unused regex$', invalid) |
| 676 | except subprocess.CalledProcessError as e: |
| 677 | raise RuntimeError( |
| 678 | f"Error calling '{' '.join(str(part) for part in e.cmd)}':\n{e.output}") from e |
| 679 | new_size = FileUtilities.getsizedir('/var/cache/yum') |
| 680 | return old_size - new_size |
| 681 | |
| 682 | |
| 683 | def dnf_clean(): |