public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Lars Weiler <pylon@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Subject: [gentoo-dev] Script for easier stabilising of ebuilds
Date: Sun, 8 Jul 2007 06:23:32 +0200	[thread overview]
Message-ID: <20070708042331.GX8720@elladan.wh-og.hs-niederrhein.de> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1098 bytes --]

Hi devs,

my fingers were tired of typing the same things over and
over again when I stabilised an ebuild.  So I wrote the
attached script which should take away the work.

Now I only have to attach the bug-number and optionally an
ebuild with atom version.  If there is no second argument,
the script tries to resolve the wanted ebuild from the bugs'
summary (like app-portage/gatt-svn does).  The script also
makes use of www-client/pybugz for an appropriate
bug-comment and removing the given arch from the bug.  It
can also close the bug, if you see that no other arch is
listed as Assignee or on CC.

It might also be possible that you can use the script for
mass-stabilisation in a for-loop, but I did not test that
case yet.  Probably that's a nice extension for a future
version, where you can attach a list of ebuilds, which
should be stabilised.

Comments are welcome!

Regards, Lars

-- 
Lars Weiler  <pylon@gentoo.org>  +49-171-1963258
Instant Messaging     : pylon@jabber.ccc.de
Gentoo Linux PowerPC  : Developer
Gentoo Infrastructure : CVS Administrator

[-- Attachment #1.2: estable --]
[-- Type: text/plain, Size: 6940 bytes --]

#!/bin/bash
#
# Stabilise an ebuild in cvs with a bug-number and ebuild-atom given
# Version: 1.0
#
#    Copyright (C) 2007  Lars Weiler <pylon@gentoo.org>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; version 2 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# Thanks to 
#   Aron Griffis for his rc()-function 
#   Robin H. Johnson for his earch-script
#   kojiro on IRC for the ebuild with Atom Version regexp


# Options can alse be hardcoded in this script
CVSDIR=""
ARCH=""
BUGZ_USER=""
BUGZ_PASSWORD=""

PATH=/usr/local/bin:/usr/bin:/bin

die() {
	echo $1 > /dev/stderr
	exit -1
}

print_usage() {
	echo "Usage: $(basename ${0}) [-a arch] [-c cvs-dir] [-u username]"
	echo "   [-p password] [-y] bug-number [ebuild with Atom Version]"
	echo
	echo "Make an ebuild stable for a given arch and change the related bug."
	echo
	echo "Options:"
	echo "  -a <arch>       Set the architecture"
	echo "  -c <cvs-dir>    Path to the gentoo-x86 repository"
	echo "  -u <username>   User name for Bugzilla"
	echo "  -p <password>   Password for Bugzilla"
	echo "  -q              Quickrun: always choose the default answer on"
	echo "                  questions.  Useful for scripting."
}

splitpackage() {
	case $1 in
		section)
			echo ${2%/*} ;;
		name)
			tmp=${2#*/}
			echo ${tmp%-[0-9]*}
			;;
		ebuild)
			echo ${2#*/} ;;
	esac
}

# rc-function stolen from Aron Griffis in http://archives.gentoo.org/gentoo-dev/msg_122004.xml
rc() {
  declare msg

  if [[ -n $* ]]; then
    msg="$*"
    echo "* Using msg from command-line" >&2
  else
    msg=$(perl <ChangeLog -0777 -pe \
      's/^.*?\n  \d{2} \w{3} \d{4};.*?:\n//s || exit 1; # trim top
       s/\n(?:\*|  \d{2} \w{3} \d{4};).*//s;            # trim bottom
       s/^\s*//; s/\s*$//; s/^(?:  |\t)//gm;            # fix spacing
       #/^ /m || s/\s+/ /g;  # normalize spacing unless formatted
      ')
    if [[ $? != 0 || -z $msg ]]; then
      echo "* could not parse message from ChangeLog" >&2
      return 1
    fi
    echo "* Parsed msg from ChangeLog" >&2
  fi

  echo "----------" >&2
  echo "$msg" >&2
  echo "----------" >&2

  repoman commit -m "$msg" || return 1

  if [[ -x /usr/bin/eviewcvs ]]; then
    local f entry=$(perl -00ne '/^  \d/ and print, last' ChangeLog)
    entry=${entry%%:*}
    entry=${entry##*>}
    entry=${entry//,/ }
    for f in $entry; do
      [[ $f == -* ]] && continue
      f=${f#+}
      echo "$f"
    done | xargs -n1 eviewcvs
  fi
} 


### main routine ###

# get the arguments
while getopts "a:c:u:p:yh" OPTION
do
	case "${OPTION}" in
		a) ARCH="$OPTARG" ;;
		c) CVSDIR="$OPTARG" ;;
		u) BUGZ_USERNAME="$OPTARG" ;;
		p) BUGZ_PASSWORD="$OPTARG" ;;
		q) quickrun="y" ;;
		h) print_usage; exit 0 ;;
	esac
done
shift $((OPTIND -1))

if [[ $# -lt 1 ]]; then
	print_usage
	die
fi

# check if we have an arch given
if [[ -z "$ARCH" ]]; then
	print_usage
	die "Please set your arch."
fi

# check for the CVSDIR
if [[ -z "$CVSDIR" ]]; then
	print_usage
	die "Please set the path to your gentoo-x86 repository."
fi

# check the bug-number
case ${1} in
	*[!0-9]*|"") 
		print_usage
		die "Argument 1 must be a bug-number."
		;;
esac

bugz_number=${1}

# without pybugz, a second argument is mandatory
if [[ -x /usr/bin/bugz ]]; then
	bugz=y
	bugz_info=$(bugz get ${bugz_number} -n)
	echo "${bugz_info}" 
	if [[ $quickrun != "y" ]]; then
		read -p "Do you want to work on this bug? [Y/n]" BUGOK
		case ${BUGOK} in
			q|n|N)
				die "Quitting" ;;
		esac
	fi
fi

# check if a package is given with a second argument
# or strip it from the bug's summary
# clean out some unneeded and common extensions to the package-name
if [[ $# -gt 1 ]]; then
	package=${2}
	package=${package##*[>|=|<|~]}
	package=${package%.ebuild}
elif [[ "${bugz}" == "y" ]]; then
	summary=$(echo "${bugz_info}" | egrep "^Title" | cut -d: -f2)
	# a great regexp to match an ebuild with Atom Version
	package=$(egrep -o '(>=|>|=|<=|<|~)?[[:alnum:]]+-[[:alnum:]]+/[-.[:alnum:]]+' <<< ${summary})
	package=${package##*[>|=|<|~]}
	package=${package%.ebuild}
else
	die "No package was given or www-client/pybugz is not installed."
fi

# check if package exists

package_section="$(splitpackage section ${package})"
package_name="$(splitpackage name ${package})"
ebuild="$(splitpackage ebuild ${package}).ebuild"
cd "${CVSDIR}/${package_section}/${package_name}" || die "Path to ebuild does not exist."

if [[ ! -e ${ebuild} ]]; then
	die "${ebuild} does not exist!"
fi

# update via cvs and remove conflicting files
cvs up -CdP
rm -f .\#*

# show current status of all ebuilds
if [[ -x /usr/bin/earch || -x /usr/local/bin/earch ]]; then
	PORTDIR="${CVSDIR}" earch
fi

# now, the workhorse, which makes my fingers happy
if [[ ${quickrun} != "y" ]]; then
	read -p "Stabilise $(basename ${package}) for ${ARCH}? [Y/n]" STABILISE
	case ${STABILISE} in
		q|n|N)
			die "Quitting" ;;
	esac
fi
ekeyword ${ARCH} $(basename ${ebuild})
echangelog "Stable on ${ARCH}; bug #${bugz_number}."
rc # function from above
if [[ "${bugz}" == "y" ]]; then
	# add a comment to the bug and remove the arch
	if [[ -n "${BUGZ_USER}" && -n "${BUGZ_PASSWORD}" ]]; then
		bugz -u ${BUGZ_USER} -p ${BUGZ_PASSWORD} modify ${bugz_number} --comment="${ARCH} stable." --remove-cc=${ARCH}@gentoo.org
	else
		bugz modify ${bugz_number} --comment="${ARCH} stable." --remove-cc=${ARCH}@gentoo.org
	fi
	# show the Assignee and CCs to choose if the bug can be closed
	echo "* Checking bugs' Assignee and CCs"
	echo "${bugz_info}" | egrep "^Assignee"
	echo "${bugz_info}" | egrep "^CC" | grep -v "${ARCH}@gentoo.org"  # strip the arch, as we don't refetch the bugs' information
	if [[ ${quickrun} != "y" ]]; then
		read -p "* Do you want to close the bug? [y/N]" BUGZCLOSE
		case ${BUGZCLOSE} in
			y|Y)
				if [[ -n "${BUGZ_USER}" && -n "${BUGZ_PASSWORD}" ]]; then
					bugz -u ${BUGZ_USER} -p ${BUGZ_PASSWORD} modify ${bugz_number} --comment="Closing, since all arches are done." --fixed
				else
					bugz modify ${bugz_number} --comment="Closing, since all arches are done." --fixed
				fi
				;;
		esac
	fi
fi

# return to the path from where the script was called
cd "$OLDPWD"
echo "All done."

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

             reply	other threads:[~2007-07-08  4:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-08  4:23 Lars Weiler [this message]
2007-07-08 10:31 ` [gentoo-dev] Re: Script for easier stabilising of ebuilds Christian Faulhammer
2007-07-08 12:45   ` Lars Weiler
2007-07-08 15:25     ` Christian Faulhammer
2007-07-08 16:07       ` Lars Weiler
2007-07-08 15:44     ` Matthias Langer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070708042331.GX8720@elladan.wh-og.hs-niederrhein.de \
    --to=pylon@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox