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

Function pacman_cache

bleachbit/Unix.py:736–754  ·  view source on GitHub ↗

Clean cache in pacman

()

Source from the content-addressed store, hash-verified

734
735
736def 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
757def snap_parse_list(stdout):

Callers 2

test_pacman_cacheMethod · 0.90

Calls 2

exe_existsFunction · 0.90
parse_sizeFunction · 0.85

Tested by 2

test_pacman_cacheMethod · 0.72