Index: /pykota/trunk/CREDITS
===================================================================
--- /pykota/trunk/CREDITS (revision 1716)
+++ /pykota/trunk/CREDITS (revision 1723)
@@ -130,4 +130,6 @@
   - Johannes Laemmermann - German translation
   - Paulo Silva - Eurotux - Improved ESC/P2 miniparser
+  - Christian Andreetta - SNMP waiting script
+  - Paolo Nobili - Universit�egli Studi di Padova - SNMP waiting script
 
 ==============================================================
Index: /pykota/trunk/pykota/version.py
===================================================================
--- /pykota/trunk/pykota/version.py (revision 1717)
+++ /pykota/trunk/pykota/version.py (revision 1723)
@@ -22,5 +22,5 @@
 #
 
-__version__ = "1.20alpha11_unofficial"
+__version__ = "1.20alpha12_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
Index: /pykota/trunk/bin/waitprinter.sh
===================================================================
--- /pykota/trunk/bin/waitprinter.sh (revision 1706)
+++ /pykota/trunk/bin/waitprinter.sh (revision 1723)
@@ -14,26 +14,76 @@
 # $Id$
 #
-# Fix by Matt Hyclak & Jerome Alet
-
-trap "KILLED=1" TERM
+# First version by Matt Hyclak & Jerome Alet
+# Rewritten from scratch, and contributed to PyKota, by Christian Andreetta
+# and Paolo Nobili
 
 # If ending phase, after the job has been fully transmitted to the printer
 # we have to wait for the printer being in printing mode before checking
 # if it is idle, otherwise we could have problems with slow printers.
+#--------------------------------------------------------------------------
 PATH=$PATH:/bin:/usr/bin:/usr/local/bin:/opt/bin
-if [ x$PYKOTAACTION != "xDENY" ] && [ x$PYKOTAPHASE = "xAFTER" ] ; then
-  until snmpget -v1 -c public -Ov $1 HOST-RESOURCES-MIB::hrPrinterStatus.1 | grep -i printing >/dev/null; do
-    if [ "$KILLED" = 1 ]; then
-      break ;
-    fi 
-    sleep 1 ;
-  done
-fi
-
-# In any case, wait until the printer is idle again.
-until snmpget -v1 -c public -Ov $1 HOST-RESOURCES-MIB::hrPrinterStatus.1 | grep -i idle >/dev/null ; do 
-  if [ "$KILLED" = 1 ]; then
-    break ;
-  fi 
-  sleep 1 ;
-done
+#--------------------------------------------------------------------------
+LOG_FILE=/var/log/pykota-waitprinter-snmpread.log
+LOG_DO_FLAG=""  #set different from null for file logging
+IDLE_WAIT_NUM=3 #number of snmp reads to consider the printer _really_ idle
+SNMP_DELAY=1    #seconds between snmp reads
+#--------------------------------------------------------------------------
+# END OF CONF
+#--------------------------------------------------------------------------
+function log_msg() {
+        if [ -n "${LOG_DO_FLAG}" ]; then
+                echo `date` "$*" >> ${LOG_FILE}
+        fi
+}
+#--------------------------------------------------------------------------
+function printer_status_get() {
+        local printer="$1"
+        PRINTER_STATUS=`snmpget -v1 -c public -Ov ${printer} HOST-RESOURCES-MIB::hrPrinterStatus.1`
+}
+#--------------------------------------------------------------------------
+function printing_wait() {
+        local printer="$1"
+        log_msg "CICLE: printing_wait"
+        while [ 1 ]; do
+                printer_status_get "${printer}"
+                log_msg "${PRINTER_STATUS}"
+                echo "${PRINTER_STATUS}" | grep -iE '(printing)|(idle)' >/dev/null && break
+                sleep ${SNMP_DELAY}
+        done
+}
+#--------------------------------------------------------------------------
+function idle_wait() {
+        local printer="$1" idle_num=0 idle_flag=0
+        log_msg "CICLE: idle_wait"
+        while [ ${idle_num} -lt ${IDLE_WAIT_NUM} ]; do
+                printer_status_get "${printer}"
+                log_msg "${PRINTER_STATUS}"
+                idle_flag=0
+                echo "${PRINTER_STATUS}" | grep -iE '(idle)' >/dev/null && idle_flag=1
+                if [ ${idle_flag} -gt 0 ]; then
+                        idle_num=$((idle_num+1))
+                else
+                        idle_num=0
+                fi
+                sleep ${SNMP_DELAY}
+        done
+}
+#--------------------------------------------------------------------------
+function main() {
+        local printer="$1"
+        log_msg "BEGIN"
+        ##log_msg "`ls -la /var/spool/{cups,samba}`"
+        log_msg "Pykota Phase: ${PYKOTAPHASE}"
+        if [ x$PYKOTAACTION != "xDENY" ] && [ x$PYKOTAPHASE = "xAFTER" ] ; then
+                printing_wait "${printer}"
+        fi
+        idle_wait "${printer}" #in any case
+        ##log_msg "`ls -la /var/spool/{cups,samba}`"
+        log_msg "END"
+}
+#==========================================================================
+# MAIN
+#==========================================================================
+PRINTER_STATUS=""
+main "$1"
+exit $?
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 1717)
+++ /pykota/trunk/NEWS (revision 1723)
@@ -22,4 +22,9 @@
 PyKota NEWS :
 
+    - 1.20alpha12 :
+    
+        - waitprinter.sh rewritten from scratch to wait
+          for printer status stabilization.
+        
     - 1.20alpha11 : 
     
