r11957 - /scripts/qa/packagecheck

gregoa-guest at users.alioth.debian.org gregoa-guest at users.alioth.debian.org
Thu Jan 3 22:26:45 UTC 2008


Author: gregoa-guest
Date: Thu Jan  3 22:26:45 2008
New Revision: 11957

URL: http://svn.debian.org/wsvn/?sc=1&rev=11957
Log:
packagecheck: split out individual tests in functions that are called by separate command line options

Modified:
    scripts/qa/packagecheck

Modified: scripts/qa/packagecheck
URL: http://svn.debian.org/wsvn/scripts/qa/packagecheck?rev=11957&op=diff
==============================================================================
--- scripts/qa/packagecheck (original)
+++ scripts/qa/packagecheck Thu Jan  3 22:26:45 2008
@@ -1,100 +1,88 @@
 #!/bin/sh
 
-# Copyright 2007 gregor herrmann <gregor+debian at comodo.priv.at>
+# Copyright 2007, 2008 gregor herrmann <gregor+debian at comodo.priv.at>
 # Copyright 2007 Damyan Ivanov <dmn at debian.org>
 # Copyright 2007 David Paleino <d.paleino at gmail.com>
 # Released under the terms of the GNU GPL version 2
 #
-# 1) Checks for and adds missing Vcs-(Svn|Browser) fields 
-# 2) Checks for Homepage: field
-# 3) Removes pseudo-field Homepage (description)
-# 4) Removes XS-Vcs-(Svn|Browser) fields
-#    in all debian/control files in trunk/
-# 5) Change URLs to http://search.cpan.org/dist/Mod-Ule/
-#    in all debian/watch files in trunk/
-# 6) rmdir /usr/{lib,share}/perl5 only if they exist
-#    in debian/rules
-#
 # To be run a directory above trunk/
 # (which name can be specified as the first argument)
 
-CHANGED=0
-TRUNK=${1:-trunk}
-
-echo "Running svn up $TRUNK ..."
-svn up $TRUNK
-
-echo "Checking if $TRUNK is clean ..."
-UNCLEAN=$(svn st $TRUNK |egrep -v '^\?')
-if [ -n "$UNCLEAN" ]; then
-    echo "$UNCLEAN"
-    echo WARNING: $TRUNK is not clean
-fi
-
-echo "Grepping through packages ..."
-for p in $(svn ls $TRUNK); do 
-  
-  # 0) reset variables
-  p=${p%/}
-  OLDHP=
-  PERLNAME=
-  NEWHP=
-  MSG_CONTROL=
-  MSG_CONTROL_ADD=
-  MSG_CONTROL_RM=
-  MSG_WATCH=
-  MSG_RULES=
-  
-  # 1) check for and add missing Vcs-Svn field
-	if ! grep ^Vcs-Svn $TRUNK/$p/debian/control > /dev/null; then
-		echo "$p: adding missing Vcs-Svn field"
-		perl -pi -e "s;(Standards-Version:.+);\$1\nVcs-Svn: svn://svn.debian.org/pkg-perl/trunk/$p/;" $TRUNK/$p/debian/control
-		MSG_CONTROL_ADD="Vcs-Svn field (source stanza)"
-		CHANGED=1
-	fi
-
-  # 2) check for and add missing Vcs-Browser field
-	if ! grep ^Vcs-Browser $TRUNK/$p/debian/control > /dev/null; then
-		echo "$p: adding missing Vcs-Browser field"
-		perl -pi -e "s;(^Vcs-Svn:.+);\$1\nVcs-Browser: http://svn.debian.org/wsvn/pkg-perl/trunk/$p/;" $TRUNK/$p/debian/control
+
+#############
+# functions #
+#############
+
+usage() {
+	[ -n "$1" ] && echo "ERROR: $1" && echo
+	echo "Usage:"
+	echo "  $(basename $0) -V | -H | -W | -R | -A | -h"
+	echo
+	echo "  At least one parameter must be present."
+	echo
+	echo "  Parameters:"
+	echo "  -V debian/control: add Vcs-(Svn|Browser) fields; remove XS-Vcs-(Svn|Browser) fields"
+	echo "  -H debian/control: add Homepage field; remove pseudo-field Homepage"
+	echo "  -W debian/watch:   change CPAN URLs to http://search.cpan.org/dist/Mod-Ule/"
+	echo "  -R debian/rules:   rmdir /usr/\{lib,share\}/perl5 only if they exist"
+	echo "  -A all checks"
+	echo "  -h this help"
+	exit 1
+}
+
+testvcs() {
+	# check for and add missing Vcs-Svn field
+	if ! grep ^Vcs-Svn $TRUNK/$1/debian/control > /dev/null; then
+		echo "$1: adding missing Vcs-Svn field"
+		perl -pi -e "s;(Standards-Version:.+);\$1\nVcs-Svn: svn://svn.debian.org/pkg-perl/trunk/$1/;" $TRUNK/$1/debian/control
+		MSG_CONTROL_ADD="${MSG_CONTROL_ADD:+$MSG_CONTROL_ADD; }Vcs-Svn field (source stanza)"
+		CHANGED=1
+	fi
+
+	# check for and add missing Vcs-Browser field
+	if ! grep ^Vcs-Browser $TRUNK/$1/debian/control > /dev/null; then
+		echo "$1: adding missing Vcs-Browser field"
+		perl -pi -e "s;(^Vcs-Svn:.+);\$1\nVcs-Browser: http://svn.debian.org/wsvn/pkg-perl/trunk/$1/;" $TRUNK/$1/debian/control
 		MSG_CONTROL_ADD="${MSG_CONTROL_ADD:+$MSG_CONTROL_ADD; }Vcs-Browser field (source stanza)"
 		CHANGED=1
 	fi
 
-	# 3) check for and remove old Homepage from long description
-	OLDHP=$(egrep "^  Homepage: " $TRUNK/$p/debian/control | egrep -o "http.+")
+	# remove old XS-Vcs-(Svn|Browser) fields
+	if grep ^XS-Vcs- $TRUNK/$1/debian/control > /dev/null; then
+		echo "$1: removing old XS-Vcs-* fields"
+		sed -i -e '/^XS-Vcs-/ d' $TRUNK/$1/debian/control
+		MSG_CONTROL_RM="${MSG_CONTROL_RM:+$MSG_CONTROL_RM; }XS-Vcs-Svn fields (source stanza)"
+		CHANGED=1
+	fi
+}
+
+testhomepage() {
+	# check for and remove old Homepage from long description
+	OLDHP=$(egrep "^  Homepage: " $TRUNK/$1/debian/control | egrep -o "http.+")
 	if [ -n "$OLDHP" ] ; then
-		echo "$p: removing Homepage: pseudo-field from Description"
-		perl -e "undef \$/; my \$buf=<STDIN>; \$buf =~ s/\n \.\n  Homepage: .*//; print \$buf" < $TRUNK/$p/debian/control > $TRUNK/$p/debian/control.new
-		mv $TRUNK/$p/debian/control.new $TRUNK/$p/debian/control
-		MSG_CONTROL_RM="Homepage pseudo-field (Description)"
+		echo "$1: removing Homepage: pseudo-field from Description"
+		perl -e "undef \$/; my \$buf=<STDIN>; \$buf =~ s/\n \.\n  Homepage: .*//; print \$buf" < $TRUNK/$1/debian/control > $TRUNK/$1/debian/control.new
+		mv $TRUNK/$1/debian/control.new $TRUNK/$1/debian/control
+		MSG_CONTROL_RM="${MSG_CONTROL_RM:+$MSG_CONTROL_RM; }Homepage pseudo-field (Description)"
 		CHANGED=1
 		NEWHP=$OLDHP
 	fi
-  
-  # 4) remove old XS-Vcs-(Svn|Browser) fields
-	if grep ^XS-Vcs- $TRUNK/$p/debian/control > /dev/null; then
-		echo "$p: removing old XS-Vcs-* fields"
-		sed -i -e '/^XS-Vcs-/ d' $TRUNK/$p/debian/control
-		MSG_CONTROL_RM="${MSG_CONTROL_RM:+$MSG_CONTROL_RM; }XS-Vcs-Svn fields (source stanza)"
-		CHANGED=1
-	fi
-
-  # 5) check for and add missing new Homepage to source stanza
-	if ! egrep "^Homepage: " $TRUNK/$p/debian/control > /dev/null; then
-		echo "$p: trying to add missing Homepage field to source stanza"
+
+	# check for and add missing new Homepage to source stanza
+	if ! egrep "^Homepage: " $TRUNK/$1/debian/control > /dev/null; then
+		echo "$1: trying to add missing Homepage field to source stanza"
 		
 		# only construct new URL if we don't have a "real one"
 		if [ -z "$NEWHP" ] || echo "$NEWHP" | grep cpan\.org > /dev/null; then
 			# try to construct canonical URL
-			if [ -s $TRUNK/$p/Build.PL ]; then 
-				PERLNAME=$(perl -n -e "print if s;^.*module_name.*=>.*['\"[]([a-zA-Z0-9:_-]+)[]'\"].*\$;\$1;" $TRUNK/$p/Build.PL | sed -e 's/::/-/g' | head -n 1)
-			fi
-			if [ -s $TRUNK/$p/Makefile.PL ]; then 
-				PERLNAME=$(perl -n -e "print if s;^.*(?:DIST)?NAME.*=>.*['\"[]([a-zA-Z0-9:_-]+)[]'\"].*\$;\$1;" $TRUNK/$p/Makefile.PL | sed -e 's/::/-/g' | head -n 1)
-			fi
-			if [ -s $TRUNK/$p/META.yml ]; then 
-				PERLNAME=$(perl -n -e "print if s;^name:.* ([a-zA-Z0-9:_-]+).*\$;\$1;" $TRUNK/$p/META.yml | head -n 1)
+			if [ -s $TRUNK/$1/Build.PL ]; then 
+				PERLNAME=$(perl -n -e "print if s;^.*module_name.*=>.*['\"[]([a-zA-Z0-9:_-]+)[]'\"].*\$;\$1;" $TRUNK/$1/Build.PL | sed -e 's/::/-/g' | head -n 1)
+			fi
+			if [ -s $TRUNK/$1/Makefile.PL ]; then 
+				PERLNAME=$(perl -n -e "print if s;^.*(?:DIST)?NAME.*=>.*['\"[]([a-zA-Z0-9:_-]+)[]'\"].*\$;\$1;" $TRUNK/$1/Makefile.PL | sed -e 's/::/-/g' | head -n 1)
+			fi
+			if [ -s $TRUNK/$1/META.yml ]; then 
+				PERLNAME=$(perl -n -e "print if s;^name:.* ([a-zA-Z0-9:_-]+).*\$;\$1;" $TRUNK/$1/META.yml | head -n 1)
 			fi
 			if [ -n "$PERLNAME" ]; then
 				if curl --silent http://search.cpan.org/dist/$PERLNAME/ | grep '<title>.*</title>' | grep --silent $PERLNAME; then
@@ -107,25 +95,31 @@
 		fi
 		
 		if [ -n "$NEWHP" ]; then
-			perl -pi -e "s;(Standards-Version:.+);\$1\nHomepage: $NEWHP;" $TRUNK/$p/debian/control
+			perl -pi -e "s;(Standards-Version:.+);\$1\nHomepage: $NEWHP;" $TRUNK/$1/debian/control
 			MSG_CONTROL_ADD="${MSG_CONTROL_ADD:+$MSG_CONTROL_ADD; }Homepage field (source stanza)"
 			CHANGED=1
 		fi
 	fi
 
-	# 6) watchfile
-	if [ -e $TRUNK/$p/debian/watch ] && ! grep search\.cpan\.org/dist/ $TRUNK/$p/debian/watch >/dev/null; then
-		echo "$p: trying to change URL in debian/watch"
-		if perl -i -e "my \$changed=1; while(<>){ \$changed=0 if s{(?:^|\s+)(?:ht|f)tp://.*cpan.+/\s*(\S+)-(?:\S+)(\s.+)?$}{http://search.cpan.org/dist/\$1/ .*/\$1-v?(\\\\d[\\\\d_.]+)\\\\.(?:tar(?:\\\\.gz|\\\\.bz2)?|tgz|zip)\$2}i; print;} exit \$changed" $TRUNK/$p/debian/watch ; then
-			perl -pi -e "s;^version=2;version=3;" $TRUNK/$p/debian/watch
+}
+
+testwatchdist() {
+	# watchfile
+	if [ -e $TRUNK/$1/debian/watch ] && ! grep search\.cpan\.org/dist/ $TRUNK/$1/debian/watch >/dev/null; then
+		echo "$1: trying to change URL in debian/watch"
+		if perl -i -e "my \$changed=1; while(<>){ \$changed=0 if s{(?:^|\s+)(?:ht|f)tp://.*cpan.+/\s*(\S+)-(?:\S+)(\s.+)?$}{http://search.cpan.org/dist/\$1/ .*/\$1-v?(\\\\d[\\\\d_.]+)\\\\.(?:tar(?:\\\\.gz|\\\\.bz2)?|tgz|zip)\$2}i; print;} exit \$changed" $TRUNK/$1/debian/watch ; then
+			perl -pi -e "s;^version=2;version=3;" $TRUNK/$1/debian/watch
 			MSG_WATCH="debian/watch: use dist-based URL."
 			CHANGED=1
 		fi
 	fi
 	
-	# 7) handle rmdir /usr/{share,lib}/perl5
-	if grep -m 1 "rmdir.*ignore-fail-on-non-empty" $TRUNK/$p/debian/rules | grep -v "\[ \! -d" > /dev/null ; then
-		ARCH=$(grep -m 1 -h "Architecture:" $TRUNK/$p/debian/control | awk '{print $2;}')
+}
+
+testrmdir() {
+	# handle rmdir /usr/{share,lib}/perl5
+	if grep -m 1 "rmdir.*ignore-fail-on-non-empty" $TRUNK/$1/debian/rules | grep -v "\[ \! -d" > /dev/null ; then
+		ARCH=$(grep -m 1 -h "Architecture:" $TRUNK/$1/debian/control | awk '{print $2;}')
 		case $ARCH in
 			any)
 				DELDIR="/share/perl5"
@@ -136,18 +130,101 @@
 			*)
 				;;
 		esac
-		echo "$p: trying to make rmdir /usr${DELDIR} conditional"
-		if perl -i -e "my \$changed=1; while(<>){ \$changed=0 if s{rmdir.*ignore-fail-on-non-empty.*\s(\S+)$DELDIR}{[ ! -d \$1${DELDIR} ] || rmdir --ignore-fail-on-non-empty --parents \$1${DELDIR}}; print;} exit \$changed" $TRUNK/$p/debian/rules ; then
+		echo "$1: trying to make rmdir /usr${DELDIR} conditional"
+		if perl -i -e "my \$changed=1; while(<>){ \$changed=0 if s{rmdir.*ignore-fail-on-non-empty.*\s(\S+)$DELDIR}{[ ! -d \$1${DELDIR} ] || rmdir --ignore-fail-on-non-empty --parents \$1${DELDIR}}; print;} exit \$changed" $TRUNK/$1/debian/rules ; then
 			MSG_RULES="debian/rules: delete /usr${DELDIR} only if it exists." && \
 			CHANGED=1
 		fi
-		if perl -i -e "my \$changed=1; while(<>){ \$changed=0 if s{-?find.+xargs.+rmdir.+}{[ ! -d \\\$(CURDIR)/debian/\\\$(shell dh_listpackages)/usr${DELDIR} ] || rmdir --ignore-fail-on-non-empty --parents \\\$(CURDIR)/debian/\\\$(shell dh_listpackages)/usr${DELDIR}}; print;} exit \$changed" $TRUNK/$p/debian/rules ; then
+		if perl -i -e "my \$changed=1; while(<>){ \$changed=0 if s{-?find.+xargs.+rmdir.+}{[ ! -d \\\$(CURDIR)/debian/\\\$(shell dh_listpackages)/usr${DELDIR} ] || rmdir --ignore-fail-on-non-empty --parents \\\$(CURDIR)/debian/\\\$(shell dh_listpackages)/usr${DELDIR}}; print;} exit \$changed" $TRUNK/$1/debian/rules ; then
 			MSG_RULES="debian/rules: delete /usr${DELDIR} only if it exists." && \
 			CHANGED=1
 		fi
 	fi
+}	
+
+
+########
+# main #
+########
+
+# parse options
+
+[ $# -ge 1 ] || usage "No parameter."
+
+while getopts VHWRAh O; do
+	case "$O" in
+		V)
+			TESTVCS=1
+			;;
+		H)
+			TESTHOMEPAGE=1
+			;;
+		W)
+			TESTWATCHDIST=1
+			;;
+		R)
+			TESTRMDIR=1
+			;;
+		A)
+			TESTVCS=1
+			TESTHOMEPAGE=1
+			TESTWATCHDIST=1
+			TESTRMDIR=1
+			;;
+		h)
+			usage
+			;;
+		*)
+			usage "Unknown parameter."
+			;;
+	esac
+done
+shift $(($OPTIND - 1)) # bash: shift $((OPTIND - 1))
+
+# start the game
+
+CHANGED=0
+TRUNK=${1:-trunk}
+
+echo "Running svn up $TRUNK ..."
+svn up $TRUNK
+
+echo "Checking if $TRUNK is clean ..."
+UNCLEAN=$(svn st $TRUNK |egrep -v '^\?')
+if [ -n "$UNCLEAN" ]; then
+	echo "$UNCLEAN"
+	echo WARNING: $TRUNK is not clean
+fi
+
+# loop over packages
+
+echo "Grepping through packages ..."
+for p in $(svn ls $TRUNK); do 
+
+	# reset variables
+	p=${p%/}
+	OLDHP=
+	PERLNAME=
+	NEWHP=
+	MSG_CONTROL=
+	MSG_CONTROL_ADD=
+	MSG_CONTROL_RM=
+	MSG_WATCH=
+	MSG_RULES=
+
+	# TESTVCS - -V debian/control: add Vcs-(Svn|Browser) fields; remove XS-Vcs-(Svn|Browser) field
+	[ "$TESTVCS" = 1 ] && testvcs $p
+
+	# TESTHOMEPAGE - -H debian/control: add Homepage field; remove pseudo-field Homepage
+	[ "$TESTHOMEPAGE" = 1 ] && testhomepage $p
+
+	# TESTWATCHDIST - -W debian/watch:   change CPAN URLs to http://search.cpan.org/dist/Mod-Ule/
+	[ "$TESTWATCHDIST" = 1 ] && testwatchdist $p
 	
-	# 8) changelog
+	# TESTRMDIR - -R debian/rules:   rmdir /usr/\{lib,share\}/perl5 only if they exist
+	[ "$TESTRMDIR" = 1 ] && testrmdir $p
+	
+	# changelog
 	if [ -n "$MSG_CONTROL_ADD" -o -n "$MSG_CONTROL_RM" ] ; then
 		MSG_CONTROL="debian/control:"
 		[ -n "$MSG_CONTROL_ADD" ] && MSG_CONTROL="$MSG_CONTROL Added: $MSG_CONTROL_ADD."
@@ -164,6 +241,7 @@
 done
 
 # work is done. svn diff? svn commit?
+
 if [ "$CHANGED" = "1" ]; then
 
 	read -p "Show svn diff $TRUNK (y|N)? " DIFF




More information about the Pkg-perl-cvs-commits mailing list