trans-coord-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error handling


From: Kaloian Doganov
Subject: Re: Error handling
Date: Tue, 26 Feb 2008 22:26:42 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gNewSense gnu/linux)

Here is what I've came up to:  I've introduced two more scripts:

   1. mailfail - mails output of a failed command.  Intended to be
      useful as a generic error-reporting tool.

   2. validate-html-notify - runs `validate-html' through `mailfail'.
      Intended to be handy in our GNUmakefile.

The patch follows.

Index: GNUmakefile
===================================================================
RCS file: /sources/trans-coord/trans-coord/gnun/server/gnun/GNUmakefile,v
retrieving revision 1.2
diff -u -r1.2 GNUmakefile
--- GNUmakefile 26 Feb 2008 16:12:21 -0000      1.2
+++ GNUmakefile 26 Feb 2008 20:17:08 -0000
@@ -20,7 +20,7 @@
 PO4A-GETTEXTIZE = po4a-gettextize
 PO4A-TRANSLATE = po4a-translate
 MAKE-PROTOTYPE = ./make-prototype
-VALIDATE-HTML = ./validate-html
+VALIDATE-HTML-NOTIFY = ./validate-html-notify
 SED = sed
 M4 = m4
 
@@ -48,8 +48,19 @@
 VALIDATESKIP := echo "SKIP:"
 endif
 
+# Do not send warning mails by default unless NOTIFY=yes.
+ifneq (,$(findstring yes,$(NOTIFY)))
+NOTIFYSKIP :=
+else
+NOTIFYSKIP := --dry-run
+endif
+
 # Email addresses for notifications.
 devel_addr := address@hidden
+# FIXME: Change to www-discuss in the official instance.
+web_addr := address@hidden
+# FIXME: Change to trans-coord-discuss in the official instance.
+transl_addr := address@hidden
 
 rootdir := ../..
 
@@ -178,7 +189,7 @@
 # in order to prevent further messing up in the chain.  For
 # extra safety, exit with an error so that make does not
 # proceed to the next command.
-       $(VALIDATESKIP) $(VALIDATE-HTML) $<
+       $(VALIDATESKIP) $(VALIDATE-HTML-NOTIFY) $(NOTIFYSKIP) $(web_attr) $<
        $(MAKE-PROTOTYPE) --home --input=$< --generic=generic.html --output=$@ 
|| ($(RM) $@ ; exit 1)
        $(SED) --in-place "s/\$$Date.*\$$/<gnun>\0<\/gnun>/g" $@
 
@@ -216,7 +227,7 @@
 # FIXME: Remove this conditional when GNUN operates in `www', where we
 # want to validate everything.
 ifneq (,$(findstring $(1),bg ru))
-       $(VALIDATESKIP) $(VALIDATE-HTML) $$@
+       $(VALIDATESKIP) $(VALIDATE-HTML-NOTIFY) $(NOTIFYSKIP) $(transl_addr) 
$$@ || (sleep 1 ; touch $(rootdir)/po/home.$(1).po)
 endif
 endef
 
@@ -226,7 +237,7 @@
 ### Rules for all other articles ###
 define article_pot_rules
 $(1).proto $(1).translinks: $(subst /po/,/,$(1).html)
-       $(VALIDATESKIP) $(VALIDATE-HTML) $$<
+       $(VALIDATESKIP) $(VALIDATE-HTML-NOTIFY) $(NOTIFYSKIP) $(transl_addr) $$<
        $(MAKE-PROTOTYPE) --input=$$< --generic=generic.html 
--output=$(1).proto --translinks=$(1).translinks || \
          ($(RM) $(1).proto $(1).translinks ; exit 1)
        $(SED) --in-place "s/\$$$$Date.*\$$$$/<gnun>\0<\/gnun>/g" $(1).proto
@@ -252,7 +263,7 @@
                $(SED) --in-place "s/\(<!--#include 
virtual=\".*$$$$replaceable\)\(.html\" -->\)/\1.$(2)\2/g" $(1).m4; \
        done;
        $(M4) $(1).m4 > $$@
-       $(VALIDATESKIP) $(VALIDATE-HTML) $$@
+       $(VALIDATESKIP) $(VALIDATE-HTML-NOTIFY) $(NOTIFYSKIP) $(transl_addr) 
$$@ || (sleep 1 ; touch $(1).po)
 endef
 
 $(foreach base,$(ALL_BASE),$(eval $(call article_pot_rules,$(base))))
Index: mailfail
===================================================================
RCS file: mailfail
diff -N mailfail
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ mailfail    26 Feb 2008 20:17:08 -0000
@@ -0,0 +1,65 @@
+#!/bin/bash
+
+# Copyright (C) 2008 Free Software Foundation, Inc.
+
+# This file is part of GNUnited Nations.
+
+# GNUnited Nations 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, either version 3 of the
+# License, or (at your option) any later version.
+
+# GNUnited Nations 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 GNUnited Nations.  If not, see <http://www.gnu.org/licenses/>.
+
+# Usage:
+#
+# ./mailfail [--dry-run] RCPT SUBJECT CMD [ARG ...]
+#
+# Example:
+#
+# ./mailfail address@hidden "[GNUN error] File is not valid XHTML" ./validate 
article.html
+
+function usage() {
+    echo 1>&2 Usage: ./mailfail [--dry-run] RCPT SUBJECT CMD [ARG ...]
+    exit 1
+}
+
+if [[ $# -lt 1 ]]; then usage; fi;
+
+# Read arguments
+DRY_RUN=""
+if [[ "$1" == "--dry-run" ]]; then
+    if [[ $# -lt 4 ]]; then usage; fi;
+    DRY_RUN="yes"
+    RCPT="$2"
+    SUBJECT="$3"
+    shift 3
+else
+    if [[ $# -lt 3 ]]; then usage; fi
+    RCPT="$1"
+    SUBJECT="$2"
+    shift 2
+fi
+
+# Create tempfile and mark it for deletion on exit.
+TMP=`mktemp -t gnun.mailfail.XXXXXX`
+trap "rm -f $TMP" EXIT
+
+# Execute the command and capture it's output
+"$@" &>"$TMP"
+CMDSTATUS=$?
+cat "$TMP"
+
+# Mail the captured output, if needed
+if [[ ( -z "$DRY_RUN" ) && ( "$CMDSTATUS" -ne 0 ) ]]; then
+    mail "$RCPT" --subj "$SUBJECT" < "$TMP"
+fi
+
+# Exit with command's original exit status.
+exit $CMDSTATUS
Index: validate-html-notify
===================================================================
RCS file: validate-html-notify
diff -N validate-html-notify
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ validate-html-notify        26 Feb 2008 20:17:08 -0000
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+# Copyright (C) 2008 Free Software Foundation, Inc.
+
+# This file is part of GNUnited Nations.
+
+# GNUnited Nations 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, either version 3 of the
+# License, or (at your option) any later version.
+
+# GNUnited Nations 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 GNUnited Nations.  If not, see <http://www.gnu.org/licenses/>.
+
+# Usage:
+#
+# ./validate-html-notify [--dry-run] RCPT FILE
+#
+# Example:
+#
+# ./validate-html-notify address@hidden article.html
+
+function usage() {
+    echo 1>&2 Usage: ./validate-html-notify [--dry-run] RCPT FILE
+    exit 1
+}
+
+if [[ $# -lt 1 ]]; then usage; fi;
+
+# Read arguments
+DRY_RUN=""
+if [[ "$1" == "--dry-run" ]]; then
+    if [[ $# -ne 3 ]]; then usage; fi;
+    DRY_RUN="$1"
+    RCPT="$2"
+    FILE="$3"
+    shift 3
+else
+    if [[ $# -ne 2 ]]; then usage; fi
+    RCPT="$1"
+    FILE="$2"
+    shift 2
+fi
+
+SUBJ="[GNUN Error] $FILE is not valid XHTML"
+
+./mailfail $DRY_RUN "$RCPT" "$SUBJ" ./validate-html "$FILE"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]