commit-gnue
[Top][All Lists]
Advanced

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

gnue/reports/src GREngine.py GRReport.py GRRun.py


From: Jason Cater
Subject: gnue/reports/src GREngine.py GRReport.py GRRun.py
Date: Thu, 18 Oct 2001 19:23:11 -0400

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/10/18 19:23:11

Modified files:
        reports/src    : GREngine.py GRReport.py GRRun.py 

Log message:
        extended and cleaned up command line options; misc code cleanup

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/reports/src/GREngine.py.diff?cvsroot=OldCVS&tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/reports/src/GRReport.py.diff?cvsroot=OldCVS&tr1=1.13&tr2=1.14&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/reports/src/GRRun.py.diff?cvsroot=OldCVS&tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gnue/reports/src/GREngine.py
diff -u gnue/reports/src/GREngine.py:1.6 gnue/reports/src/GREngine.py:1.7
--- gnue/reports/src/GREngine.py:1.6    Tue May 29 22:19:49 2001
+++ gnue/reports/src/GREngine.py        Thu Oct 18 19:23:10 2001
@@ -29,11 +29,11 @@
 # HISTORY:
 #
 
-import os
+import os, sys
 import urllib
 import GRReport
 import GRParser
-from gnue.common import GDebug
+from gnue.common import openResource, GDebug
 
 
 class GREngine: 
@@ -44,25 +44,20 @@
 
   #
   # Run the report (reportFile) and generate the XML output. 
-  # Write the XML output to handle tempFileHandle 
+  # Write the XML output to the outputHandle IOStream
   #
-  def processReport(self, reportFile, parameters={}, sortoption=None, \
-                          includeStructuralComments=0): 
+  def processReport(self, reportFile, outputHandle=sys.stdout, parameters={}, 
+                          sortoption=None, includeStructuralComments=0, 
+                          omitGNUeXML=0): 
 
-    import sys
-    outputHandle = sys.stdout
-#    outputHandle = sys.stderr
-
-    drive = os.path.splitdrive(reportFile) 
-    if len(drive[0]):
-      fileHandle = open(reportFile,'r')
-    else:
-      fileHandle = urllib.urlopen(reportFile)
 
+    fileHandle = openResource(reportFile)
+
     report = GRParser.loadReport(fileHandle, self._connectionManager)
 
     report.process(outputHandle, parameters, sortoption, \
-                   includeStructuralComments)
+                   includeStructuralComments=includeStructuralComments, 
+                   omitGNUeXML=omitGNUeXML)
 
     GDebug.printMesg(999, '-'*60)
     GDebug.printMesg(999, report.dumpXML(1))
Index: gnue/reports/src/GRReport.py
diff -u gnue/reports/src/GRReport.py:1.13 gnue/reports/src/GRReport.py:1.14
--- gnue/reports/src/GRReport.py:1.13   Mon Oct 15 00:15:51 2001
+++ gnue/reports/src/GRReport.py        Thu Oct 18 19:23:10 2001
@@ -69,7 +69,7 @@
   # Destination must be a file handle (StringIO will work as well)
   #
   def process(self, dest, userParameters={}, userSortOption=None, \
-      includeStructuralComments=0):
+      includeStructuralComments=0, omitGNUeXML=0):
 
     import GRDataMapper
 
@@ -108,16 +108,18 @@
     layout.prepare(mapper, parameters)
 
     # Write common header information
-    dest.write ('<?xml version="1.0"?>\n')
-    dest.write ("<GNUe-report-output>\n")
-    dest.write ("  <GNUe-report-request>\n")
-    dest.write ( parameters.getRunOptionsAsXML() )
-    dest.write ( sortoptions.getRunOptionsAsXML() )
-    dest.write ("  </GNUe-report-request>\n")
+    if not omitGNUeXML: 
+      dest.write ('<?xml version="1.0"?>\n')
+      dest.write ("<GNUe-report-output>\n")
+      dest.write ("  <GNUe-report-request>\n")
+      dest.write ( parameters.getRunOptionsAsXML() )
+      dest.write ( sortoptions.getRunOptionsAsXML() )
+      dest.write ("  </GNUe-report-request>\n")
 
     layout.process(dest, includeStructuralComments)
 
-    dest.write ("</GNUe-report-output>\n")
+    if not omitGNUeXML: 
+      dest.write ("</GNUe-report-output>\n")
 
 
 
Index: gnue/reports/src/GRRun.py
diff -u gnue/reports/src/GRRun.py:1.1 gnue/reports/src/GRRun.py:1.2
--- gnue/reports/src/GRRun.py:1.1       Sun Oct  7 02:28:35 2001
+++ gnue/reports/src/GRRun.py   Thu Oct 18 19:23:10 2001
@@ -33,9 +33,20 @@
 from gnue.common import GDebug
 from gnue.common.GClientApp import GClientApp 
 from GREngine import GREngine
+import string
 
-from string import split, join, lower
 
+
+def quietprint(*message): 
+  print string.join(message)
+
+def quietprint_nl(*message): 
+  print string.join(message),
+
+def _quietprintSuppress(*message): 
+  GDebug.printMesg(1,string.join(message))
+
+
 class GRRun(GClientApp):
 
   #
@@ -47,27 +58,40 @@
   USAGE = "%s [options] file" % COMMAND
   COMMAND_OPTIONS = [ 
       [ 'destination_type', 'O', 'destination-type', 1, 'printer', 'type',  
-          'This specifies how the report should be output. The currently ' + \
-          'supported values for <type> are printer [default], file, and email. 
'+\
+          'This specifies how the report should be output. The currently '
+          'supported values for <type> are printer [default], file, email, and 
fax. '
           '[NOT YET IMPLEMENTED]' ],
       [ 'destination', 'o', 'destination', 1, 'lp', 'dest', 
-          'Where should the report be output to?  The value of this ' \
-          'depends on the destination type (e.g., if sending to printer, ' + \
-          'then -o specifies the printer name; if sending via email, then ' + \
-          '-o specifies the email address.) [NOT YET IMPLEMENTED]'], 
+          'Where should the report be output to?  The value of this ' 
+          'depends on the destination type (e.g., if sending to printer, '
+          'then -o specifies the printer name; if sending via email, then '
+          '-o specifies the email address.) If <dest> is "-", then output is '
+          'sent to stdout -- NOTE: when sending to stdout, also use the -q '
+          '[--quiet] option or you may get junk in your output stream. '
+          '[NOT YET IMPLEMENTED]'], 
       [ 'sortoption', 'S', 'sort-option', 1, '', 'sort',  
           'Select the "sort-option" used to sort the report. '], 
+      [ 'quiet', 'q', 'quiet', 0, 0, None,  
+          'Run GNUe Reports in quiet mode -- i.e., display no output. '
+          'NOTE: if --debug-level is specified, then suppressed text will '
+          'be output as debugging information (at debug level 1)'], 
       [ 'comment', 'C', 'comment', 0, 0, None,  
-          'Include structural comments in the XML output stream. Useful for 
debugging .grd files.'], 
+          'Include structural comments in the XML output stream. '
+          'Useful for debugging .grd files.'], 
+      [ 'exclude_xml', 'X', 'exclude-xml', 0, 0, None,  
+          'Do not output GNUe Report''s runtime XML markup information.  If 
specified, '
+          'then the GRD''s layout section will be processed and output '
+          'as-is; i.e., without any additional information added by '
+          'GNUe Reports.'], 
       [ 'user', 'u', 'user', 1, '', 'name',  
-          'Username used to log into the database.  Note that if ' + \
-          'specified, this will be used for all databases.  If not ' + \
+          'Username used to log into the database.  Note that if '
+          'specified, this will be used for all databases.  If not '
           'supplied, the program will prompt for username.'], 
-      [ 'password', 'U', 'pass', 1, '', 'passwd', 
-          'Password used to log into the database.  Note that if ' + \
-          'specified, this will be used for all databases.  If not ' + \
-          'supplied, the program will prompt for password.  NOTE THAT ' + \
-          'SUPPLYING A PASSWORD VIA THE COMMAND LINE MAY BE CONSIDERED ' + \
+      [ 'password', None, 'pass', 1, '', 'passwd', 
+          'Password used to log into the database.  Note that if '
+          'specified, this will be used for all databases.  If not '
+          'supplied, the program will prompt for password.  NOTE THAT '
+          'SUPPLYING A PASSWORD VIA THE COMMAND LINE MAY BE CONSIDERED '
           'A SECURITY RISK.' ] ]
   SUMMARY = \
      "GNUe Reports is the primary reporting agent of the GNU Enterprise 
system."
@@ -99,7 +123,6 @@
     except:
       self.handleStartupError ("No Report Definition File Specified.")
 
-
     #
     # Get the user supplied parameters
     #
@@ -108,14 +131,14 @@
     userParameters = {}
 
     for param in paramList: 
-      psplit = split(param,'=')
+      psplit = string.split(param,'=',1)
       if len(psplit) == 1: 
         self.handleStartupError ( \
             'Parameter "%s" specified, but no value supplied.' % psplit[0] )
-      userParameters[lower(psplit[0])] = join(psplit[1:],'=')
+      userParameters[lower(psplit[0])] = psplit[1]
 
       GDebug.printMesg(2,'Param "%s"="%s" ' % \
-           (lower(psplit[0]), join(psplit[1:],'=')))
+           (string.lower(psplit[0]), psplit[1]))
 
     #
     # Get the user supplied sortoption
@@ -126,9 +149,21 @@
       sortoption = None
 
 
+    #
+    # Set quiet mode
+    #
+    if self.OPTIONS["quiet"]:
+      global quietprint
+      global quietprint_nl
+      quietprint = _quietprintSuppress
+      quietprint_nl = _quietprintSuppress
+
+    
+
     GREngine(self.getConnectionManager()).processReport(reportfile, \
         parameters=userParameters, sortoption=sortoption, \
-        includeStructuralComments=self.OPTIONS["comment"])
+        includeStructuralComments=self.OPTIONS["comment"], 
+        omitGNUeXML=self.OPTIONS["exclude_xml"])
 
 
 #
@@ -142,28 +177,28 @@
 
   def getLogin(self, loginData): 
     try:
-      print "*"*60
+      quietprint ( "*"*60 )
       if len(loginData[1]): 
-        print 'Attempting to log into "%s" (%s):' % (loginData[1], 
loginData[0])
+        quietprint ( 'Attempting to log into "%s" (%s):' % (loginData[1], 
loginData[0]) )
       else: 
-        print 'Attempting to log into %s:' % (loginData[0])
-      print 
+        quietprint ( 'Attempting to log into %s:' % (loginData[0]) )
+      quietprint ("")
       val = {} 
       for prompt in loginData[2]: 
          if self.defaults.has_key(prompt[0])  and self.defaults[prompt[0]]: 
-           print "  %s: " % prompt[1], 
+           quietprint_nl ( "  %s: " % prompt[1] )
            if prompt[2]: 
-             print "***"
+             quietprint ( "***" )
            else:
-             print self.defaults[prompt[0]]
+             quietprint ( self.defaults[prompt[0]] )
            val[prompt[0]] = self.defaults[prompt[0]]
          else: 
            if prompt[2]: 
              val[prompt[0]] = getpass.getpass("  %s: " % prompt[1])
            else: 
              val[prompt[0]] = raw_input("  %s: " % prompt[1])
-      print 
-      print "*"*60
+      quietprint ("")
+      quietprint ("*"*60)
       return val
     except KeyboardInterrupt: 
       raise GLoginHandler.UserCanceledLogin



reply via email to

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