summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2012-06-27 17:14:00 +0200
committerJan Pokorný <jpokorny@redhat.com>2012-06-27 17:14:37 +0200
commit1a61f09a74ff60e48d29eeb3071c4cca4b59ca15 (patch)
treead0b74e7caa1554e15b81e1b6d49932020095b52
parent5f72fa08776eacb77a3d18e22d131d12fc7248b8 (diff)
downloadwatch-bz-1a61f09a74ff60e48d29eeb3071c4cca4b59ca15.tar.gz
watch-bz-1a61f09a74ff60e48d29eeb3071c4cca4b59ca15.tar.xz
watch-bz-1a61f09a74ff60e48d29eeb3071c4cca4b59ca15.zip
start modularization, add logout and some comments
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rwxr-xr-xwatch-bz105
1 files changed, 66 insertions, 39 deletions
diff --git a/watch-bz b/watch-bz
index 0a20e08..11afd54 100755
--- a/watch-bz
+++ b/watch-bz
@@ -1,4 +1,5 @@
#!/bin/bash
+# silly, but good-enough bugzilla monitoring
# jpokorny@redhat.com (will be pleased to know about further enhancements)
# usage:
@@ -11,18 +12,25 @@
# - optionally set BZUSER to avoid the need to login manually before
# the "watch session"; you can set BZPASSWORD as well but be careful!
+#set -eu
+export LANG=C
+
HERE=$(dirname $0)
BUGZILLA=$(which bugzilla 2>/dev/null)
BUGZILLA_ROOT=/usr
+BUGZILLA_COOKIE=~/.watchbzcookies
+BUGZILLA_LOGOUT=1
# example defaults, modify via ~/.watchbzrc
COMPONENT=luci,ricci,clustermon,conga,sunzi
STATUS=OPEN
REFRESH_INTERVAL=600 # [s], better not to drain bugzilla's power...
+# user configuration
[ -f ~/.watchbzrc ] && source ~/.watchbzrc
+# guess correct paths
if [ -z "$BUGZILLA" ]; then
# BUGZILLA_ROOT (path to local repo) should rather be set in ~/.watchbzrc
BUGZILLA="${BUGZILLA_ROOT}/bin/bugzilla"
@@ -33,6 +41,7 @@ fi
SEP=@@@
WIDTH=$(( $(stty size | cut -d' ' -f2) - 1 ))
+# arguments
if [ $# -ge 1 ]; then
if [[ "$1" = -* ]]; then
STATUS=$(echo "$1" | cut -c2-)
@@ -51,44 +60,62 @@ else
OUTPUT_FMT="%{bug_id}$SEP%{product}$SEP%{priority}$SEP%{status}$SEP%{flags}$SEP%{short_desc}"
fi
-# login when available
-if [ -n "$BZUSER" ]; then
- "$BUGZILLA" login "$BZUSER" $BZPASSWORD
- if [ $? -ne 0 ]; then
- echo "Cannot log in"
- exit 2
+
+do_logout () {
+ rm "${BUGZILLA_COOKIE}"
+}
+
+# exclusively using globals
+do_init () {
+ # login when available
+ if [ -n "$BZUSER" ] && [ ! -f "${BUGZILLA_COOKIE}" ]; then
+ "$BUGZILLA" --cookiefile="${BUGZILLA_COOKIE}" login "$BZUSER" $BZPASSWORD
+ if [ $? -ne 0 ]; then
+ echo "Cannot log in"
+ exit 2
+ fi
fi
-fi
-#sh -c \
-watch -t --interval $REFRESH_INTERVAL --differences=cumulative \
- "$BUGZILLA query -c $COMPONENT -t $STATUS --outputformat $OUTPUT_FMT \
- | sed -u \
- -e \"s|${SEP}Red Hat Enterprise Linux |${SEP}EL|\" \
- -e \"s|${SEP}Fedora|${SEP} F |\" \
- -e \"s|${SEP}NEW|${SEP}N|\" \
- -e \"s|${SEP}ASSIGNED|${SEP}A|\" \
- -e \"s|${SEP}POST|${SEP}P|\" \
- -e \"s|${SEP}MODIFIED|${SEP}M|\" \
- -e \"s|${SEP}ON_QA|${SEP}Q|\" \
- -e \"s|${SEP}ON_DEV|${SEP}D|\" \
- -e \"s|${SEP}VERIFIED|${SEP}V|\" \
- -e \"s|${SEP}RELEASE_PENDING|${SEP}R|\" \
- -e \"s|${SEP}CLOSED|${SEP}C|\" \
- -e \"s|${SEP}urgent|${SEP}!!!|\" \
- -e \"s|${SEP}high|${SEP}!!|\" \
- -e \"s|${SEP}medium|${SEP} ! |\" \
- -e \"s|${SEP}low|${SEP} ~ |\" \
- -e \"s|${SEP}unspecified|${SEP} ? |\" \
- -e \"s|qa_ack|QA|\" \
- -e \"s|pm_ack|PM|\" \
- -e \"s|devel_ack|D|\" \
- -e \"s|needinfo|I|\" \
- -e \"s|exception|E|\" \
- -e \"s|blocker|BL|\" \
- -e \"s|requires_release_note|RN|\" \
- -e \"s|rhel-||\" \
- -e \"s|None||\" \
- | ${HERE}/table-data $SEP | cut -c-$WIDTH"
-# todo: colours for priorities (rhbz#801626)
-#-e 's/\(urgent\)/\^\[\[31m\1\^\[\[0m/' \
+ # C-c handler to optionally remove cookie on exit
+ test $BUGZILLA_LOGOUT -ne 0 && trap do_logout INT
+}
+
+# exclusively using globals
+do_watch () {
+ #sh -c \
+ watch -t --interval $REFRESH_INTERVAL --differences=cumulative \
+ "$BUGZILLA --cookiefile="${BUGZILLA_COOKIE}" query -c $COMPONENT \
+ -t $STATUS --outputformat $OUTPUT_FMT \
+ | sed -u \
+ -e \"s|${SEP}Red Hat Enterprise Linux |${SEP}EL|\" \
+ -e \"s|${SEP}Fedora|${SEP} F |\" \
+ -e \"s|${SEP}NEW|${SEP}N|\" \
+ -e \"s|${SEP}ASSIGNED|${SEP}A|\" \
+ -e \"s|${SEP}POST|${SEP}P|\" \
+ -e \"s|${SEP}MODIFIED|${SEP}M|\" \
+ -e \"s|${SEP}ON_QA|${SEP}Q|\" \
+ -e \"s|${SEP}ON_DEV|${SEP}D|\" \
+ -e \"s|${SEP}VERIFIED|${SEP}V|\" \
+ -e \"s|${SEP}RELEASE_PENDING|${SEP}R|\" \
+ -e \"s|${SEP}CLOSED|${SEP}C|\" \
+ -e \"s|${SEP}urgent|${SEP}!!!|\" \
+ -e \"s|${SEP}high|${SEP}!!|\" \
+ -e \"s|${SEP}medium|${SEP} ! |\" \
+ -e \"s|${SEP}low|${SEP} ~ |\" \
+ -e \"s|${SEP}unspecified|${SEP} ? |\" \
+ -e \"s|qa_ack|QA|\" \
+ -e \"s|pm_ack|PM|\" \
+ -e \"s|devel_ack|D|\" \
+ -e \"s|needinfo|I|\" \
+ -e \"s|exception|E|\" \
+ -e \"s|blocker|BL|\" \
+ -e \"s|requires_release_note|RN|\" \
+ -e \"s|rhel-||\" \
+ -e \"s|None||\" \
+ | ${HERE}/table-data $SEP | cut -c-$WIDTH"
+ # todo: colours for priorities (rhbz#801626)
+ #-e 's/\(urgent\)/\^\[\[31m\1\^\[\[0m/' \
+}
+
+do_init
+do_watch