You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@community.apache.org by se...@apache.org on 2015/10/28 00:27:37 UTC

svn commit: r1710905 - in /comdev/reporter.apache.org/trunk/data: errtee.py parsepmcs.py python3logger.sh

Author: sebb
Date: Tue Oct 27 23:27:37 2015
New Revision: 1710905

URL: http://svn.apache.org/viewvc?rev=1710905&view=rev
Log:
Enable errtee for parsepmcs.py

Added:
    comdev/reporter.apache.org/trunk/data/errtee.py   (with props)
Modified:
    comdev/reporter.apache.org/trunk/data/parsepmcs.py
    comdev/reporter.apache.org/trunk/data/python3logger.sh

Added: comdev/reporter.apache.org/trunk/data/errtee.py
URL: http://svn.apache.org/viewvc/comdev/reporter.apache.org/trunk/data/errtee.py?rev=1710905&view=auto
==============================================================================
--- comdev/reporter.apache.org/trunk/data/errtee.py (added)
+++ comdev/reporter.apache.org/trunk/data/errtee.py Tue Oct 27 23:27:37 2015
@@ -0,0 +1,36 @@
+"""
+    Class to copy stderr to stdout.
+
+    This is intended for use in cronjobs,
+    where it is useful to have both stderr and stdout in the log file
+    but still have stderr so that the mailer gets any errors
+    The main script should be run unbuffered (-u)
+
+    Unfortunately Python does not seem to offer the equivalent of:
+    perl -[mM][-]module  execute "use/no module..." before executing program
+    ruby -rlibrary       require the library before executing your script
+    lua  -l name         require library 'name'
+    Thus the module has to be explicitly imported by the user script,
+    and the user must defing the 'ERRTEE' environment variable to enable it
+  
+"""
+import sys
+import os
+
+class ErrTee(object):
+    def write(self, buf):
+        sys.__stderr__.write(buf)
+        sys.stdout.write(buf)
+    def flush(self):
+        sys.__stderr__.flush()
+
+# only enable the override if it is needed
+if 'ERRTEE' in os.environ:
+    sys.stderr=ErrTee()
+
+if __name__ == '__main__': # simple test
+    print("STDOUT1")
+    print("STDERR2", file=sys.stderr)
+    sys.stderr=ErrTee() # enable for testing
+    print("STDERR3", file=sys.stderr)
+    raise Exception("STDERR4")
\ No newline at end of file

Propchange: comdev/reporter.apache.org/trunk/data/errtee.py
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: comdev/reporter.apache.org/trunk/data/parsepmcs.py
URL: http://svn.apache.org/viewvc/comdev/reporter.apache.org/trunk/data/parsepmcs.py?rev=1710905&r1=1710904&r2=1710905&view=diff
==============================================================================
--- comdev/reporter.apache.org/trunk/data/parsepmcs.py (original)
+++ comdev/reporter.apache.org/trunk/data/parsepmcs.py Tue Oct 27 23:27:37 2015
@@ -20,6 +20,7 @@ if sys.hexversion < 0x030000F0:
          time.time() when entry was last seen,
          ]
 """
+import errtee
 import re
 import urllib.request
 import csv

Modified: comdev/reporter.apache.org/trunk/data/python3logger.sh
URL: http://svn.apache.org/viewvc/comdev/reporter.apache.org/trunk/data/python3logger.sh?rev=1710905&r1=1710904&r2=1710905&view=diff
==============================================================================
--- comdev/reporter.apache.org/trunk/data/python3logger.sh (original)
+++ comdev/reporter.apache.org/trunk/data/python3logger.sh Tue Oct 27 23:27:37 2015
@@ -23,7 +23,7 @@ export
 # show the process tree
 #pstree -slapA $$
 
-python3 -u $SCRIPT 
+ERRTEE=1 python3 -u $SCRIPT 
 
 echo Completed $SCRIPT at $(date)
 echo '<<<'