Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
pye - "pick your emerge" script
View unanswered posts
View posts from last 24 hours

Goto page 1, 2, 3, 4, 5, 6  Next  
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
dr_strange
Guru
Guru


Joined: 16 Apr 2002
Posts: 480
Location: Cambridge, UK

PostPosted: Thu Feb 12, 2004 11:19 pm    Post subject: pye - "pick your emerge" script Reply with quote

pick your emerge is a wrapper script for emerge, written in Python. Basically it parses the output of an emerge -p command (e.g. emerge -pu world), and numbers the packages entries so that the user can easily specifiy which ones he/she wants to emerge or maybe unmerge.


pye is at version 0.8.4 now. Features of the current version:

the script now uses the getopt.getopt() function for option parsing
- you have the following options now:
-v or --version: prints version
-h or --help
-s or --sync: makes emerge rsync before anything else
-e or --emergeopts: here you list the opts you would give to emerge: for instance pye -e uDv world would be equivalent with calling emerge -puDv world
-i or --info <package> will print all info about <package> that can be found in /var/db/pkg
-c or --category: will list all packages available in a portage category; e.g. pye -c games-fps will give you the list of all FPS games in portage, to choose from
-p or --prune: lists all installed packages, and the user can choose which nes to unmerge

When the packages are listed, you will have the following possibilities:

Code:

* you can simply enter the numbers comma-separated, e.g. 1,3,5,6,8
* you can also specify ranges: 2,4-7,9,11-16
* "a" or "all" merges all packages in the list
* "!" excludes the specified packages (and merges the rest): !4,6-8,13
* "x" excludes _and_ masks them in /etc/portage/package.mask or ~/.pye/pye.mask
* "q" quits pye


- Pye now boasts of a config file! It would reside in ~/.pye/pye.conf (you should manually create the dir and file for the time being), and can contain the following variables:

Code:

EMERGEOPTS = uDv
SILENT = no
MASKFILE_ETC_PORTAGE_PACKAGEMASK = no


With EMERGEOPTS you can specify your standard options for emerge (pye -e overrides this).
If SILENT is yes, pye will not print the list of choices as shown above.
The maskfile is a new feature. When you specify the packages to be excluded with an x (e.g. x3,6-9,23), pye will enter these packages either into /etc/portage/package.mask or ~/.pye/pye.mask, depending on the variable MASKFILE_ETC_PORTAGE_PACKAGEMASK (if yes, the former, if no, the latter). Those packages will not show up when you dp pye world the next time.
At the end, pye now gives emerge times for the individual packages.

The script is available from here. Please test extensively and suggest improvements.

TODO:

- --purge option to totally unmerge a package
- --sqlite backend
- HUSH variable to oppress emerge output

Enjoy,

dr_strange


Last edited by dr_strange on Fri Sep 24, 2004 6:36 am; edited 1 time in total
Back to top
View user's profile Send private message
skimitar
n00b
n00b


Joined: 30 Dec 2003
Posts: 20

PostPosted: Fri Feb 13, 2004 10:05 am    Post subject: Reply with quote

Thanks for that, a useful script indeed!

Just a note for those using it: cutting and pasting directly into an editor (I used nano, I'm guessing it'll be the same for other editors) will introduce leading spaces that python doesn't like, so you'll need to clean the script before it will run. I've seen this on other posts with python scripts.
_________________
"Internet! Is that thing still around? " - HJS
Back to top
View user's profile Send private message
reyneke
Guru
Guru


Joined: 09 Jan 2004
Posts: 542
Location: Augsburg / Germany

PostPosted: Fri Feb 13, 2004 11:02 am    Post subject: Reply with quote

Really nice script, thanx. Been looking for something like that a long time.
However, there's one thing missing: an option to quit without updating anything. I just don't like quitting with Ctrl-C.

Cya,

reyneke.
Back to top
View user's profile Send private message
dr_strange
Guru
Guru


Joined: 16 Apr 2002
Posts: 480
Location: Cambridge, UK

PostPosted: Fri Feb 13, 2004 8:48 pm    Post subject: Reply with quote

Okay, I wrote a "quit" option in. You can download the revised version from here:

dev.gentoo.org/~strangedr
Back to top
View user's profile Send private message
singular
n00b
n00b


Joined: 07 Jun 2003
Posts: 54

PostPosted: Sun Feb 15, 2004 12:01 am    Post subject: Reply with quote

Great script, I like it. I definitely will be using this script in the future, Thanks.

One enhancement would be to change this:
Code:

(r, w) = popen2.popen4('emerge -Up world')

To this:
Code:

if len(sys.argv) > 1 and sys.argv[1] == 'system':
    (r, w) = popen2.popen4('emerge -Up system')
else:
    (r, w) = popen2.popen4('emerge -Up world')

That way it will work with both 'world' and 'system' updates.

Not really a necessary change, but here is a slightly simpler version of the parsethis() function if you want it :
Code:

import string
def parsethis(be):
    """Extract cat/packagename out of emerge -p output"""
    pos = be.find("-", be.find("/"))
    while be[pos] not in string.digits:
        pos += 1
    ki = be[:pos-1].split("]")[1].strip()
    return ki
Back to top
View user's profile Send private message
revertex
l33t
l33t


Joined: 23 Apr 2003
Posts: 806

PostPosted: Sun Feb 15, 2004 5:31 am    Post subject: Reply with quote

Nice one, work's fine for me.

Just one question, this script call "emerge --update package" or just "emerge package"?

8O
Back to top
View user's profile Send private message
dr_strange
Guru
Guru


Joined: 16 Apr 2002
Posts: 480
Location: Cambridge, UK

PostPosted: Sun Feb 15, 2004 10:31 am    Post subject: Reply with quote

just emerge package, but you can easily modify it to suit your needs

singular: thanks for the enhancement, the .digit method simplifies it a lot! I am just a beginner in Python and programming.
Back to top
View user's profile Send private message
revertex
l33t
l33t


Joined: 23 Apr 2003
Posts: 806

PostPosted: Sun Feb 15, 2004 10:57 pm    Post subject: Reply with quote

dr_strange wrote:
just emerge package, but you can easily modify it to suit your needs

Python is like chinese to me, time to learn something new! :roll:
Back to top
View user's profile Send private message
dr_strange
Guru
Guru


Joined: 16 Apr 2002
Posts: 480
Location: Cambridge, UK

PostPosted: Mon Feb 16, 2004 8:02 am    Post subject: Reply with quote

revertex wrote:
dr_strange wrote:
just emerge package, but you can easily modify it to suit your needs

Python is like chinese to me, time to learn something new! :roll:


Here in this section:

if len(packstring) > 0:
os.system("emerge %s" % packstring)

at the end of the script you just insert --update after "emerge", before %s.
Back to top
View user's profile Send private message
Bastux
Guru
Guru


Joined: 15 Dec 2002
Posts: 369
Location: France - Paris

PostPosted: Mon Feb 16, 2004 9:00 am    Post subject: Reply with quote

Very usefull :lol: :lol: :lol:

Thank you!!
Back to top
View user's profile Send private message
revertex
l33t
l33t


Joined: 23 Apr 2003
Posts: 806

PostPosted: Mon Feb 16, 2004 9:02 am    Post subject: Reply with quote

I'm sorry dr_strange, this is exactly what i did before post, the "chinese thing" what i mean is the error message after insert the "--update" key.
Code:

pye
  File "/usr/local/bin/pye", line 48
    if emergethis == 'q':
    ^
SyntaxError: invalid syntax

I don't want steal your time with so irrelevant question.
Here follows what i did
Code:
if len(packstring) > 0:
    os.system("emerge --update %s" % packstring)
else:
    sys.stdout.write(red("No package given... exiting."))
    sys.exit(0)

I guess it's right, but python is a insanely flexible language!

--Off topic--

wdo rocks! it's must be in gentoolkit!
Once again thank you.
Back to top
View user's profile Send private message
dr_strange
Guru
Guru


Joined: 16 Apr 2002
Posts: 480
Location: Cambridge, UK

PostPosted: Mon Feb 16, 2004 10:41 am    Post subject: Reply with quote

Hmm.. it shouldn't give an error after inserting that... you sure you haven't deleted some thing, a quote or a bracket or something? I'll look into this when I get home.
Back to top
View user's profile Send private message
revertex
l33t
l33t


Joined: 23 Apr 2003
Posts: 806

PostPosted: Mon Feb 16, 2004 6:19 pm    Post subject: Reply with quote

I downloaded pye from your site (to prevent cute&paste errors), and just added "--update"
like you say.

I'm double check it using colordiff agaist the original downloaded and the only thing changed is "--update".

I'm edited using nano and scite (just for sure), both without wordwrap.

If i remove the "--update" previousily inserted, the script works again.

It's like "emerge" only wants to emerge, not update, eheh.

Really weird. 8O
Back to top
View user's profile Send private message
dr_strange
Guru
Guru


Joined: 16 Apr 2002
Posts: 480
Location: Cambridge, UK

PostPosted: Mon Feb 16, 2004 7:29 pm    Post subject: Reply with quote

Well, the list calls "emerge -Up world" in the first place, so does adding an --update at the end make a difference? After all only the packages that need an upgrade show up in the list.
Back to top
View user's profile Send private message
revertex
l33t
l33t


Joined: 23 Apr 2003
Posts: 806

PostPosted: Mon Feb 16, 2004 9:06 pm    Post subject: Reply with quote

You are right!
Your script first check for the latests packages, select them, then emerge the latest one.
"--update" here is a redundance, sorry for so idiotic question! :oops:
Stay so long in front my computer maybe has damage my brain, if i've got one
Thanks.
Back to top
View user's profile Send private message
dr_strange
Guru
Guru


Joined: 16 Apr 2002
Posts: 480
Location: Cambridge, UK

PostPosted: Mon Feb 16, 2004 9:06 pm    Post subject: Reply with quote

I've modified the script so that it now accepts targets, so
pye world
pye system
pye gnome etc.

should work. If no target is given, the script takes 'world' as default. Uploaded to this page.
Back to top
View user's profile Send private message
neenee
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1786

PostPosted: Mon Feb 16, 2004 10:15 pm    Post subject: Reply with quote

wow. i love this to bits. thanks dr_strange!
_________________
proud to be a scout and a chronic penguin hugger
Legion of Lore - site
Back to top
View user's profile Send private message
singular
n00b
n00b


Joined: 07 Jun 2003
Posts: 54

PostPosted: Tue Feb 17, 2004 4:20 am    Post subject: Reply with quote

Getting better and better dr_strange. :)

One thing though, at least on my computer, I get an error if no arguments are given using the latest code at this line :
Code:
arg = sys.argv[1]

This is because when you do not supply any additional arguments, there isn't any argv[1]. Only argv[0] which is the name of the program.

The program should test is if argv[1] exists before assigning it to a variable. You can do this one of two ways.
Like this:
Code:
if len(sys.argv) > 1 :
    argv = sys.argv[1]
    if arg in ["--help", "-"]:
        usage()
else:
    arg = "world"

or:
Code:
try:
    arg sys.argv[1]
except IndexError:
    arg = "world"
if arg in ["--help", "-h"]:
    usage()


Also, here's another feature I thought of. I modified the code to allow both comma-seperated numbers and a range of numbers (i.e. 6-10).
Where you check the list of numbers with this code:
Code:
for num in packnumlist:
    packlist.append(pkgdict[eval(num)])
packstring = " ".join(packlist)

I replaced it with this:
Code:
for num in packnumlist:
    if "-" in num :
        start, stop = num.split("-")
        for n in range(int(start), int(stop)+1):
            packlist.append(pkgdict[n])
    else:
        packlist.append(pkgdict[eval(num)])
packstring = " ".join(packlist)


The message in the raw_input statement above it should probably be changed as well. Maybe something like this?
Code:
print blue("Enter the number of the packages you want to emerge, comma-seperated")
print blue("(a range can be specified i.e. 6-10), or q to quit:")
emergethis = raw_input(blue(">>>"))
Back to top
View user's profile Send private message
dr_strange
Guru
Guru


Joined: 16 Apr 2002
Posts: 480
Location: Cambridge, UK

PostPosted: Tue Feb 17, 2004 8:30 am    Post subject: Reply with quote

Hehh... you will not believe me, but after facing a 40-item list after a pye gnome yesterday, I went to bed with the thought "I will write in a range-functionality tomorrow". But you do my work for me, thanks:-)

Anyway you are right about the sys.argv raising a KeyError if no argument is given. Thanks, I'll modify the script accordingly. And also incorporate the range-thing, of course.
_________________
shine on,

dr_strange

Set the Controls for the Heart of Gentoo
http://magenta.linuxforum.hu
Back to top
View user's profile Send private message
mudrii
l33t
l33t


Joined: 26 Jun 2003
Posts: 789
Location: Singapore

PostPosted: Tue Feb 17, 2004 8:51 am    Post subject: Reply with quote

cool script THX a lot it is very useful
_________________
www.gentoo.ro
Back to top
View user's profile Send private message
wrc1944
Advocate
Advocate


Joined: 15 Aug 2002
Posts: 2776
Location: Gainesville, Florida

PostPosted: Tue Feb 17, 2004 1:25 pm    Post subject: Reply with quote

Sorry to be so dense, but could you please clarify where you put pye (like in /usr/bin/, or somewhere else??), and what commands one uses to run it, and what permissions it needs? I can't seem to get this to run.

Thanks,
wrc1944
_________________
Main box- Gigabyte GIGABYTE GA-990FXA-UD3 AM3+ rev.-4.0
Amd FX 8320, 3.5 GHz, 16GB GSkill DDR3 1866mhz
Samsung SATA 1000GB, Radeon HD 6570 2GB DDR3
Gentoo ~x86, ~amd64, glibc-2.19-r1, gcc-4.9.1 kernel 3.17.1-gentoo-r1 (USE=experimental "native")
Back to top
View user's profile Send private message
neenee
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1786

PostPosted: Tue Feb 17, 2004 1:50 pm    Post subject: Reply with quote

save the script as 'pye', then chmod +x pye,
then login as root and copy it to /sbin/

now you can type 'pye' as root to run it.
_________________
proud to be a scout and a chronic penguin hugger
Legion of Lore - site
Back to top
View user's profile Send private message
dr_strange
Guru
Guru


Joined: 16 Apr 2002
Posts: 480
Location: Cambridge, UK

PostPosted: Tue Feb 17, 2004 6:12 pm    Post subject: Reply with quote

Updated script uploaded to http://dev.gentoo.org/~strangedr

Thanks to everybody for comments and suggestions.
_________________
shine on,

dr_strange

Set the Controls for the Heart of Gentoo
http://magenta.linuxforum.hu
Back to top
View user's profile Send private message
wrc1944
Advocate
Advocate


Joined: 15 Aug 2002
Posts: 2776
Location: Gainesville, Florida

PostPosted: Tue Feb 17, 2004 6:21 pm    Post subject: Reply with quote

dr_strange,
Thanks for the new version! What's changed in this update?

neenee,
Thanks for cluing me in on how to use it!

BTW, my younger sister's nickname has been" neenee" for over 50 years. My Grandchildren still call her that, as well as all her nieces and nephews.

wrc1944
_________________
Main box- Gigabyte GIGABYTE GA-990FXA-UD3 AM3+ rev.-4.0
Amd FX 8320, 3.5 GHz, 16GB GSkill DDR3 1866mhz
Samsung SATA 1000GB, Radeon HD 6570 2GB DDR3
Gentoo ~x86, ~amd64, glibc-2.19-r1, gcc-4.9.1 kernel 3.17.1-gentoo-r1 (USE=experimental "native")
Back to top
View user's profile Send private message
dr_strange
Guru
Guru


Joined: 16 Apr 2002
Posts: 480
Location: Cambridge, UK

PostPosted: Tue Feb 17, 2004 6:26 pm    Post subject: Reply with quote

Quote:
dr_strange,
Thanks for the new version! What's changed in this update?


I have incorporated the suggestions made by singular above: namely, you can now specify ranges of numers, e.g. 2,5-11,24
The script now also correctly handles when it is called without arguments.
_________________
shine on,

dr_strange

Set the Controls for the Heart of Gentoo
http://magenta.linuxforum.hu
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Goto page 1, 2, 3, 4, 5, 6  Next
Page 1 of 6

 
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