commit-gnue
[Top][All Lists]
Advanced

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

r6776 - trunk/gnue-reports/src/tools


From: jcater
Subject: r6776 - trunk/gnue-reports/src/tools
Date: Wed, 1 Dec 2004 08:44:17 -0600 (CST)

Author: jcater
Date: 2004-12-01 08:44:17 -0600 (Wed, 01 Dec 2004)
New Revision: 6776

Modified:
   trunk/gnue-reports/src/tools/ReportPostProcessor.py
Log:
added support for stdin

Modified: trunk/gnue-reports/src/tools/ReportPostProcessor.py
===================================================================
--- trunk/gnue-reports/src/tools/ReportPostProcessor.py 2004-12-01 14:29:16 UTC 
(rev 6775)
+++ trunk/gnue-reports/src/tools/ReportPostProcessor.py 2004-12-01 14:44:17 UTC 
(rev 6776)
@@ -44,7 +44,7 @@
   VERSION = VERSION
   COMMAND = "gnue-reports-filter"
   NAME = "GNUe Reports Post-Processor"
-  USAGE = "%s input-file filter-name ..." % GClientApp.USAGE
+  USAGE = "%s file filter-name ..." % GClientApp.USAGE
   SUMMARY = \
       _("The GNUe Reports Post-Processor takes the XML output of gnue-reports 
and applies filters to generate formatted output.")
   USE_DATABASE_OPTIONS = False
@@ -116,12 +116,15 @@
 
     filters = GRFilters.GRFilters()
 
-    try:
-      fileHandle = openResource(reportfile)
-    except IOError, msg:
-      self.handleStartupError(
-         "Unable to read the requested report output\n  (%s)\n\n" % reportFile 
\
-         + "Additional Information:\n  %s" % msg)
+    if reportfile == '-':
+      fileHandle = sys.stdin
+    else:
+      try:
+        fileHandle = openResource(reportfile)
+      except IOError, msg:
+        self.handleStartupError(
+          "Unable to read the requested report output\n  (%s)\n\n" % 
reportFile \
+          + "Additional Information:\n  %s" % msg)
 
     if destinationType == 'file' and destination == '-':
       # Handle the special case of stdout
@@ -139,7 +142,10 @@
       # as we don't really want to load the entire XML file at this point)
       namespace = None
 
+      prereadLines = []
+
       line = fileHandle.readline()
+      prereadLines.append(line)
       while line and not namespace:
         if 'xmlns="GNUe:Reports:' in line:
           try:
@@ -147,20 +153,13 @@
           except:
             continue
         line = fileHandle.readline()
+        prereadLines.append(line)
 
       if not namespace:
+        fileHandle.close()
         self.handleStartupError(_("The file does not appear to be output from 
gnue-reports or is in an unsupported document type. (Perhaps gnue-reports was 
run with the -X option?)"))
 
-      # Reset the file handle
-      fileHandle.close()
-      try:
-        fileHandle = openResource(reportfile)
-      except IOError, msg:
-        self.handleStartupError(
-          "Unable to read the requested report output\n  (%s)\n\n" % 
reportFile \
-          + "Additional Information:\n  %s" % msg)
 
-
       # Create a Filter Adapter
       filtAdapter = filters.loadFilter(namespace,
                                        filter,
@@ -168,9 +167,10 @@
                                        filterOptions)
 
       dest = filtAdapter.open()
-      line = fileHandle.readline()
+      line = string.join(prereadLines)
       while line:
         dest.write(line)
+        sys.stdout.write(line)
         line = fileHandle.readline()
 
       # Cleanup





reply via email to

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