Esempio n. 1
0
def main():
   #------------------------------------------------------------------------------
   # We are using the same gui_support as VCDAT for possible future integration 
   #------------------------------------------------------------------------------
   root = gui_support.root()
   Pmw.initialise( root )

   #----------------------------------------------------------------------------
   # One time only call to setup the database session 
   #----------------------------------------------------------------------------
   root.echoSql = False
   extraction_controls.call_sessionmaker( root )

   #----------------------------------------------------------------------------
   # Initialize the GUI widgets
   #----------------------------------------------------------------------------
   root.main_frame = GUI_frame( root )

   #------------------------------------------------------------------------------
   # Display the ESG-CET world image in the background and the copyright
   #------------------------------------------------------------------------------
   root.canvas = Tkinter.Frame(root.pane2.pane( 'EditPaneTop' ))
   root.canvas.pack(side='top', fill='both', expand=1)

   txtFont = tkFont.Font(root, family = pub_controls.tab_font_type, size=pub_controls.tab_font_size)
   copywrite_text = "\nPublisher software version %s @ copyright LLNL/PCMDI\nEarth System Grid Center for Enabling Technologies, funded by the U.S. Department of Energy" % root.Version
   root.text = Tkinter.Label(root.canvas, text=copywrite_text, font=txtFont, bg = "white")
   root.text.pack(side='top', fill='both', expand=1)

   img = Tkinter.PhotoImage( file = esg_bg )
   root.canvas_img = Tkinter.Label( root.canvas, image = img, background = "white")
   root.canvas_img.image = img
   root.canvas_img.pack(side='top', fill='both', expand=1)

   #------------------------------------------------------------------------------
   # Redirect stderr and stdout to the output windows located in the bottom_right
   # pane (i.e., "Output" and "Error")
   # 
   # INFO messages are sent to the "Output" window -- that is, stdout
   #
   # WARNING, ERROR, DEBUG, CRITICAL, and Exception messages are sent to
   # the "Error" window -- that is, stderr
   #
   # Note: we distinguish between what is standard out and standard error,
   #       then display the appropriate window to view the text       
   #------------------------------------------------------------------------------
   sys.stdout = pub_controls.standard_out( root )
   sys.stderr = pub_controls.standard_err( root )

   #----------------------------------------------------------------------------
   # Log INFO messages to stdout and display the output to the "Output" window
   #----------------------------------------------------------------------------
   inf=logging.StreamHandler(sys.stdout)
   inf.setLevel(logging.INFO)
   logging.getLogger('Info').addHandler(inf)

   #----------------------------------------------------------------------------
   # Log WARNING messages to stderr and display the output to the "Error" window
   #----------------------------------------------------------------------------
   wrn=logging.StreamHandler(sys.stderr)
   wrn.setLevel(logging.WARNING)
   logging.getLogger('Warning').addHandler(wrn)

   #----------------------------------------------------------------------------
   # Log ERROR messages to stderr and display the output to the "Error" window
   #----------------------------------------------------------------------------
   err=logging.StreamHandler(sys.stderr)
   err.setLevel(logging.ERROR)
   logging.getLogger('Error').addHandler(err)

   #----------------------------------------------------------------------------
   # Log DEBUG messages to stderr and display the output to the "Error" window
   #----------------------------------------------------------------------------
   dbg=logging.StreamHandler(sys.stderr)
   dbg.setLevel(logging.DEBUG)
   logging.getLogger('Debug').addHandler(dbg)

   #----------------------------------------------------------------------------
   # Log CRITICAL messages to stderr and display the output to the "Error" window
   #----------------------------------------------------------------------------
   crt=logging.StreamHandler(sys.stderr)
   crt.setLevel(logging.CRITICAL)
   logging.getLogger('Critical').addHandler(crt)

   #----------------------------------------------------------------------------
   # Log Exception messages to stderr and display the output to the "Error" window
   #----------------------------------------------------------------------------
   exc=logging.StreamHandler(sys.stderr)
   exc.setLevel(logging.ERROR)
   logging.getLogger('Exception').addHandler(exc)

   #----------------------------------------------------------------------------
   # Test the message print commands from logging --- the below lines are
   # showing examples of how to use Python logging for message sending
   #----------------------------------------------------------------------------
   #debug("%d: This is the Debug Test" % logging.DEBUG)
   #info("%d: This is the Info Test" % logging.INFO)
   #warning("%d: This is Warning Test" % logging.WARNING)
   #error("%d: This is the Error Test" % logging.ERROR)
   #critical("%d: This is the Critical Test" % logging.CRITICAL)
   #exception("%d: This is the Exception (NotSet) Test" % logging.NOTSET)

   #---------------------------------------------------------------------
   # View the GUI on the screen.
   #---------------------------------------------------------------------
   root.deiconify()
   root.update()
   root.lift()

   #---------------------------------------------------------------------
   # Enter the Tkinter main event loop
   #---------------------------------------------------------------------
   root.mainloop()
    def return_content2(self, appendOpt=False):
        from esgcet.publish import iterateOverDatasets, processIterator
        from esgcet.config import getHandlerByName
        from esgcet.model import eventName
        from esgcet.config import loadConfig

        # Initialize parameters for interating over datasets
        initcontext = {}
        aggregateOnly = False
        # appendOpt = False
        initcontext = {}
        properties = {}
        publish = False
        publishOnly = False
        thredds = False
        testProgress1 = [self.parent.parent.statusbar.show, 0, 50]
        testProgress2 = [self.parent.parent.statusbar.show, 50, 100]
        handlerDictionary = {}

        # Get the currently selected tab and the selected datasets
        tab_name = self.parent.parent.top_notebook.getcurselection()
        selected_page = self.parent.parent.main_frame.selected_top_page
        datasetNames = []
       # datasetNames2 = []
        if (selected_page is None):
           warning("Must generate a list of datasets to scan before data extraction can occur.")
           return

        if (selected_page is not None) or (self.parent.parent.hold_offline[selected_page] == True):
           extraFields = None 
           if (self.parent.parent.hold_offline[selected_page] == False) or (isinstance(self.parent.parent.hold_offline[selected_page], types.DictType)):
              for x in self.parent.parent.main_frame.top_page_id[selected_page]:
                dsetVersionName = self.parent.parent.main_frame.top_page_id2[selected_page][x].cget('text') # GANZ TODO version_label
                
                   # ganz added this 1/21/11
                if (self.parent.parent.main_frame.version_label[selected_page] ):
                    dset_name = self.parent.parent.main_frame.top_page_id2[selected_page][x].cget('text')               
                    dsetVersion = self.parent.parent.main_frame.version_label[selected_page][x].cget('text')                 
                  #####################################################################################               
                else:
                    dset_name, dsetVersion = parseDatasetVersionId(dsetVersionName)

                # Retrieve all the datasets in the collection for display
                """ ganz test code
                status = pollDatasetPublicationStatus(dset_name, self.Session)
                status_text = pub_controls.return_status_text( status )
                if status_text != 'Error':
                   dsetTuple = parseDatasetVersionId(self.parent.parent.main_frame.top_page_id2[selected_page][x].cget('text'))
                   datasetNames2.append(dsetTuple)
                """
                # Retrieve only the datasets that have been selected
                if self.parent.parent.main_frame.top_page_id[selected_page][x].cget('bg') != 'salmon':
                   dsetTuple =  parseDatasetVersionId(self.parent.parent.main_frame.top_page_id2[selected_page][x].cget('text'))
                   datasetNames.append(dsetTuple)

              dmap = self.parent.parent.main_frame.dmap[selected_page]
              extraFields = self.parent.parent.main_frame.extraFields[selected_page]
              datasetMapfile = self.parent.parent.main_frame.datasetMapfile[selected_page]
              projectName = self.parent.parent.main_frame.projectName[selected_page]
              directoryMap = self.parent.parent.directoryMap[selected_page]

              if dmap is not None:
                 for x in datasetNames:
                    dsetId = x[0] 
                    datasetName = x
                    try:
                        dmapentry = dmap[datasetName]
                    except:

                        # Check if the dataset map key was changed from (dsetname,-1) to (dsetname,version).
                        # If so, replace the entry with the new key.
                        trykey = (datasetName[0], -1)
                        dmapentry = dmap[trykey]
                        del dmap[trykey]
                        dmap[datasetName] = dmapentry
                    firstFile = dmapentry[0][0]
  
                    self.parent.parent.handlerDictionary[dsetId] = getHandlerByName(projectName, firstFile, self.Session)
                    handler = self.parent.parent.handlerDictionary[dsetId]
                 # Copy the defaultGlobalValues into initcontext
                 initcontext = self.parent.parent.main_frame.defaultGlobalValues[selected_page]
              else:
                  # more test code
                 myholdDirectoryMap = self.parent.parent.directoryMap[selected_page] 
                 #mydatasetNames = [(item,-1) for item in myholdDirectoryMap.keys()]
                 mydatasetNames = [(item) for item in myholdDirectoryMap.keys()]
                 #end
                 for x in mydatasetNames:
                    dsetId = x[0] 
                    datasetName = x
                    # ganz this is test code
                    try:
                        dmapentry = myholdDirectoryMap[datasetName]
                    except:

                        # Check if the dataset map key was changed from (dsetname,-1) to (dsetname,version).
                        # If so, replace the entry with the new key.
                        
                        trykey = (datasetName[0], -1)
                        dmapentry = myholdDirectoryMap[trykey]
                        del myholdDirectoryMap[trykey]
                        myholdDirectoryMap[datasetName] = dmapentry
                        
                    firstFile = dmapentry[0][1]
                    #end of test code
                    
                    #firstFile = self.parent.parent.main_frame.dirp_firstfile[selected_page]
 
                    self.parent.parent.handlerDictionary[dsetId] = getHandlerByName(projectName, firstFile, self.Session)
                    handler = self.parent.parent.handlerDictionary[dsetId]
           else:      # working off-line
              projectName = self.parent.parent.main_frame.projectName[selected_page]
              if self.parent.parent.offline_file_directory[selected_page] == "directory":
                 if self.parent.parent.config is None:
                    extraction_controls.call_sessionmaker( self.parent.parent )
                 datasetPaths = []
                 dmap = {self.parent.parent.offline_datasetName : datasetPaths}
                 listerSection = getOfflineLister(self.parent.parent.config, "project:%s"%projectName, None)
                 offlineLister = self.parent.parent.config.get(listerSection, 'offline_lister_executable')
                 lastargs = self.parent.parent.offline_directories
                 commandArgs = "--config-section %s "%listerSection
                 commandArgs += " ".join(lastargs)
                 for filepath, size in processIterator(offlineLister, commandArgs, filefilt=self.parent.parent.filefilt):
                   datasetPaths.append((filepath, str(size)))
                 datasetNames = self.parent.parent.datasetNames
                 directoryMap = None

                 # get the handler
                 for x in datasetNames:
                    dsetId = x[0] 
                    self.parent.parent.handlerDictionary[dsetId] = getHandlerByName(projectName, None, self.Session, offline=True)

              elif self.parent.parent.offline_file_directory[selected_page] == "file":
                 dmap = self.parent.parent.main_frame.dmap[selected_page]
                 extraFields = self.parent.parent.main_frame.extraFields[selected_page]
                 datasetMapfile = self.parent.parent.main_frame.datasetMapfile[selected_page]
                 projectName = self.parent.parent.main_frame.projectName[selected_page]
                 directoryMap = None
                 if datasetMapfile is not None:
                     dmap, extraFields = readDatasetMap(datasetMapfile, parse_extra_fields=True)
                     datasetNames = dmap.keys()

                 # get the handlers
                 for x in datasetNames:
                    dsetId = x[0] 
                    self.parent.parent.handlerDictionary[dsetId] = getHandlerByName(projectName, None, self.Session, offline=True)


           # Iterate over datasets
           if appendOpt:
               operation = UPDATE_OP
           else:
               operation = CREATE_OP
        
           datasets = iterateOverDatasets(projectName, dmap, directoryMap, datasetNames, self.Session, self.parent.parent.aggregateDimension, operation, self.parent.parent.filefilt, initcontext, self.parent.parent.hold_offline[selected_page], properties, comment=self.comments, testProgress1=testProgress1, testProgress2=testProgress2 , handlerDictionary=self.parent.parent.handlerDictionary, extraFields=extraFields, readFiles=True)

           # If working on-line then replace the scanned list of datasets with 
           # the complete list of datasets
           #test
           """
           print 'datasetNames:'
           for t1 in datasetNames:
               print t1
           print 'datasetNames2:'    
           for t2 in datasetNames2:
               print t2
           """   
           if not self.parent.parent.hold_offline[selected_page]:
              datasets = []
              versionObjs = []
              # ganz finally, tested datasetNames2 here
              for dsetName, version in datasetNames:
                  result = Dataset.lookup(dsetName, self.Session, version=version)
                  if result is not None:
                      entry, versionObj = result
                      datasets.append(entry)
                      versionObjs.append(versionObj)

           # Get the summary of errors after doing a data extraction
           dset_error = []
           for dset in datasets:
               status = dset.get_publication_status(self.Session)
               status_name = eventName[status]
               if dset.has_warnings(self.Session):
                   dset_error.append(dset.get_name(self.Session))

           try:
              list_fields = getQueryFields( handler )
           except:
              handler = getHandlerByName(projectName, None, self.Session)
              list_fields = getQueryFields( handler )

           # Display the datasets in the "Collection" page
#           if self.parent.parent.hold_offline[selected_page] == True:
#              tab_name = "Collection_Offline"
#              from_tab = "Collection"
#              pub_editorviewer = self.parent.parent.create_publisher_editor_viewer( self.parent.parent, tab_name, dataset, from_tab, self.Session)

           # Show the extracted datasets
           self.set_column_labels( len(datasets), list_fields )
           self.show_extracted_info(datasets, dset_error, list_fields, versionObjs)

        # Enable the "Data Publication" button
        self.parent.ControlButton3.configure( state = 'normal' )
def main():
    #------------------------------------------------------------------------------
    # We are using the same gui_support as VCDAT for possible future integration
    #------------------------------------------------------------------------------
    root = gui_support.root()
    Pmw.initialise(root)

    #----------------------------------------------------------------------------
    # One time only call to setup the database session
    #----------------------------------------------------------------------------
    root.echoSql = False
    extraction_controls.call_sessionmaker(root)

    #----------------------------------------------------------------------------
    # Initialize the GUI widgets
    #----------------------------------------------------------------------------
    root.main_frame = GUI_frame(root)

    #------------------------------------------------------------------------------
    # Display the ESG-CET world image in the background and the copyright
    #------------------------------------------------------------------------------
    root.canvas = Tkinter.Frame(root.pane2.pane('EditPaneTop'))
    root.canvas.pack(side='top', fill='both', expand=1)

    txtFont = tkFont.Font(root,
                          family=pub_controls.tab_font_type,
                          size=pub_controls.tab_font_size)
    copywrite_text = "\nPublisher software version %s @ copyright LLNL/PCMDI\nEarth System Grid Center for Enabling Technologies, funded by the U.S. Department of Energy" % root.Version
    root.text = Tkinter.Label(root.canvas,
                              text=copywrite_text,
                              font=txtFont,
                              bg="white")
    root.text.pack(side='top', fill='both', expand=1)

    img = Tkinter.PhotoImage(file=esg_bg)
    root.canvas_img = Tkinter.Label(root.canvas, image=img, background="white")
    root.canvas_img.image = img
    root.canvas_img.pack(side='top', fill='both', expand=1)

    #------------------------------------------------------------------------------
    # Redirect stderr and stdout to the output windows located in the bottom_right
    # pane (i.e., "Output" and "Error")
    #
    # INFO messages are sent to the "Output" window -- that is, stdout
    #
    # WARNING, ERROR, DEBUG, CRITICAL, and Exception messages are sent to
    # the "Error" window -- that is, stderr
    #
    # Note: we distinguish between what is standard out and standard error,
    #       then display the appropriate window to view the text
    #------------------------------------------------------------------------------
    sys.stdout = pub_controls.standard_out(root)
    sys.stderr = pub_controls.standard_err(root)

    #----------------------------------------------------------------------------
    # Log INFO messages to stdout and display the output to the "Output" window
    #----------------------------------------------------------------------------
    inf = logging.StreamHandler(sys.stdout)
    inf.setLevel(logging.INFO)
    logging.getLogger('Info').addHandler(inf)

    #----------------------------------------------------------------------------
    # Log WARNING messages to stderr and display the output to the "Error" window
    #----------------------------------------------------------------------------
    wrn = logging.StreamHandler(sys.stderr)
    wrn.setLevel(logging.WARNING)
    logging.getLogger('Warning').addHandler(wrn)

    #----------------------------------------------------------------------------
    # Log ERROR messages to stderr and display the output to the "Error" window
    #----------------------------------------------------------------------------
    err = logging.StreamHandler(sys.stderr)
    err.setLevel(logging.ERROR)
    logging.getLogger('Error').addHandler(err)

    #----------------------------------------------------------------------------
    # Log DEBUG messages to stderr and display the output to the "Error" window
    #----------------------------------------------------------------------------
    dbg = logging.StreamHandler(sys.stderr)
    dbg.setLevel(logging.DEBUG)
    logging.getLogger('Debug').addHandler(dbg)

    #----------------------------------------------------------------------------
    # Log CRITICAL messages to stderr and display the output to the "Error" window
    #----------------------------------------------------------------------------
    crt = logging.StreamHandler(sys.stderr)
    crt.setLevel(logging.CRITICAL)
    logging.getLogger('Critical').addHandler(crt)

    #----------------------------------------------------------------------------
    # Log Exception messages to stderr and display the output to the "Error" window
    #----------------------------------------------------------------------------
    exc = logging.StreamHandler(sys.stderr)
    exc.setLevel(logging.ERROR)
    logging.getLogger('Exception').addHandler(exc)

    #----------------------------------------------------------------------------
    # Test the message print commands from logging --- the below lines are
    # showing examples of how to use Python logging for message sending
    #----------------------------------------------------------------------------
    #debug("%d: This is the Debug Test" % logging.DEBUG)
    #info("%d: This is the Info Test" % logging.INFO)
    #warning("%d: This is Warning Test" % logging.WARNING)
    #error("%d: This is the Error Test" % logging.ERROR)
    #critical("%d: This is the Critical Test" % logging.CRITICAL)
    #exception("%d: This is the Exception (NotSet) Test" % logging.NOTSET)

    #---------------------------------------------------------------------
    # View the GUI on the screen.
    #---------------------------------------------------------------------
    root.deiconify()
    root.update()
    root.lift()

    #---------------------------------------------------------------------
    # Enter the Tkinter main event loop
    #---------------------------------------------------------------------
    root.mainloop()