# Portage utility: bumper

## Pythonhead

I wrote a utility for portage named "bumper".

You notice that version 2.0 is out for your favorite software, but portage only has 1.0  (foobar-1.0.ebuild) and you want it now.

bumper will copy the 1.0 ebuild to your portage overlay directory, creating the necessary directories, and name it foobar-2.0.ebuild. It will then create a digest, which will also download the new package. It also copies any non-digest files in ${FILESDIR}.

Its a Python script you can get here:

http://dev.gentoo.org/~pythonhead/bumper/bumper-0.0.10

Usage:

```
bumper app-games/pacman-1.0 2.0
```

Its also useful for simply copying an ebuild from your PORTDIR to your overlay (no version bump) for editing. Just use the same version number:

```
bumper apps-foo/boo-1.0 1.0
```

Last edited by Pythonhead on Sun Mar 06, 2005 5:10 am; edited 12 times in total

----------

## pjp

Moved from Portage & Programming.

----------

## TheCoop

wouldnt it be better as a bash script?

ie:

```
<get PORTAGE_OVERLAY from make.conf using some obsfusticated sed command>

cp $1 overlay/$2 etc /w name changes

ebuild <new ebuild> digest

emerge <ebuild>
```

why python?

----------

## AgenT

Neat! I think this calls for a request!

----------

## Pythonhead

 *TheCoop wrote:*   

> wouldnt it be better as a bash script?
> 
> 

 

What difference does the language matter as long as it works?

 *Quote:*   

> 
> 
> ie:
> 
> ```
> ...

 

Well, thats nice pseudo-code, but my Python psudeo-code looked about the same before I actually wrote the finished code. Look at all the error checking in my code. 

Why Python? It sounds better than "bash".

Write in in bash if it'll make you feel better.Last edited by Pythonhead on Sun Aug 03, 2003 4:59 pm; edited 1 time in total

----------

## floam

It kinda pukes with something like:

```
bumper app-misc/blah-1.0.1-r1 blah-2.0
```

It trys to look in app-misc/blah-1.0.1/

----------

## Pythonhead

 *floam wrote:*   

> It kinda pukes with something like:
> 
> ```
> bumper app-misc/blah-1.0.1-r1 blah-2.0
> ```
> ...

 

Thanks Floam!

EDIT: Fixed in version 0.0.2, same link in first post.

----------

## floam

Also gets messed up if people have multiple PORTDIR_OVERLAY's. In recent versions of portage it is legal to do a

PORTDIR_OVERLAY="/usr/local/portage /usr/local/portage2" or similar, which I happen to use. Could the script only use the first directory? Right now it dies with a Couldn't copy file error.

----------

## Pythonhead

 *floam wrote:*   

> Also gets messed up if people have multiple PORTDIR_OVERLAY's. In recent versions of portage it is legal to do a
> 
> PORTDIR_OVERLAY="/usr/local/portage /usr/local/portage2" or similar, which I happen to use. Could the script only use the first directory? Right now it dies with a Couldn't copy file error.

 

Ok, thanks for the heads up. I didn't know you could use more than one PORTDIR_OVERLAY. It would be easy enough to fix it to check the first one, but let me read up on it and see why people would use two. Was this announced somewhere? I'd like to be a little more informed before I change it.

How does portage use it? Does the first one take precedence over the second?

----------

## floam

PythonHead: You see a few mentions of it in the portage changelog. The first takes precidence. I use it because I have a script that does some weird stuff there to specific ebuilds and I don't want it affecting my real overlay. People could also use it to sync up with like the breakmygentoo.net development gnome stuff and able to keep it seperate, and stuff like that. It's a very little used feature.

----------

## Pythonhead

 *floam wrote:*   

> PythonHead: You see a few mentions of it in the portage changelog. The first takes precidence. I use it because I have a script that does some weird stuff there to specific ebuilds and I don't want it affecting my real overlay. People could also use it to sync up with like the breakmygentoo.net development gnome stuff and able to keep it seperate, and stuff like that. It's a very little used feature.

 

Ok, good enough. I'll go update it to use the first one in the list.

----------

## wizy

This is great.  I do this by hand a lot of the time, thank you.

----------

## Pythonhead

 *wizy wrote:*   

> This is great.  I do this by hand a lot of the time, thank you.

 

Thank you.

Version 0.3 is ready and fixes the multiple overlay directory bug, thanks Floam.

http://abeni.sourceforge.net/ebuilds/bumper-0.3

----------

## floam

Thanks! Works almost great now  :Smile:  One more suggestion, since many ebuilds have patches and stuff they need in the /files/ dir, maybe you should copy that over to overlay as well?

----------

## Pythonhead

 *floam wrote:*   

> Thanks! Works almost great now :) One more suggestion, since many ebuilds have patches and stuff they need in the /files/ dir, maybe you should copy that over to overlay as well?

 

Ok, I'll test that out. I'm not sure how well that will work since the names of patches are tied to the version number. It'd be some trick to guess the patch names, since there isn't a standard. If it doesn't work out, I'll have a message showing the files that were copied that aren't digests.

Thanks for the suggestion.

----------

## floam

Yeah, you can't really be sure itll always work, but just moving /files/ over and then basically s/oldversion/newversion/'ing all the filenames seems like it would work a good percent of the time.

----------

## Pythonhead

Bumper 0.4 is ready for testing:

From the ChangeLog:

- Changed delimiter for PORTDIR_OVERLAY from space to colon.

https://bugs.gentoo.org/show_bug.cgi?id=10803

https://bugs.gentoo.org/show_bug.cgi?id=26773

- Copy non-digest files from ${FILESDIR}

- More error checking for env vars, warn and exit if no PORTDIR_OVERLAY

- Exits if user isn't root

----------

## asph

pythonhead rules!

thanks, nice app  :Very Happy:  (also for learning python)

----------

## floam

```
( floam  ~ ) bumper enchant-1.0.0 enchant-1.1.1

Traceback (most recent call last):

  File "/usr/bin/bumper", line 99, in ?

    cat, p = ebuild_from.split("/")

ValueError: unpack list of wrong size
```

----------

## Pythonhead

 *floam wrote:*   

> 
> 
> ```
> ( floam  ~ ) bumper enchant-1.0.0 enchant-1.1.1
> 
> ...

 

You should be using this instead:

```
bumper app-text/enchant-1.0.0 enchant-1.1.1
```

I'll fix it so it shows the usage message though, thanks.

----------

## Pythonhead

Version 0.5 is out and works with newer versions of portage. The code is cleaned up a bit thanks to the use of gentoolkit.py now.

EDIT

0.6 is ready for testing due to major problem in 0.5:

http://dev.gentoo.org/~pythonhead/bumper-0.6

----------

## floam

I think "0.0.4 - Changed delimiter for PORTDIR_OVERLAY from space to colon." was incorrect. While the portage documentation says a colon should be used, looking in the source shows that it actually uses a space to seperate multiple overlays. Trying to use colons will cause in an error:

```
( floam@Aluminium ~ ) emerge -puD world

!!! Invalid PORTDIR_OVERLAY (not a dir): /usr/local/overlays/personal/:/usr/local/overlays/public
```

----------

## JasonRogers

2 problems actually.

First, I had to change line#53

```

+++ l = os.listdir(package_path)

--- l = os.listdir(pacakge_path)

```

Second, I get this error trying to bump resin-2.1.9 which is located in net-www/resin

```

# bumper net-www/resin-2.1.9 3.0.8

!!! aux_get(): ebuild for 'net-www/resin-resin-3.0.8' does not exist at:

!!!            /usr/portage/net-www/resin-resin/resin-resin-3.0.8.ebuild

Error - Can't find ebuild for net-www/resin-2.1.9

Give the category and ebuild name in this format:

bumper games-arcade/pacman-0.1 0.2

```

So I thought that perhaps I need to just use 'resin' instead of 'resin-2.1.9', but then I get this error.

```

eanus resin # bumper net-www/resin 3.0.8

!!! aux_get(): ebuild for 'net-www/resin-resin-3.0.8' does not exist at:

!!!            /usr/portage/net-www/resin-resin/resin-resin-3.0.8.ebuild

Error - Can't find ebuild for net-www/resin

Give the category and ebuild name in this format:

bumper games-arcade/pacman-0.1 0.2

```

What's with the '/usr/portage/net-www/resin-resin/resin-resin-3.0.8.ebuild'?  Shouldn't it be  '/usr/portage/net-www/resin/resin-3.0.8.ebuild'?

----------

## Pythonhead

 *floam wrote:*   

> I think "0.0.4 - Changed delimiter for PORTDIR_OVERLAY from space to colon." was incorrect. While the portage documentation says a colon should be used, looking in the source shows that it actually uses a space to seperate multiple overlays. Trying to use colons will cause in an error:
> 
> ```
> ( floam@Aluminium ~ ) emerge -puD world
> 
> ...

 

Thanks, changed to space.

----------

## Pythonhead

JasonRogers, sorry, guess I should watch my own threads. I fixed the typo in the latest version:

http://dev.gentoo.org/~pythonhead/bumper/bumper-0.0.8

As for the second problem, I'm not sure what happened, but you may have been caught when they were changing categories? I see resin is in www-servers now, not net-www.

----------

## JasonRogers

Thanks, that did it.

----------

## Pythonhead

bumper-0.0.10 is out

It will ask you if you want to edit the ebuild if the digest failed due to not guessing SRC_URI correctly or ask if you want to emerge the package if it downloaded and created digest.

http://dev.gentoo.org/~pythonhead/bumper/bumper-0.0.10

----------

## jamapii

To fix the KEYWORDS, if you don't want to run the file through a python loop, I suggest calling sed with something like:

```
sed -i -r -e '/^KEYWORDS=/s/([-_a-z0-9]+)/~\1/g' $new_ebuild_file

sed -i -r -e '/^KEYWORDS=/s/~~/~/g' $new_ebuild_file
```

----------

## ecatmur

 *Pythonhead wrote:*   

>  *floam wrote:*   I think "0.0.4 - Changed delimiter for PORTDIR_OVERLAY from space to colon." was incorrect. While the portage documentation says a colon should be used, looking in the source shows that it actually uses a space to seperate multiple overlays. Trying to use colons will cause in an error:
> 
> ```
> ( floam@Aluminium ~ ) emerge -puD world
> 
> ...

 

Actually, any whitespace will do; also, it is the last overlay which takes precedence, not the first. So it should be:

```

    PORTDIR_OVERLAY = env['PORTDIR_OVERLAY'].split()[-1]

```

Other than that, great!

----------

## ecatmur

Some more thoughts: first, there's no particularly good reason why the category or old version should be required: the category can be got from a query, as can the version (it should be the highest installed version). Also, it should be OK to omit the new version; in that case the script should assume it to be the same as the old version.

Here's my changes, which seem to work:

```

--- bumper-0.0.10       2005-03-07 05:17:53.000000000 +0000

+++ bumper      2005-08-13 20:09:23.000000000 +0100

@@ -82,7 +82,7 @@ if os.getuid() != 0:

     print red("You must be root to run bumper.")

     sys.exit(1)

-if len(sys.argv) < 3:

+if len(sys.argv) < 2:

     print red("\nI need a category/package to bump up and a destination version.\n")

     print green("Example:")

     print "bumper games-arcade/pacman-1.0 2.0\n"

@@ -97,7 +97,7 @@ except:

 try:

     #In case people have multiple PORTDIR_OVERLAY directories, use first one.

     # See http://bugs.gentoo.org/show_bug.cgi?id=10803

-    PORTDIR_OVERLAY = env['PORTDIR_OVERLAY'].split(" ")[0]

+    PORTDIR_OVERLAY = env['PORTDIR_OVERLAY'].split()[-1]

 except:

     print red("ERROR: You must define PORTDIR_OVERLAY in your /etc/make.conf")

     print green("You can simply uncomment this line:")

@@ -106,9 +106,8 @@ except:

     sys.exit(1)

 def get_versions(query, new_version):

-    cat, pn, version, rev = gentoolkit.split_package_name(query)

     try:

-        pkg = gentoolkit.find_packages("=%s" % query)[0]

+        pkg = gentoolkit.find_packages("=%s" % query)[-1]

     except:

         print red("Error - Can't find ebuild for %s" % query)

         print green("\nGive the category and ebuild name in this format:")

@@ -121,12 +120,15 @@ def get_versions(query, new_version):

         print "bumper games-arcade/pacman-0.1 0.2"

         sys.exit(1)

+    cat, pn, version, rev = pkg._scpv

     ebuild_path = pkg.get_ebuild_path()

     filesdir = "%s/files" % pkg.get_package_path()

     # Is it an overlay version?

     overlay = pkg.is_overlay()

     if rev != "r0":

         version += "-" + rev

+    if not new_version:

+       new_version = version

     dest = ("%s/%s/%s/%s-%s.ebuild" % \

            (PORTDIR_OVERLAY, cat, pn, pn, new_version))

     if os.path.exists(dest):

@@ -182,7 +184,11 @@ def check_digest(dest, pn, new_version):

         return -1

 query = sys.argv[1]

-new_version = sys.argv[2]

+if len(sys.argv) > 2:

+    new_version = sys.argv[2]

+else:

+    new_version = None

+

 ebuild_path, dest, cat, pn, filesdir, overlay = get_versions(query, new_version)

 bump(ebuild_path, dest, filesdir, overlay)

```

----------

## rhill

 *ecatmur wrote:*   

> Here's my changes, which seem to work:

 

works for me too - nice improvement   :Very Happy: 

----------

## al3x_

For some reason bumper stopped working for me at some point.

It couldn't find PORTAGE_OVERLAY.

```

ERROR: You must define PORTDIR_OVERLAY in your /etc/make.conf

You can simply uncomment this line:

#PORTDIR_OVERLAY='/usr/local/portage'

Then: mkdir -p /usr/local/portage

```

Exception said "green takes 1 argument (2 supplied), so I have to modify it a bit.

```

--- bumper.old  2006-06-09 15:07:15.245812840 -0700

+++ bumper      2006-06-09 13:26:08.870645416 -0700

@@ -99,7 +99,7 @@

     #In case people have multiple PORTDIR_OVERLAY directories, use first one.

     # See http://bugs.gentoo.org/show_bug.cgi?id=10803

     PORTDIR_OVERLAY = env['PORTDIR_OVERLAY'].split()[-1]

-    print green("Your OVERLAY is: %s", PORTDIR_OVERLAY)

+    print green("Your OVERLAY is:" + PORTDIR_OVERLAY)

 except:

     print red("ERROR: You must define PORTDIR_OVERLAY in your /etc/make.conf")

     print green("You can simply uncomment this line:")

```

indents are important.

----------

