Clean cache in pacman
()
| 734 | |
| 735 | |
| 736 | def pacman_cache(): |
| 737 | """Clean cache in pacman""" |
| 738 | if os.path.exists('/var/lib/pacman/db.lck'): |
| 739 | msg = _( |
| 740 | "%s cannot be cleaned because it is currently running. Close it, and try again.") % "pacman" |
| 741 | raise RuntimeError(msg) |
| 742 | if not exe_exists('paccache'): |
| 743 | raise RuntimeError('paccache not found') |
| 744 | cmd = ['paccache', '-rk0'] |
| 745 | (rc, stdout, stderr) = General.run_external(cmd) |
| 746 | if rc > 0: |
| 747 | raise RuntimeError(f'paccache raised error {rc}: {stderr}') |
| 748 | # parse line like this: "==> finished: 3 packages removed (42.31 MiB freed)" |
| 749 | cregex = re.compile( |
| 750 | r"==> finished: ([\d.]+) packages removed \(([\d.]+\s+[BkMG]) freed\)") |
| 751 | match = cregex.search(stdout) |
| 752 | if match: |
| 753 | return parse_size(match.group(2)) |
| 754 | return 0 |
| 755 | |
| 756 | |
| 757 | def snap_parse_list(stdout): |