You are not logged in.
Pages: 1
A script to list all the packages currently installed, according to /var/log/pacman.log
it can help in case of a broken/lost pacman database (/var/lib/pacman)
Remember that packages installed during arch setup are not logged in /var/log/pacman.log, so they are found by this script only if they were upgraded later.
#!/usr/bin/env python
#
# pacfix.py: a script by pierluigi to list all the packages currently installed according to /var/log/pacman.log
pkg=[]
logfile = open("/var/log/pacman.log","r")
log=logfile.readlines()
for myline in log:
myarray = myline.strip("\n").split(" ")
if (myarray[2]=="installed" or myarray[2]=="upgraded"):
if (pkg.count(myarray[3])==0):
pkg.append(myarray[3])
if (myarray[2]=="removed"):
if (pkg.count(myarray[3])!=0):
pkg.remove(myarray[3])
pkg.sort()
for p in pkg:
print p
Available also in "pactools" @ AUR
Last edited by Pierluigi (2007-02-06 19:43:15)
Offline
It doesn't work for me:
$ pacfix.py | wc -l
665
$ pacman -Q | wc -l
530
pacfix shows some removed packages
Offline
well that's a bit strange. this script has been tested on my system and by a couple of italian users.
i will investigate what it can be...
Offline
umm, this isn't reliable ... why not use /var/lib/pacman/local ?
i wrote this script some time ago .. it's on this forum somewhere with other scripts that do more or less same thing...
#!/usr/bin/python
import os
pd = '/var/lib/pacman/'
total = 0
def okd(prfx,dr):
if os.path.isdir(prfx+dr) and dr[0] != '.' and dr != 'local':
return True
else:
return False
sep = '--------------------------------------'
print 'Misc. Stats on Packages in Pacman DBs.\n'+sep
for db in os.listdir(pd):
if okd(pd,db):
count = 0
for pk in os.listdir(pd+db):
if okd(pd+db+'/',pk):count += 1
print 'Packages in ['+db+'] Repo. :'+str(count)
total += count
installed = 0
for ix in os.listdir(pd+'/local'):
if okd(pd+'/local/',ix):installed += 1
print sep+'\nThere are '+str(total)+' Packages in Total,\n\
of which '+str(installed)+' are Installed.\n'+sep
[root@lithium4 tmp]# /cc/port/bin/tellpkg
Misc. Stats on Packages in Pacman DBs.
--------------------------------------
Packages in [current] Repo. :563
Packages in [extra] Repo. :1971
Packages in [unstable] Repo. :101
Packages in [community] Repo. :1114
Packages in [testing] Repo. :41
--------------------------------------
There are 3790 Packages in Total,
of which 461 are Installed.
--------------------------------------
=========================
[root@lithium4 tmp]# pacfix.py | wc -l
132
Last edited by noriko (2007-02-06 21:04:08)
The.Revolution.Is.Coming - - To fight, To hunger, To Resist!
Offline
Misc. Stats on Packages in Pacman DBs.
--------------------------------------
Packages in [lost+found] Repo. :0
Packages in [current] Repo. :563
Packages in [extra] Repo. :1971
Packages in [unstable] Repo. :101
Packages in [community] Repo. :1114
Packages in [archie] Repo. :26
Packages in [obarchie] Repo. :5
Packages in [nooms] Repo. :34
Packages in [release] Repo. :334
Packages in [staging] Repo. :142
Packages in [testing] Repo. :25
Packages in [takhis] Repo. :59
--------------------------------------
There are 4374 Packages in Total,
of which 1050 are Installed.
oops
Mr Green
Offline
umm, this isn't reliable ... why not use /var/lib/pacman/local ?
because i wrote it to help an user who accidentally removed his pacman database (/var/lib/pacman/local).
I know that should be better backing up the DB, but this script may help when no backup is available and you want to know which packages have been installed.
Offline
Nice script, for me it was very accurate, here's a diff below
$ comm -3 <(pacman -Q|cut -d' ' -f1) <(python pacfix.py)
beryl-plugins
control-center
inside
unifdef
I checked the pacman.log file, and well its not the scripts fault, pacman just didn't log the removal of some of those files *shrug*.
Anyways, one of them was a mistake 'inside', here's the line where it got it from.
[2008-03-01 17:31] installed inside a Guest Computer to improve its performance and
[2008-03-01 17:31] cooperation with the rest of the Product. In addition to and independent
"Whatever can go wrong, will go wrong" - Murphy's law
Anywho, I guess a quick check for # of fields would fix this.
EDIT: For those of you that don't have python (I assume this is less than a handfull), here's an awk solution.
awk 'NF>7{next} $3~/installed|upgraded/{a[$4]} $3~/removed/{delete a[$4]} END {for (x in a){print x}}' /var/log/pacman.log |sort
Last edited by sabooky (2008-06-18 03:51:34)
Offline
The 'awk' script by 'sabooky' is very neat and worked well.
The 'python' script by 'Pierluigi' was also good, but failed because my "pacman.log" has some lines with only two words. Here's a slightly modified version:
#!/usr/bin/env python
#
# pacfix.py: a script by pierluigi to list all the packages currently installed according to /var/log/pacman.log
# 2008-07-04: Modified by Chris Giles to prevent failure when "pacman.log" has lines with only two words
pkg=[]
logfile = open("/var/log/pacman.log","r")
#logfile = open("./pacman.log","r")
log=logfile.readlines()
for myline in log:
myarray = myline.strip("\n").split(" ")
if len(myarray) >= 3 :
if (myarray[2]=="installed" or myarray[2]=="upgraded"):
if (pkg.count(myarray[3])==0):
pkg.append(myarray[3])
if (myarray[2]=="removed"):
if (pkg.count(myarray[3])!=0):
pkg.remove(myarray[3])
pkg.sort()
for p in pkg:
print p
Offline
Pages: 1