Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Script reports new/removed packages after 'emerge sync'
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 16138
Location: Colorado

PostPosted: Mon May 19, 2003 3:08 pm    Post subject: Script reports new/removed packages after 'emerge sync' Reply with quote

EDIT: Use /usr/sbin/esync, provided by app-portage/esearch.

Known bug(s):

This script looks at the portage tree, runs a sync, looks at the portage tree again, and reports if any packages are new or removed. Since the script runs an emerge sync, it must be run as root.

I'm no programmer, so I make no claims about quality of code. Warranty: "It works for me".

I decided to make this one in python after some problems with a similar bash script. Using python seems to have improved speed over using the bash/find method.

Code:
#!/usr/bin/env python2.2

import sys,portage,os
from output import *

if (not sys.stdout.isatty()) or (portage.settings["NOCOLOR"] in ["yes","true"]):
        nocolor()

def portTree():
        return portage.portdb.cp_all()


print green("*")+" Recording tree information before syncing."
before = portTree()

os.system("/usr/bin/emerge sync")

print green("*")+" Recording tree information after syncing.\n"
after = portTree()

rmd = before
new = after
matches = []

# Find common elements in before & after.
for pos in range(len(before)):
        if after.count(before[pos]):
                matched = after.index(before[pos])
                matches.append(after[matched])

# Remove common elements (matches) from before & after, creating "new" and "removed" packages.
for pos in range(len(matches)):
        new.remove(matches[pos])
        rmd.remove(matches[pos])

# Report results
print "- - - ---------------------------------------------------------------------"
print "New packages [%s]" % (len(new))
print "- - - ---------------------------------------------------------------------"
if (len(new)):
        for what in new:
                full_pkg = portage.best(portage.portdb.xmatch("match-all", (what.split("/")[1]) ))
                print green("*")+" "+what
                print "\t"+portage.portdb.aux_get(full_pkg, ["DESCRIPTION"])[0]
else:
        print yellow("*")+" No new packages."

print
print "- - - ---------------------------------------------------------------------"
print "Removed packages [%s]" % (len(rmd))
print "- - - ---------------------------------------------------------------------"
if (len(rmd)):
        for what in rmd:
                print yellow("*")+" "+what
else:
        print green("*")+" No packages removed."

print
print green("*")+" Done."



EDIT:
2003.05.20: Added import lines I somehow managed to omit.
2003.05.29: Added reference to aux_get(): ebuild for '' does not exist at: bug post.

_________________
lolgov. 'cause where we're going, you don't have civil liberties.

In Loving Memory
1787 - 2008


Last edited by pjp on Thu Dec 23, 2004 5:57 pm; edited 4 times in total
Back to top
View user's profile Send private message
GenKiller
n00b
n00b


Joined: 04 Mar 2003
Posts: 66
Location: United States of America

PostPosted: Tue May 20, 2003 3:18 am    Post subject: Reply with quote

Great to hear you made this script, as I've been looking for something like this now, and was just about to make one myself. I get an error, however, when I attempt to run it

Code:
warlord portage # ./portage
./portage: line 3: syntax error near unexpected token `('
./portage: line 3: `if (not sys.stdout.isatty()) or (portage.settings["NOCOLOR"] in ["yes","true"]):'


Any ideas? Is this script suppose to have a specific filename?
_________________
http://www.digital-drip.com
Back to top
View user's profile Send private message
handsomepete
Guru
Guru


Joined: 21 Apr 2002
Posts: 548
Location: Kansas City, MO

PostPosted: Tue May 20, 2003 3:33 am    Post subject: Reply with quote

Neato. Looking forward to playing with it.
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 16138
Location: Colorado

PostPosted: Tue May 20, 2003 7:52 pm    Post subject: Reply with quote

GenKiller wrote:
I get an error, however, when I attempt to run it ...
Woops... I left out a very important part... no idea how.
Incorrect snippet wrote:
Code:
#!/usr/bin/env python2.2

if (not sys.stdout.isatty()) or (portage.settings["NOCOLOR"] in ["yes","true"]):
        nocolor()


Corrected snippet wrote:
Code:
#!/usr/bin/env python2.2

import sys,portage,os
from output import *

if (not sys.stdout.isatty()) or (portage.settings["NOCOLOR"] in ["yes","true"]):
        nocolor()


Original post/script has been updated.
_________________
lolgov. 'cause where we're going, you don't have civil liberties.

In Loving Memory
1787 - 2008
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 16138
Location: Colorado

PostPosted: Tue May 20, 2003 7:57 pm    Post subject: Reply with quote

GenKiller wrote:
Is this script suppose to have a specific filename?
Anything should work. The old bash version suggested /usr/bin/emerge2. For testing, I was using em2. I have it as /usr/bin/es (emerge sync) now.
_________________
lolgov. 'cause where we're going, you don't have civil liberties.

In Loving Memory
1787 - 2008
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 16138
Location: Colorado

PostPosted: Thu May 29, 2003 5:58 pm    Post subject: Re: Script reports new/removed packages after 'emerge sync' Reply with quote

Code:
                print "\t"+portage.portdb.aux_get(full_pkg, ["DESCRIPTION"])[0]
That code breaks if there is no .ebuild file. When it fails, it will look something like this:
Code:
!!! aux_get(): ebuild for '' does not exist at:
!!!           
Traceback (most recent call last):
  File "/usr/bin/es", line 49, in ?
    print "\t"+portage.portdb.aux_get(full_pkg, ["DESCRIPTION"])[0]
  File "/usr/lib/python2.2/site-packages/portage.py", line 3333, in au
    raise KeyError
KeyError
I haven't looked into fixing it yet, but its on my list. In the meantime, if anyone is interested, feel free to submit corrections.
_________________
lolgov. 'cause where we're going, you don't have civil liberties.

In Loving Memory
1787 - 2008
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 16138
Location: Colorado

PostPosted: Thu May 29, 2003 6:44 pm    Post subject: Reply with quote

Code:
print "\t"+portage.portdb.aux_get(full_pkg, ["DESCRIPTION"])[0]
Will produce the following error (or similar) if an ebuild file is missing.
Code:
!!! aux_get(): ebuild for '' does not exist at:
!!!           
Traceback (most recent call last):
  File "/usr/bin/es", line 49, in ?
    print "\t"+portage.portdb.aux_get(full_pkg, ["DESCRIPTION"])[0]
  File "/usr/lib/python2.2/site-packages/portage.py", line 3333, in au
    raise KeyError
KeyError

I haven't worked on resolving it yet, though its on my list of things to do. Feel free to contribute corrections in the meantime.
_________________
lolgov. 'cause where we're going, you don't have civil liberties.

In Loving Memory
1787 - 2008
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum