Skip to content

Instantly share code, notes, and snippets.

@oprypin
Last active March 17, 2018 23:38
Show Gist options
  • Save oprypin/ffdf357916f43f5009910ef4089ed361 to your computer and use it in GitHub Desktop.
Save oprypin/ffdf357916f43f5009910ef4089ed361 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import re
last_lines = lines = None
with open('/var/log/pacman.log') as log_file:
for line in log_file:
if re.search(r'\btransaction started\b', line):
lines = []
elif re.search(r'\btransaction completed\b', line):
last_lines = lines
lines = None
elif lines is not None:
lines.append(line.strip())
to_upgrade = []
to_remove = []
for line in last_lines:
m = (re.search(r' removed (.+?) \((.+?)\)$', line) or
re.search(r' upgraded (.+?) \((.+?) -> .+?\)', line))
if m:
to_upgrade.append('/var/cache/pacman/pkg/{}-{}-*.pkg.tar.xz'.format(*m.groups()))
m = re.search(r' installed (.+?) \(.+?\)$', line)
if m:
to_remove.append('{}'.format(*m.groups()))
sep = ' \\\n '
print('sudo pacman -U' + ''.join(sep + pkg for pkg in to_upgrade))
print('sudo pacman -R' + ''.join(sep + pkg for pkg in to_remove))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment