/[papo]/gnue/reports/src/GRRun.py
ViewVC logotype

Diff of /gnue/reports/src/GRRun.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by charlie, Fri Jun 28 19:43:54 2002 UTC revision 1.2 by styxman, Thu Nov 14 23:02:37 2002 UTC
# Line 34  from gnue.common.GClientApp import GClie Line 34  from gnue.common.GClientApp import GClie
34  from GREngine import GREngine  from GREngine import GREngine
35  import GRFilters  import GRFilters
36  import GRExceptions  import GRExceptions
37    from GRRunUI import GRRunUI
38    from GRReportInfo import GRReportInfo
39  import string, sys  import string, sys
40  import tempfile  import tempfile
41  from gnue.reports.GRConfig import ConfigOptions  from gnue.reports.GRConfig import ConfigOptions
# Line 82  class GRRun(GClientApp): Line 84  class GRRun(GClientApp):
84            'is the name of the filtering process as defined on the Report '            'is the name of the filtering process as defined on the Report '
85            'Server machine. If not specified, the "raw" filter is used '            'Server machine. If not specified, the "raw" filter is used '
86            '(i.e., no filtering takes place.)'],            '(i.e., no filtering takes place.)'],
87        [ 'list_filters', None, 'filter-list', 0, 0, None,        [ 'list_filters', None, 'list-filters', 0, 0, None,
88            'List the available [predefined] filters available to GNUe Reports'],            'List the available [predefined] filters available to GNUe Reports'],
89        [ 'filter_options', 'F', 'filter-options', 1, '', 'opts',        [ 'filter_options', 'F', 'filter-options', 1, '', 'opts',
90            'Options to pass to the filter process. Available options are '            'Options to pass to the filter process. Available options are '
91            'specific to the filter.  --filter-list will list available filters '            'specific to the filter.  --list-filters will list available filters '
92            'and their options.  Example: \'--filter-options "paper=letter margin=1,1,1,1" \''],            'and their options.  Example: \'--filter-options "paper=letter margin=1,1,1,1" \''],
93        [ 'sortoption', 's', 'sort', 1, '', 'sort',        [ 'sortoption', 's', 'sort', 1, '', 'sort',
94            'Select the "sort-option" used to sort the report. '],            'Select the "sort-option" used to sort the report. '],
95          [ 'batch', 'b', 'batch', 0, 0, None,
96              'Run GNUe Reports in batch mode -- i.e., no login information or '
97              'runtime parameters will be prompted.  If required parameters are '
98              'not provided, then Reports will terminate with an error'],
99        [ 'quiet', 'q', 'quiet', 0, 0, None,        [ 'quiet', 'q', 'quiet', 0, 0, None,
100            'Run GNUe Reports in quiet mode -- i.e., display no output. '            'Run GNUe Reports in quiet mode -- i.e., display no output. '
101            'NOTE: if --debug-level is specified, then suppressed text will '            'NOTE: if --debug-level is specified, then suppressed text will '
102            'be output as debugging information (at debug level 1)'],            'be output as debugging information (at debug level 1)'],
103          [ 'ui', 'U', 'ui', 1, 'text', 'interface',
104              'Run GNUe Reports using a specific UI.  Possible UI\'s are text and gui.'],
105        [ 'comment', 'C', 'comment', 0, 0, None,        [ 'comment', 'C', 'comment', 0, 0, None,
106            'Include structural comments in the XML output stream. '            'Include structural comments in the XML output stream. '
107            'Useful for debugging .grd files.'],            'Useful for debugging .grd files.'],
# Line 125  class GRRun(GClientApp): Line 133  class GRRun(GClientApp):
133    #    #
134    def __init__(self):    def __init__(self):
135      GClientApp.__init__(self, application='reports',defaults=ConfigOptions)      GClientApp.__init__(self, application='reports',defaults=ConfigOptions)
     lh = LoginHandler()  
   
     try:  
       if len(self.OPTIONS['user']):  
         lh.defaults['_username'] = self.OPTIONS['user']  
       if len(self.OPTIONS['password']):  
         lh.defaults['_password'] = self.OPTIONS['password']  
     except:  
       pass  
   
     self.getConnectionManager().setLoginHandler(lh)  
136    
137    
138    def run(self):    def run(self):
# Line 144  class GRRun(GClientApp): Line 141  class GRRun(GClientApp):
141      # Are we doing a simple help-like operation?      # Are we doing a simple help-like operation?
142      #      #
143    
     # ...list available filters?  
     if self.OPTIONS["list_filters"]:  
       self.listFilters()  
       sys.exit()  
   
   
144      # assign report file from 1st free argument      # assign report file from 1st free argument
145      try:      try:
146        reportfile = self.ARGUMENTS[0]        reportfile = self.ARGUMENTS[0]
147      except:      except:
148        self.handleStartupError ("No Report Definition File Specified.")        self.handleStartupError ("No Report Definition File Specified.")
149    
150        # ...list available filters?
151        if self.OPTIONS["list_filters"]:
152          self.listFilters(reportfile)
153          sys.exit()
154    
155    
156      #      #
157      # Get the user supplied parameters      # Get the user supplied parameters
158      #      #
# Line 183  class GRRun(GClientApp): Line 180  class GRRun(GClientApp):
180        sortoption = None        sortoption = None
181    
182    
183        filter = self.OPTIONS['filter']
184        destination = self.OPTIONS["destination"]
185        destinationType = self.OPTIONS["destination_type"]
186        destinationOptions = self.OPTIONS["destination_options"]
187    
188    
189      #      #
190      # Set quiet mode      # Set quiet mode
191      #      #
# Line 194  class GRRun(GClientApp): Line 197  class GRRun(GClientApp):
197    
198    
199      #      #
200        # Will we do a UI engine
201        #
202        if not self.OPTIONS['batch']:
203          runui = GRRunUI(self,reportInfo=self.getReportInformation(reportfile),
204                          ui = self.OPTIONS['ui'],
205                          userParameters=userParameters,
206                          destination=destination,
207                          destinationType=destinationType,
208                          filter=filter,
209                          sortoption=sortoption
210                          )
211    
212          lh = runui.getLoginHandler()
213          self.getConnectionManager().setLoginHandler(lh)
214    
215          runui.run()
216    
217          userParameters = runui.getParameters()
218          destination = runui.getDestination()
219          destinationType = runui.getDestinationType()
220          filter = runui.getFilter()
221          sortoption = runui.getSortOption()
222    
223        else:
224          lh = NoLoginHandler()
225          self.getConnectionManager().setLoginHandler(lh)
226    
227        try:
228          if len(self.OPTIONS['user']):
229            lh.defaults['_username'] = self.OPTIONS['user']
230          if len(self.OPTIONS['password']):
231            lh.defaults['_password'] = self.OPTIONS['password']
232        except:
233          pass
234    
235    
236    
237    
238        #
239      # Now, run an engine instance      # Now, run an engine instance
240      #      #
241      # TODO: Once reports is server-ized, this call      # TODO: Once reports is server-ized, this call
# Line 204  class GRRun(GClientApp): Line 246  class GRRun(GClientApp):
246      #      #
247      try:      try:
248        GREngine(self.getConnectionManager()).processReport(reportfile,        GREngine(self.getConnectionManager()).processReport(reportfile,
249            destination = self.OPTIONS["destination"],            destination = destination,
250            destinationType = self.OPTIONS["destination_type"],            destinationType = destinationType,
251            destinationOptions = self.OPTIONS["destination_options"],            destinationOptions = destinationOptions,
252            filter = self.OPTIONS['filter'],            filter = filter,
253              batch = self.OPTIONS['batch'],
254            filterOptions = self.OPTIONS['filter_options'],            filterOptions = self.OPTIONS['filter_options'],
255            parameters=userParameters,            parameters=userParameters,
256            sortoption=sortoption,            sortoption=sortoption,
# Line 218  class GRRun(GClientApp): Line 261  class GRRun(GClientApp):
261      except GRExceptions.ReportUnreadable, msg:      except GRExceptions.ReportUnreadable, msg:
262        self.handleStartupError (msg)        self.handleStartupError (msg)
263    
264        sys.exit()
265    
266    #    #
267    # List filters available on the server    # List filters available on the server
268    #    #
269    def listFilters(self):    def listFilters(self, location):
   
     # TODO: um, implement??  
270    
271      self.printVersion()      self.printVersion()
272    
273      print "Available filters:"      reportInfo = self.getReportInformation(location)
274      print "  raw      [default] Do not process the XML with a filter. Emit raw XML."      namespace = reportInfo.getNamespace()
275    
276        filters = reportInfo.getFilters()
277        filters.sort()
278        filters.insert(0,('raw',{'description':'Do not process the XML with a filter. Emit raw XML.',
279                           'engine': 'raw' }))
280    
281        processed = []
282        maxlen = 0
283        for filter, properties in filters:
284          filter = filter.split(':')[-1]
285          maxlen = max(maxlen, len(filter))
286          try:
287            descr = properties['description']
288            if not len(descr):
289              raise KeyError
290          except KeyError:
291            descr = "%s output filter (no description available)" % filter
292          processed.append((filter, descr))
293    
294    
295    
296    
297        print 'Available filters for "%s" reports:' % namespace.split(':')[-1]
298        print
299        for filter, descr in processed:
300          print "  %s  %s" % (filter.ljust(maxlen+2), descr)
301      print      print
302    
303    
304      #
305      # Get a report's information
306      #
307      # TODO: This needs to support GNUe Reports Server
308      # TODO: when the time is right.
309      def getReportInformation(self, location):
310        return GRReportInfo(location)
311    
312    
313    
314  #  #
315  # This is a (temporary?) solution to getting a login  # Login handler for --batch mode
316  #  #
317  from gnue.common import GLoginHandler  from gnue.common import GLoginHandler
318  import getpass  class NoLoginHandler(GLoginHandler.LoginHandler):
 class LoginHandler(GLoginHandler.LoginHandler):  
319    
320    defaults = {'_username': None, '_password': None}    defaults = {'_username': None, '_password': None}
321    
322    def getLogin(self, loginData, error):    def getLogin(self, loginData, error):
323      try:      val = {}
324        quietprint ( "*"*60 )      for prompt in loginData[2]:
325        if len(loginData[1]):         if self.defaults.has_key(prompt[0])  and self.defaults[prompt[0]]:
326          quietprint ( 'Attempting to log into "%s" (%s):' % (loginData[1], loginData[0]) )           val[prompt[0]] = self.defaults[prompt[0]]
327        else:         else:
328          quietprint ( 'Attempting to log into %s:' % (loginData[0]) )           val[prompt[0]] = None
329        quietprint ("")      return val
       val = {}  
       for prompt in loginData[2]:  
          if self.defaults.has_key(prompt[0])  and self.defaults[prompt[0]]:  
            quietprint_nl ( "  %s: " % prompt[1] )  
            if prompt[2]:  
              quietprint ( "***" )  
            else:  
              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])  
       quietprint ("")  
       quietprint ("*"*60)  
       return val  
     except KeyboardInterrupt:  
       raise GLoginHandler.UserCanceledLogin  
   
330    
331    def destroyLoginDialog(self):    def destroyLoginDialog(self):
332      pass      pass
# Line 278  class LoginHandler(GLoginHandler.LoginHa Line 334  class LoginHandler(GLoginHandler.LoginHa
334  if __name__ == '__main__':  if __name__ == '__main__':
335    GRRun().run()    GRRun().run()
336    
   

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26