You are not logged in.
Pages: 1
Hi,
I usually install programs, just to test out new features, and i always forget which ones ive installed so it takes a while looking through the pacman log to fiind which ones ive removed and which ones i havn't.
So i created this quick and dirty little python script.
#!/usr/bin/env python
installedfile = open('/var/log/pacman.log', 'r')
removedfile = open('/var/log/pacman.log', 'r')
foundprog = False
for line in installedfile:
### If current line in file doesnt have any installed programs, skip to next line in file ###
curIProgStart = line.find('] installed ')
if curIProgStart == -1: continue
### Remove version info ###
curIProgEnd = line.find('(')
### Get the installed program name ###
installedprog = line[curIProgStart+12:curIProgEnd]
### Get the date which the program was installed ###
curIDateEnd = line.find(']')
curDate = line[1:curIDateEnd]
foundprog = False
removedfile.seek(0)
for line1 in removedfile:
### Get Removed program name ###
curRProgStart = line1.find('] removed ')
### Remove version info ###
curRProgEnd = line1.find('(')
removedprog = line1[curRProgStart+10:curRProgEnd]
if removedprog == installedprog:
### If the date of Removed program is less than the installed program ###
### e.g. if it has been installed and removed before ###
### Then skip it, otherwise it must have been removed ###
curRDateEnd = line1.find(']')
curRDate = line1[1:curRDateEnd]
if curRDate >= curDate:
foundprog = True
continue
### If program hasnt been found to be removed then it must still be installed ###
#removedfile.close()
if foundprog == False:
print "Installed: " , curDate , " " , installedprog.rstrip()
installedfile.close()
removedfile.close()
If anyone has any suggestions to improve it id like to hear them
EDIT: Added #!/usr/bin/env python
Last edited by Kane (2008-06-06 19:29:34)
Offline
Nice I've been wondering whether one of these existed for a while now.
Edit: a suggestion - add a #!/usr/bin/env python
so we can copy and paste and run
Last edited by bavardage (2008-06-06 17:58:52)
blog - github - facebook - google profile
Offline
OK i've changed it, thanks
Be warned im sure there are lots of little bugs that i havnt noticed as im only just a beginner lol
Last edited by Kane (2008-06-06 18:14:48)
Offline
OK i've changed it, thanks
Be warned im sure there are lots of little bugs that i havnt noticed as im only just a beginner
lol
Is it me or are installedfile and removedfile the same?
If so, might I suggest you make it into one variable?
As it seems, you're already splitting both loops, so it would just be a matter of renaming both (and deleting 2 lines: one on the top, one on the bottom), and just let the seek(0) where it is.
The reason you've probably found that you _need_ to seek in the first place is because it's the same file. [I'm actually assuming atm]
Point being, it would be somewhat more clean.
Also, maybe as a patch or some new version of it (if you're interested in going on with it)
I would make it into a class -> and write an "example" implementation.
That way other coders can use the class, without having the need to write it themselves (therefore probably saving time, effort, and headache). And with some luck you'll even get some support from them too ^^
Apart from all what I just typed: Great idea! And keep up the work
My coding blog (or an attempt at it)
Archer start page (or an attempt at it)
Offline
Thanks for the feedback X/ax
Yes you're probably right about the two variables, i originally started out with two grep results and worked from there, but now it can probably be cleaned up alot more.
I'll also have a go at the class thing, i didnt implement that in the first place as it was just a simple little script but after thinking about it there may be some more features i might like implement.
But right now its bed time
Offline
ok heres an updated version thats alot more efficient, still havnt made it into a class yet.
#!/usr/bin/env python
logfile = open('/var/log/pacman.log', 'r')
foundremovedprog = False
log = logfile.readlines()
for i in range(len(log)):
### If current line in file doesnt have any installed programs, skip to next line in file ###
installedProgStart = log[i].find('] installed ')
if installedProgStart == -1: continue
### Remove version info ###
installedProgEnd = log[i].find('(')
### Get the installed program name ###
installedProg = log[i][installedProgStart+12:installedProgEnd]
### Get the date which the program was installed ###
installedDateEnd = log[i].find(']')
installedDate = log[i][1:installedDateEnd]
foundremovedprog = False
### Start looking for removed program after current program log[j+i] ###
for j in range(len(log[i:])):
### Get Removed program name ###
removedProgStart = log[j+i].find('] removed ')
### Remove version info ###
removedProgEnd = log[j+i].find('(')
removedProg = log[j+i][removedProgStart+10:removedProgEnd]
if removedProg == installedProg:
### If the date of Removed program is less than the installed program ###
### e.g. if it has been installed and removed before ###
### Then skip it, otherwise it must have been removed ###
removedDateEnd = log[j+i].find(']')
removedDate = log[j+i][1:removedDateEnd]
if removedDate >= installedDate:
foundremovedprog = True
### If program hasnt been found to be removed then it must still be installed ###
if foundremovedprog == False:
print "Installed: " , installedDate , " " , installedProg.rstrip()
logfile.close()
Offline
Pages: 1