View previous topic :: View next topic |
Author |
Message |
dr_strange Guru
Joined: 16 Apr 2002 Posts: 480 Location: Cambridge, UK
|
Posted: Thu Feb 12, 2004 11:19 pm Post subject: pye - "pick your emerge" script |
|
|
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 |
|
|
skimitar n00b
Joined: 30 Dec 2003 Posts: 20
|
Posted: Fri Feb 13, 2004 10:05 am Post subject: |
|
|
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 |
|
|
reyneke Guru
Joined: 09 Jan 2004 Posts: 542 Location: Augsburg / Germany
|
Posted: Fri Feb 13, 2004 11:02 am Post subject: |
|
|
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 |
|
|
dr_strange Guru
Joined: 16 Apr 2002 Posts: 480 Location: Cambridge, UK
|
Posted: Fri Feb 13, 2004 8:48 pm Post subject: |
|
|
Okay, I wrote a "quit" option in. You can download the revised version from here:
dev.gentoo.org/~strangedr |
|
Back to top |
|
|
singular n00b
Joined: 07 Jun 2003 Posts: 54
|
Posted: Sun Feb 15, 2004 12:01 am Post subject: |
|
|
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 |
|
|
revertex l33t
Joined: 23 Apr 2003 Posts: 806
|
Posted: Sun Feb 15, 2004 5:31 am Post subject: |
|
|
Nice one, work's fine for me.
Just one question, this script call "emerge --update package" or just "emerge package"?
|
|
Back to top |
|
|
dr_strange Guru
Joined: 16 Apr 2002 Posts: 480 Location: Cambridge, UK
|
Posted: Sun Feb 15, 2004 10:31 am Post subject: |
|
|
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 |
|
|
revertex l33t
Joined: 23 Apr 2003 Posts: 806
|
Posted: Sun Feb 15, 2004 10:57 pm Post subject: |
|
|
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! |
|
Back to top |
|
|
dr_strange Guru
Joined: 16 Apr 2002 Posts: 480 Location: Cambridge, UK
|
Posted: Mon Feb 16, 2004 8:02 am Post subject: |
|
|
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! |
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 |
|
|
Bastux Guru
Joined: 15 Dec 2002 Posts: 369 Location: France - Paris
|
Posted: Mon Feb 16, 2004 9:00 am Post subject: |
|
|
Very usefull
Thank you!! |
|
Back to top |
|
|
revertex l33t
Joined: 23 Apr 2003 Posts: 806
|
Posted: Mon Feb 16, 2004 9:02 am Post subject: |
|
|
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 |
|
|
dr_strange Guru
Joined: 16 Apr 2002 Posts: 480 Location: Cambridge, UK
|
Posted: Mon Feb 16, 2004 10:41 am Post subject: |
|
|
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 |
|
|
revertex l33t
Joined: 23 Apr 2003 Posts: 806
|
Posted: Mon Feb 16, 2004 6:19 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
dr_strange Guru
Joined: 16 Apr 2002 Posts: 480 Location: Cambridge, UK
|
Posted: Mon Feb 16, 2004 7:29 pm Post subject: |
|
|
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 |
|
|
revertex l33t
Joined: 23 Apr 2003 Posts: 806
|
Posted: Mon Feb 16, 2004 9:06 pm Post subject: |
|
|
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!
Stay so long in front my computer maybe has damage my brain, if i've got one
Thanks. |
|
Back to top |
|
|
dr_strange Guru
Joined: 16 Apr 2002 Posts: 480 Location: Cambridge, UK
|
Posted: Mon Feb 16, 2004 9:06 pm Post subject: |
|
|
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 |
|
|
neenee Veteran
Joined: 20 Jul 2003 Posts: 1786
|
Posted: Mon Feb 16, 2004 10:15 pm Post subject: |
|
|
wow. i love this to bits. thanks dr_strange! |
|
Back to top |
|
|
singular n00b
Joined: 07 Jun 2003 Posts: 54
|
Posted: Tue Feb 17, 2004 4:20 am Post subject: |
|
|
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 :
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 |
|
|
dr_strange Guru
Joined: 16 Apr 2002 Posts: 480 Location: Cambridge, UK
|
Posted: Tue Feb 17, 2004 8:30 am Post subject: |
|
|
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 |
|
|
mudrii l33t
Joined: 26 Jun 2003 Posts: 789 Location: Singapore
|
Posted: Tue Feb 17, 2004 8:51 am Post subject: |
|
|
cool script THX a lot it is very useful _________________ www.gentoo.ro |
|
Back to top |
|
|
wrc1944 Advocate
Joined: 15 Aug 2002 Posts: 3456 Location: Gainesville, Florida
|
Posted: Tue Feb 17, 2004 1:25 pm Post subject: |
|
|
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- AsRock x370 Gaming K4
Ryzen 7 3700x, 3.6GHz, 16GB GSkill Flare DDR4 3200mhz
Samsung SATA 1000GB, Radeon HD R7 350 2GB DDR5
OpenRC Gentoo ~amd64 plasma, glibc-2.40-r5, gcc-14
kernel-6.11.3 USE=experimental python3_12.7-final-0 |
|
Back to top |
|
|
neenee Veteran
Joined: 20 Jul 2003 Posts: 1786
|
Posted: Tue Feb 17, 2004 1:50 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
dr_strange Guru
Joined: 16 Apr 2002 Posts: 480 Location: Cambridge, UK
|
|
Back to top |
|
|
wrc1944 Advocate
Joined: 15 Aug 2002 Posts: 3456 Location: Gainesville, Florida
|
Posted: Tue Feb 17, 2004 6:21 pm Post subject: |
|
|
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- AsRock x370 Gaming K4
Ryzen 7 3700x, 3.6GHz, 16GB GSkill Flare DDR4 3200mhz
Samsung SATA 1000GB, Radeon HD R7 350 2GB DDR5
OpenRC Gentoo ~amd64 plasma, glibc-2.40-r5, gcc-14
kernel-6.11.3 USE=experimental python3_12.7-final-0 |
|
Back to top |
|
|
dr_strange Guru
Joined: 16 Apr 2002 Posts: 480 Location: Cambridge, UK
|
Posted: Tue Feb 17, 2004 6:26 pm Post subject: |
|
|
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 |
|
|
|
|
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
|
|