[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Mass edit-pr
From: |
Hans-Albert Schneider |
Subject: |
Re: Mass edit-pr |
Date: |
Fri, 26 Mar 2004 18:34:16 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030703 |
Adam Cade wrote:
Is there any way to do a mass edit on the pr's??
(Editing the same field within a number of pr's)
Yes. I wrote the attached script to change the Responsible: field of
reports after a colleague left.
It does a lot of checking on files and also on its arguments, but the
trick is to create a little temporary file that does the replacement
(using the UNIX editor "ed"), have $EDITOR point to it, and then call
edit-pr for each report.
(I used this idea for other purposes, too. E.g., when we were shifted
from Siemens to Infineon I needed to adjust all our mail addresses, and
I used the opportunity to also cleanup the X-GNATS-NOTIFY: lines from
obsolete addresses.)
Note that this still stems from the GNATS 3.11x times; the line
pr_list=`awk ...`
will not work with GNATS 4 (the index file is now a binary format). The
line extracts those reports that belong to the old responsible and are
not closed.
But I think this should get you started.
Have a nice weekend,
Hans-Albert
--
Hans-Albert Schneider <address@hidden>
Infineon Technologies AG phone: (+49) 89 234 45445
Corporate Logic; Verification fax: (+49) 89 234 724399
(CL DAT DF V) Munich, Germany
#!/bin/sh
#
# change the >Responsible: of all non-closed reports.
# Author: address@hidden
# Copyright (C) Infineon Technologies AG, 2002
#
usage="usage: $0 -d gnats_root old_responsible new_responsible reason"
# Check usage
if [ $# -lt 5 ]
then
echo $usage >&2
exit 1
fi
if [ "x$1" = "x-d" ]
then
if [ "x$2" = "x" ]
then
echo $usage >&2
exit 1
else
gnatsroot="$2"
fi
else
echo $usage >&2
exit 1
fi
if [ "x$3" = "x" -o "x$4" = "x" -o "x$5" = "x" ]
then
echo $usage >&2
exit 1
fi
oldresp="$3"
newresp="$4"
reason="$5"
if [ ! -f "$gnatsroot/gnats-adm/index" ]
then
echo $usage >&2
echo "Cannot find index file $gnatsroot/gnats-adm/index" >&2
exit 1
fi
resp_file=$gnatsroot/gnats-adm/responsible
if grep "^${oldresp}:" "$resp_file"
then
: OK
else
echo "Warning: '${oldresp}' not listed in $resp_file" >&2
# No exit here; we are going to replace her/him anyway.
fi
if grep "^${newresp}:" "$resp_file"
then
: OK
else
echo $usage >&2
echo "Warning: New responsible '${newresp}' not listed in $resp_file" >&2
exit 1
fi
pr_list=`awk '-F|' '$3 == resp && $4 != "closed" {print $1}' resp="${oldresp}"
$gnatsroot/gnats-adm/index`
if [ "x$pr_list" = "x" ]
then
echo "No reports for '${oldresp}' found."
exit 0
fi
echo "Responsible" | grep -i "${oldresp}" >/dev/null
if [ $? -eq 0 ]
then
echo "Sorry, but the name of the new responsible, '${newresp}'," >&2
echo "is a substring of the word 'Responsible'." >&2
echo "This script cannot deal with that case; it would mess up" >&2
echo "your reports." >&2
echo "Please do the assignment manually." >&2
exit 2
fi
#
# End of usage checking
#
# Create a temporary file to be used as the EDITOR environment variable.
# Make sure it belongs to us, and nobody else can modify it.
#
tmp=${TMPDIR:-/tmp}/chresp$$
[ -f "$tmp" ] && rm -f "$tmp"
[ -f "$tmp" ] && echo "Cannot rm $tmp" >&2 && exit 2
touch "$tmp" || echo "Cannot create $tmp" >&2
[ -f "$tmp" ] || exit 2
chmod 700 "$tmp"
cat >"$tmp" <<EOF
#!/bin/sh
# change responsible of GNATS problem report
EOF
echo "(echo '/>Responsible:/ s/${oldresp}/${newresp}/'; echo w) | ed "'$1' >>
"$tmp"
EDITOR="$tmp"
export EDITOR
unset VISUAL
for id in $pr_list
do
echo "Changing PR# $id ..."
echo "$reason" | edit-pr -d "$gnatsroot" $id
done
rm -f "$tmp"
- Mass edit-pr, Adam Cade, 2004/03/26
- Re: Mass edit-pr,
Hans-Albert Schneider <=