You are not logged in.

#1 2009-05-12 23:39:05

kumyco
Member
From: somewhere
Registered: 2008-06-23
Posts: 153
Website

PkgHist -- get the list of installed packages from pacman.log

an old script i wrote last October:o, cleaned it up in hopes of getting it tested for ARMTools
the script in the wiki doesn't actually work as it tracks all packages you ever installed
and some of us have packages that are installed up not in pacman.log

#!/usr/bin/env python

'''
-------------------------------------------------------------------------------
                        Pirat-libre Public License 1.12
-------------------------------------------------------------------------------
Copyme (k) Nathan K. Bathory <kumyco@kh.nu>. Some Rights Reserved.

Permission is hereby granted to any intelligent being obtaining a copy
of this work, to copy and distribute as-is or modified
copies of this work as one sees fit, subject to the following clauses.
-------------------------------------------------------------------------------
     Terms and conditions for Copying, Distribution and Modification
-------------------------------------------------------------------------------
  2. All warranties, expressed or implied, are disclaimed.
-------------------------------------------------------------------------------
'''

import re, sys

if not '-l' in sys.argv and not '--list' in sys.argv:
    print 'Usage:'
    print '       -l | --list -- list all packages installed, based on pacman.log'
    print '\n Note: some packages may be missing in the list,'
    print '  so if you installed group [base] at install,'
    print '  then you should pass that to pacman as well if you re-install.'
    sys.exit(0)

LOGFILE = '/var/log/pacman.log'

fp = open(LOGFILE)
try:
    log = fp.read()
finally:
    fp.close()

history = {
    'installed': {},
    'removed': {},
    'upgraded': {}
}

for match in re.findall('\] (installed|removed|upgraded) (.+?) \(', log):
    history[match[0]][match[1]] = history[match[0]].get(match[1], 0) + 1

installed = history['installed']
removed = history['removed']
upgraded = history['upgraded']

# -- some packages, (at least) in older Arch installs don't get registered in pacman.log
# -- so track them from when they get upgraded
for pkg in upgraded:
    if not installed.get(pkg):
        installed[pkg] = upgraded[pkg]

for pkg in installed:
    if removed.get(pkg, 0) < installed[pkg]:
        print pkg

please attach your pacman.log if you test it and it misses anything

you can check if it works by

pkghist --list | sort > /tmp/-out-ph
pacman -Qq > /tmp/-out-pm

then

diff /tmp/-out-p{h,m}

or

comm -3 /tmp/-out-p{h,m}

Offline

Board footer

Powered by FluxBB