def evt_selected_dataset_text(self, datasetTuple, num_tag, genFrom):
        dataset, vers = datasetTuple
        datasetVersId = generateDatasetVersionId(datasetTuple)
        list_of_dataset_tabs = self.parent.parent.top_notebook.pagenames()
        tab_name = datasetVersId.replace("_", "-")
        dset = None
        if (
            self.parent.parent.main_frame.top_page_id2[self.parent.parent.main_frame.selected_top_page][num_tag].cget(
                "relief"
            )
            == "raised"
        ):
            if tab_name in list_of_dataset_tabs:
                self.parent.parent.top_notebook.selectpage(tab_name)
            else:
                self.parent.parent.main_frame.top_page_id2[self.parent.parent.main_frame.selected_top_page][
                    num_tag
                ].configure(bg=self.keycolor3, fg=self.keycolor2)

                from_tab = self.parent.parent.top_notebook.getcurselection()
                dset = Dataset.lookup(dataset, self.Session)
                if genFrom:
                    handler = self.parent.parent.handlerDictionary[dataset]
                else:
                    handler = getHandlerFromDataset(dset, self.Session)

                pub_editorviewer = self.parent.parent.create_publisher_editor_viewer(
                    self.parent.parent, tab_name, dataset, from_tab, self.Session
                )
                pub_editorviewer.dataset_page(dataset=dset, Session=self.Session, handler=handler)
                self.parent.parent.top_notebook.selectpage(tab_name)

                # Disable the "Data Publication" button
                self.parent.parent.pub_buttonexpansion.control_frame3.pack_forget()
                self.parent.parent.pub_buttonexpansion.control_toggle3 = 0
                self.parent.parent.pub_buttonexpansion.ControlButton3.configure(
                    image=self.parent.parent.pub_buttonexpansion.right, state="disabled"
                )
    def start_harvest(self, parent):
        from esgcet.publish import publishDatasetList
        from esgcet.model import Dataset, PUBLISH_FAILED_EVENT, ERROR_LEVEL

        dcolor1 = Pmw.Color.changebrightness(self.parent.parent, 'aliceblue',
                                             0.8)

        # Make sure the publisher is logged in
        # if not self.parent.parent.password_flg:
        #    self.parent.parent.menu.login_menu.evt_login( self.parent.parent )

        # Start the busy routine to indicate to the users something is happening
        self.parent.parent.busyCursor = 'watch'
        self.parent.parent.busyWidgets = [
            self.parent.parent.pane2.pane('EditPaneTop'),
            self.parent.parent.pane2.pane('EditPaneBottom'),
            self.parent.parent.pane2.pane('EditPaneStatus'),
            self.parent.parent.pane.pane('ControlPane')
        ]
        pub_busy.busyStart(self.parent.parent)
        try:
            # Generate the list of datasets to be published
            datasetNames = []
            GUI_line = {}
            tab_name = self.parent.parent.top_notebook.getcurselection()
            selected_page = self.parent.parent.main_frame.selected_top_page

            if (selected_page is None):
                warning(
                    "Must generate a list of datasets to scan before publishing can occur."
                )
                pub_busy.busyEnd(self.parent.parent)
                return

            for x in self.parent.parent.main_frame.top_page_id[selected_page]:

                if self.parent.parent.main_frame.top_page_id[selected_page][x].cget(
                        'bg'
                ) != 'salmon' and self.parent.parent.main_frame.top_page_id2[
                        selected_page][x].cget('bg') != 'salmon':
                    dset_name = self.parent.parent.main_frame.top_page_id2[
                        selected_page][x].cget('text')
                    #######################################
                    # ganz added this 1/18/11
                    versionNum = self.parent.parent.main_frame.version_label[
                        selected_page][x].cget('text')
                    dsetTuple = (dset_name, versionNum)
                    #dsetName = generateDatasetVersionId(dsetTuple)
                    #####################################################################################
                    # dsetTuple = parseDatasetVersionId(dset_name) # ganz no longer necessary
                    datasetNames.append(dsetTuple)
                    GUI_line[dset_name] = x
                else:
                    if self.parent.parent.main_frame.top_page_id2[
                            selected_page][x].cget('bg') == 'salmon':
                        self.parent.parent.main_frame.top_page_id[
                            selected_page][x].configure(relief='raised',
                                                        background='salmon',
                                                        image=self.off)

        # Publish collection of datasets
            testProgress = (self.parent.parent.statusbar.show, 0, 100)
            publishThredds = (quality_control_widgets.get_CheckBox3() == 1)
            publishGateway = (quality_control_widgets.get_CheckBox2() == 1)
            if (publishThredds):
                print 'publishing to Thredds'
            if (publishGateway):
                print 'publishing to Gateway'

            status_dict = publishDatasetList(datasetNames,
                                             self.Session,
                                             publish=publishGateway,
                                             thredds=publishThredds,
                                             progressCallback=testProgress)

            # Show the published status
            for x in status_dict.keys():
                status = status_dict[x]
                dsetName, versionNo = x
                dsetVersionName = generateDatasetVersionId(x)
                guiLine = GUI_line[dsetName]  # dsetVersionName]

                self.parent.parent.main_frame.status_label[selected_page][
                    guiLine].configure(
                        text=pub_controls.return_status_text(status))
                dset = Dataset.lookup(dsetName, self.Session)
                if dset.has_warnings(self.Session):
                    warningLevel = dset.get_max_warning_level(self.Session)
                    if warningLevel >= ERROR_LEVEL:
                        buttonColor = "pink"
                        buttonText = "Error"
                    else:
                        buttonColor = "yellow"
                        buttonText = "Warning"
                    self.parent.parent.main_frame.ok_err[selected_page][
                        guiLine].configure(
                            text=buttonText,
                            bg=buttonColor,
                            relief='raised',
                            command=pub_controls.Command(
                                self.parent.parent.pub_buttonexpansion.
                                extraction_widgets.error_extraction_button,
                                dset))
                else:
                    self.parent.parent.main_frame.ok_err[selected_page][
                        guiLine].configure(
                            text='Ok',
                            bg=dcolor1,
                            highlightcolor=dcolor1,
                            relief='sunken',
                        )
        except:
            pub_busy.busyEnd(
                self.parent.parent
            )  # catch here in order to turn off the busy cursor ganz
            raise
        finally:
            pub_busy.busyEnd(self.parent.parent)
            self.my_refresh()
    def show_extracted_info( self, datasets, dset_error, list_fields, versionObjs ):
      # set the color for each item in the row
      dcolor1 = Pmw.Color.changebrightness(self.parent.parent, 'aliceblue', 0.8 )
      dcolor2 = Pmw.Color.changebrightness(self.parent.parent, 'aliceblue', 0.7 )
      dcolor3 = Pmw.Color.changebrightness(self.parent.parent, 'aliceblue', 0.5 )
      dcolor4 = Pmw.Color.changebrightness(self.parent.parent, 'aliceblue', 0.6 )
      dcolor5 = Pmw.Color.changebrightness(self.parent.parent, 'aliceblue', 0.7 )
      dcolor6 = Pmw.Color.changebrightness(self.parent.parent, 'aliceblue', 0.8 )
      dcolor7 = Pmw.Color.changebrightness(self.parent.parent, 'aliceblue', 0.85 )

      selected_page = self.parent.parent.main_frame.selected_top_page
      dobj = {}
      
      
      
      for dset,versobj in zip(datasets,versionObjs):
          dobj[(dset.name,versobj.version)] = (dset,versobj)
          if dset.getVersion()==versobj.version:
              dobj[(dset.name,-1)] = (dset,versobj)
              
      #t_version = -1
      #for x in self.parent.parent.main_frame.top_page_id[selected_page]:
      #   dset_row = self.parent.parent.main_frame.top_page_id[selected_page][x].cget('text')
      #   dset_text = self.parent.parent.main_frame.top_page_id2[selected_page][x].cget('text')
      #   dsetName,dsetVers = parseDatasetVersionId(dset_text)
         
      #   if (dsetVers > t_version): 
      #           t_version = dsetVers
                 
      #print 'Highest version is %s' % t_version        
              
      for x in self.parent.parent.main_frame.top_page_id[selected_page]:
         dset_row = self.parent.parent.main_frame.top_page_id[selected_page][x].cget('text')
         dset_text = self.parent.parent.main_frame.top_page_id2[selected_page][x].cget('text')
         #if (self.parent.parent.main_frame.)
                    # ganz added this 1/21/11 NOT NEC
#         if (self.parent.parent.main_frame.version_label[selected_page] ):
#                    dsetName = self.parent.parent.main_frame.top_page_id2[selected_page][x].cget('text')               
#                    dsetVers = self.parent.parent.main_frame.version_label[selected_page][x].cget('text')                 
                  #####################################################################################               
#         else:
         dsetName,dsetVers = parseDatasetVersionId(dset_text)
         
         dsetId = (dsetName,dsetVers)
         if dsetId in dobj.keys():
            dset, versobj = dobj[dsetId]
            dsetVersionName = generateDatasetVersionId((dset.name, versobj.version))
            if self.parent.parent.main_frame.top_page_id[selected_page][x].cget('relief') == 'raised':
               frame = self.parent.parent.main_frame.add_row_frame[selected_page][x]
               if not dset.has_warnings(self.Session):
                  ok_err = Tkinter.Button( frame, text = 'Ok', bg = dcolor1, highlightcolor = dcolor1, width = 4, relief = 'sunken') #was 4
               else:
                  warningLevel = dset.get_max_warning_level(self.Session) 
                  if warningLevel>=ERROR_LEVEL:
                      buttonColor = "pink"
                      buttonText = "Error"
                  else:
                      buttonColor = "yellow"
                      buttonText = "Warning"
                  ok_err = Tkinter.Button( frame, 
                        text = buttonText,
                        bg = buttonColor,
                        width = 4, ## was 4 ganz
                        relief = 'raised',
                        command = pub_controls.Command( self.error_extraction_button,dset ) )
               #ok_err.grid(row = dset_row, column = 1, sticky = 'nsew') 
               #self.parent.parent.main_frame.ok_err[selected_page][x] = ok_err
 
               ok_err.grid(row = dset_row, column = 1, sticky = 'nsew') 
               self.parent.parent.main_frame.ok_err[selected_page][x] = ok_err 
 
   
               status = pollDatasetPublicationStatus(dset.get_name(self.Session), self.Session)
               status_text = pub_controls.return_status_text( status )
               self.parent.parent.main_frame.status_label[selected_page][x] = Tkinter.Label( frame, text = status_text, bg = dcolor1, width = 10, relief = 'sunken') # 4 was 10
               self.parent.parent.main_frame.status_label[selected_page][x].grid(row = dset_row, column = 2, sticky = 'nsew')
   
               if 'id' in list_fields:
                  id = Tkinter.Label( frame, text = `dset.id`, bg = dcolor2, width = 6, relief = 'sunken')
                  id.grid(row = dset_row, column = 3, sticky = 'nsew')
               
               #ganz adding rows here...need to add versions
      #dset.name, versobj.version
               ver_1 = versobj.version
               if (ver_1 ==-1):
                   ver_1 = "N/A"
                   # ganz TODO test this to see if this records the version 1/12/11
               
               
               """ Ganz: this code is a test to see if I can save the version label, 1/17/11
                 comment out the top code and insert the rest
               """
               #version = Tkinter.Label( frame, text = ver_1, bg = dcolor2, width = 6, relief = 'sunken')
               #version.grid(row = dset_row, column = 4, sticky = 'nsew')
               # width was 6 column = 4
               self.parent.parent.main_frame.version_label[selected_page][x] = Tkinter.Label( frame, text = ver_1, 
                                                                                              bg = dcolor2, width = 11, 
                                                                                              relief = 'sunken' )
               self.parent.parent.main_frame.version_label[selected_page][x].grid(row = dset_row, column = 4, sticky = 'nsew')
               """ end of test """
               
               #self.parent.parent.main_frame.version_label1[selected_page][x] = Tkinter.Label( frame, text = ver_1, bg = dcolor2, width = 6, relief = 'sunken')
               #self.parent.parent.main_frame.version_label1[selected_page][x].grid(row=dset_row,column = 4, columnspan=2, sticky = 'nsew')
         # create a menu
#               popup = Menu(version, tearoff=0)
#               popup.add_command(label="Show All Versions") # , command=next) etc...
#               popup.add_command(label="Show Latest Versions")
#               popup.add_separator()
#               popup.add_command(label="Home 3a")

#               def do_popupv1(event):
                # display the popup menu
#                    try:
#                        popup.tk_popup(event.x_root, event.y_root, 0)
#                    finally:
                    # make sure to release the grab (Tk 8.0a1 only)
#                        popup.grab_release()
                      


#               version.bind("<Button-3>", do_popupv1)

               self.parent.parent.main_frame.top_page_id2[selected_page][x].configure( width=71, relief='raised', bg = dcolor7, text=dset.name) #dsetVersionName)
               self.parent.parent.main_frame.top_page_id2[selected_page][x].grid(row=dset_row,column = 5, columnspan=2, sticky = 'nsew')
# ganz add this code to enable users to view all the files/dates and times within a dataset
         # create a menu
#               popup = Menu(ok_err, tearoff=0)
#               popup.add_command(label="Show All Files", command=pub_controls.Command( self.file_display_button,dset )) 

#               def do_popupv1(event):
                # display the popup menu
#                    try:
#                        popup.tk_popup(event.x_root, event.y_root, 0)
#                    finally:
                    # make sure to release the grab (Tk 8.0a1 only)
#                        popup.grab_release()
                      


#               self.parent.parent.main_frame.version_label[selected_page][x].bind("<Button-3>", self.evt_file_display_button)
                              
               
               

               if 'project' in list_fields:
                  project = Tkinter.Label( frame, text = dset.get_project(self.Session), bg = dcolor3, width = 20, relief = 'sunken', borderwidth = 2)
                  project.grid(row = dset_row, column = 7, sticky = 'nsew')
   
               if 'model' in list_fields:
                  model = Tkinter.Label( frame, text = dset.get_model(self.Session), bg = dcolor4, width = 20, relief = 'sunken', borderwidth = 2)
                  model.grid(row = dset_row, column = 8, sticky = 'nsew')
   
               if 'experiment' in list_fields:
                  experiment = Tkinter.Label( frame, text = dset.get_experiment(self.Session), bg = dcolor5, width = 20, relief = 'sunken', borderwidth = 2)
                  experiment.grid(row = dset_row, column = 9, sticky = 'nsew')
   
               if 'run_name' in list_fields:
                  run_name = Tkinter.Label( frame, text = dset.get_run_name(self.Session), bg = dcolor6, width = 20, relief = 'sunken', borderwidth = 2)
                  run_name.grid(row = dset_row, column = 10, sticky = 'nsew')
         else:
             
             #GANZ tested removed and replaced this 3/20/2011 
            
            frame = self.parent.parent.main_frame.add_row_frame[selected_page][x]
            ok_err = Tkinter.Button( frame, text = 'N/A', bg = 'salmon', highlightcolor = dcolor1, width = 4, relief = 'sunken') #was dcolor1
            ok_err.grid(row = dset_row, column = 1, sticky = 'nsew')

            status = Tkinter.Label( frame, text = 'N/A', bg = 'salmon', width = 10, relief = 'sunken')
            status.grid(row = dset_row, column = 2, sticky = 'nsew')

            id = Tkinter.Label( frame, text = 'N/A', bg = 'salmon', width = 6, relief = 'sunken')
            id.grid(row = dset_row, column = 3, sticky = 'nsew')
            
# test ganz 1/17/11
            #version = Tkinter.Label( frame, text = 'N/A', bg = dcolor2, width = 4, relief = 'sunken')
            #version.grid(row = dset_row, column = 4, sticky = 'nsew')
            # was dcolor2
            self.parent.parent.main_frame.version_label[selected_page][x] = Tkinter.Label( frame, text = 'N/A', bg = dcolor2, width = 4, relief = 'sunken')
            self.parent.parent.main_frame.version_label[selected_page][x].grid(row = dset_row, column = 4, sticky = 'nsew')
            # same test as above
            
            self.parent.parent.main_frame.top_page_id2[selected_page][x].configure( width=71, relief='sunken', bg = 'salmon', fg = 'black' )
            self.parent.parent.main_frame.top_page_id2[selected_page][x].grid(row=dset_row,column = 5, columnspan=2, sticky = 'nsew')
            
            
         x += 1
    def addQueryPageRow(self, num_tag, query_result, list_fields):

        # set the color for each item in the row
        dcolor1 = Pmw.Color.changebrightness(self.parent.parent, "aliceblue", 0.8)
        dcolor2 = Pmw.Color.changebrightness(self.parent.parent, "aliceblue", 0.7)
        dcolor3 = Pmw.Color.changebrightness(self.parent.parent, "aliceblue", 0.5)
        dcolor4 = Pmw.Color.changebrightness(self.parent.parent, "aliceblue", 0.6)
        dcolor5 = Pmw.Color.changebrightness(self.parent.parent, "aliceblue", 0.7)
        dcolor6 = Pmw.Color.changebrightness(self.parent.parent, "aliceblue", 0.8)
        dcolor7 = Pmw.Color.changebrightness(self.parent.parent, "aliceblue", 0.9)

        frame_ct = self.parent.parent.top_ct
        labelFont = tkFont.Font(
            self.parent.parent, family=pub_controls.collection_font_type, size=pub_controls.collection_font_size
        )
        self.add_row_frame[num_tag] = self.pageFrame[frame_ct].interior()

        self.select_button[num_tag] = Tkinter.Button(
            self.add_row_frame[num_tag],
            #                compound = Tkinter.LEFT,
            #                justify = Tkinter.LEFT,
            #                anchor = Tkinter.W,
            text=num_tag,
            #                font = labelFont,
            image=self.on,
            bg=self.keycolor1,
            relief="raised",
            #                width = 70,
            height=1,
            command=pub_controls.Command(self.evt_selected_dataset, num_tag),
        )
        self.select_button[num_tag].image = self.on  # save the image from garbage collection
        self.select_button[num_tag].grid(row=self.row, column=0, sticky="nsew")

        dset = Dataset.lookup(query_result[1], self.Session)
        if dset.has_warnings(self.Session):
            warningLevel = dset.get_max_warning_level(self.Session)
            if warningLevel >= ERROR_LEVEL:
                buttonColor = "pink"
                buttonText = "Error"
            else:
                buttonColor = "yellow"
                buttonText = "Warning"
            self.ok_err[num_tag] = Tkinter.Button(
                self.add_row_frame[num_tag],
                text=buttonText,
                bg=buttonColor,
                width=4,
                relief="raised",
                command=pub_controls.Command(
                    self.parent.parent.pub_buttonexpansion.extraction_widgets.error_extraction_button, dset
                ),
            )
            self.ok_err[num_tag].grid(row=self.row, column=1, sticky="nsew")
        else:
            self.ok_err[num_tag] = Tkinter.Button(
                self.add_row_frame[num_tag], text="Ok", bg=dcolor1, highlightcolor=dcolor1, width=4, relief="sunken"
            )
            self.ok_err[num_tag].grid(row=self.row, column=1, sticky="nsew")

        status = pollDatasetPublicationStatus(query_result[1], self.Session)
        status_text = pub_controls.return_status_text(status)
        self.status[num_tag] = Tkinter.Label(
            self.add_row_frame[num_tag], text=status_text, bg=dcolor1, highlightcolor=dcolor1, width=10, relief="sunken"
        )
        self.status[num_tag].grid(row=self.row, column=2, sticky="nsew")

        if "id" in list_fields:
            id = Tkinter.Label(self.add_row_frame[num_tag], text=query_result[0], bg=dcolor2, width=6, relief="sunken")
            id.grid(row=self.row, column=3, sticky="nsew")

        dsetName = query_result[1]
        versionNum = -1
        try:
            versionIndex = list_fields.index("version")
            versionNum = string.atoi(query_result[versionIndex])
        except:
            pass

        dsetTuple = (dsetName, versionNum)
        dsetName = generateDatasetVersionId(dsetTuple)
        # ganz adding rows here...need to add versions
        datasetName = dsetTuple[0]  # dataset[0]  #parseDatasetVersionId(dataset)
        versionno = dsetTuple[1]  # dataset[1]

        ver_1 = versionno
        if ver_1 == -1:
            ver_1 = "N/A"

        self.select_labelV[num_tag] = Tkinter.Label(
            self.add_row_frame[num_tag], text=ver_1, bg=dcolor2, width=11, relief="sunken"
        )
        self.select_labelV[num_tag].grid(row=self.row, column=4, sticky="nsew")

        self.select_label[num_tag] = Tkinter.Button(
            self.add_row_frame[num_tag],
            text=datasetName,  # dsetName,
            font=labelFont,
            bg=self.keycolor2,
            relief="raised",
            borderwidth=2,
            anchor="w",
            justify="left",
            width=71,
            command=pub_controls.Command(self.evt_selected_dataset_text, dsetTuple, num_tag, 0),
        )
        self.select_label[num_tag].grid(row=self.row, column=5, columnspan=2, sticky="nsew")

        if "project" in list_fields:
            project = Tkinter.Label(
                self.add_row_frame[num_tag], text=query_result[2], bg=dcolor3, width=20, relief="sunken", borderwidth=2
            )
            project.grid(row=self.row, column=7, sticky="nsew")

        if "model" in list_fields:
            model = Tkinter.Label(
                self.add_row_frame[num_tag], text=query_result[3], bg=dcolor4, width=20, relief="sunken", borderwidth=2
            )
            model.grid(row=self.row, column=8, sticky="nsew")

        if "experiment" in list_fields:
            experiment = Tkinter.Label(
                self.add_row_frame[num_tag], text=query_result[4], bg=dcolor5, width=20, relief="sunken", borderwidth=2
            )
            experiment.grid(row=self.row, column=9, sticky="nsew")

        if "run_name" in list_fields:
            run_name = Tkinter.Label(
                self.add_row_frame[num_tag], text=query_result[5], bg=dcolor6, width=20, relief="sunken", borderwidth=2
            )
            run_name.grid(row=self.row, column=10, sticky="nsew")

        self.add_row_frame[num_tag].grid_rowconfigure(self.row, weight=1)
        self.add_row_frame[num_tag].grid_columnconfigure(1, weight=1)
        if (
            self.pageFrame[frame_ct].cget("horizflex") == "expand"
            or self.pageFrame[frame_ct].cget("vertflex") == "expand"
        ):
            self.pageFrame[frame_ct].reposition()

        self.row = self.row + 1  # increment to the next dataset row
Example #5
0
def main(argv):

    try:
        args, lastargs = getopt.getopt(argv, "hi:", [
            'database-delete', 'database-only', 'echo-sql', 'map=',
            'no-republish', 'no-thredds-reinit', 'skip-gateway', 'skip-index',
            'las', 'log=', 'rest-api', 'skip-thredds', 'sync-thredds',
            'use-list='
        ])
    except getopt.error:
        print sys.exc_value
        return

    deleteAll = False
    datasetMap = None
    deleteDset = False
    unpublishOnGateway = False
    echoSql = False
    init_file = None
    gatewayOp = DELETE
    las = False
    log_filename = None
    republish = True
    restApi = None
    thredds = True
    syncThredds = False
    useList = False
    threddsReinit = True
    for flag, arg in args:
        if flag == '--database-delete':
            deleteDset = True
        elif flag == '--database-only':
            gatewayOp = NO_OPERATION
            thredds = False
            deleteDset = True
        elif flag == '--echo-sql':
            echoSql = True
        elif flag in ['-h', '--help']:
            return
        elif flag == '-i':
            init_file = arg
        elif flag == '--map':
            datasetMap = readDatasetMap(arg)
        elif flag == '--skip-gateway':
            gatewayOp = NO_OPERATION
        elif flag == '--skip-index':
            gatewayOp = NO_OPERATION
        elif flag == '--las':
            las = True
        elif flag == '--log':
            log_filename = arg
        elif flag == '--no-republish':
            republish = False
        elif flag == '--no-thredds-reinit':
            threddsReinit = False
        elif flag == '--rest-api':
            restApi = True
        elif flag == '--skip-thredds':
            thredds = False
        elif flag == '--sync-thredds':
            syncThredds = True
        elif flag == '--use-list':
            useList = True
            useListPath = arg

    if gatewayOp != NO_OPERATION and unpublishOnGateway:
        gatewayOp = UNPUBLISH

    # Load the configuration and set up a database connection
    config = loadConfig(init_file)
    engine = create_engine(config.getdburl('extract'),
                           echo=echoSql,
                           pool_recycle=3600)
    initLogging('extract', override_sa=engine, log_filename=log_filename)
    Session = sessionmaker(bind=engine, autoflush=True, autocommit=False)

    if config is None:
        raise ESGPublishError("No configuration file found.")
    threddsRoot = config.get('DEFAULT', 'thredds_root')

    # Get the default publication interface (REST or Hessian)
    if restApi is None:
        restApi = config.getboolean('DEFAULT', 'use_rest_api', default=False)

    if datasetMap is None:
        if not useList:
            datasetNames = [parseDatasetVersionId(item) for item in lastargs]
        else:
            if useListPath == '-':
                namelist = sys.stdin
            else:
                namelist = open(useListPath)
            datasetNames = []
            for line in namelist.readlines():
                versionId = parseDatasetVersionId(line.strip())
                datasetNames.append(versionId)
    else:
        datasetNames = datasetMap.keys()
        datasetNames.sort()
    result = deleteDatasetList(datasetNames,
                               Session,
                               gatewayOp,
                               thredds,
                               las,
                               deleteDset,
                               deleteAll=deleteAll,
                               republish=republish,
                               reinitThredds=threddsReinit,
                               restInterface=restApi)

    # Republish previous versions as needed. This will happen if the latest version
    # was deleted from the database, and is not
    # the only version. In this case the previous version will be rescanned to generate the aggregations.
    if republish:
        statusDict, republishList = result
        if len(republishList) > 0:

            # Register project handlers.
            registerHandlers()

            info("Republishing modified datasets:")
            republishDatasetNames = [
                generateDatasetVersionId(dsetTuple)
                for dsetTuple in republishList
            ]
            dmap, offline = queryDatasetMap(republishDatasetNames, Session)
            datasetNames = dmap.keys()
            datasets = iterateOverDatasets(None,
                                           dmap,
                                           None,
                                           republishList,
                                           Session,
                                           "time",
                                           UPDATE_OP,
                                           None, {},
                                           offline, {},
                                           forceAggregate=True)
            republishOp = (gatewayOp != NO_OPERATION
                           )  # Don't republish if skipping the gateway op
            result = publishDatasetList(datasetNames,
                                        Session,
                                        publish=republishOp,
                                        thredds=thredds)

    # Synchronize database and THREDDS catalogs
    if syncThredds:
        threddsRoot = config.get('DEFAULT', 'thredds_root')

        # Make a dictionary of catalogs from the database
        session = Session()
        subcatalogs = session.query(Catalog).select_from(
            join(Catalog, Dataset,
                 Catalog.dataset_name == Dataset.name)).all()
        catdict = {}
        for catalog in subcatalogs:
            location = os.path.join(threddsRoot, catalog.location)
            catdict[location] = 1
        session.close()

        # Scan all XML files in the threddsroot
        os.path.walk(threddsRoot, cleanupCatalogs, catdict)
    def start_harvest( self, parent ):
        from esgcet.publish import publishDatasetList
        from esgcet.model import Dataset, PUBLISH_FAILED_EVENT, ERROR_LEVEL

        dcolor1 = Pmw.Color.changebrightness(self.parent.parent, 'aliceblue', 0.8 )

        # Make sure the publisher is logged in
       # if not self.parent.parent.password_flg:
       #    self.parent.parent.menu.login_menu.evt_login( self.parent.parent )

        # Start the busy routine to indicate to the users something is happening
        self.parent.parent.busyCursor = 'watch'
        self.parent.parent.busyWidgets = [self.parent.parent.pane2.pane( 'EditPaneTop' ), self.parent.parent.pane2.pane( 'EditPaneBottom' ), self.parent.parent.pane2.pane( 'EditPaneStatus' ), self.parent.parent.pane.pane( 'ControlPane' )]
        pub_busy.busyStart( self.parent.parent )
        try:
        # Generate the list of datasets to be published
           datasetNames=[]
           GUI_line = {}
           tab_name = self.parent.parent.top_notebook.getcurselection()
           selected_page = self.parent.parent.main_frame.selected_top_page

           if (selected_page is None):
              warning("Must generate a list of datasets to scan before publishing can occur.")
              pub_busy.busyEnd( self.parent.parent )
              return

           for x in self.parent.parent.main_frame.top_page_id[selected_page]:

               if self.parent.parent.main_frame.top_page_id[selected_page][x].cget('bg') != 'salmon' and self.parent.parent.main_frame.top_page_id2[selected_page][x].cget('bg') != 'salmon':
                   dset_name = self.parent.parent.main_frame.top_page_id2[selected_page][x].cget('text')
                #######################################
                                  # ganz added this 1/18/11    
                   versionNum = self.parent.parent.main_frame.version_label[selected_page][x].cget('text') 
                   dsetTuple = (dset_name, versionNum)
                #dsetName = generateDatasetVersionId(dsetTuple)                
                  #####################################################################################
                # dsetTuple = parseDatasetVersionId(dset_name) # ganz no longer necessary
                   datasetNames.append(dsetTuple)
                   GUI_line[ dset_name ] = x
               else:
                   if self.parent.parent.main_frame.top_page_id2[selected_page][x].cget('bg') == 'salmon':
                      self.parent.parent.main_frame.top_page_id[selected_page][x].configure(relief = 'raised', background = 'salmon', image = self.off)

        # Publish collection of datasets
           testProgress = (self.parent.parent.statusbar.show, 0, 100)
           publishThredds = (quality_control_widgets.get_CheckBox3()==1)
           publishGateway = (quality_control_widgets.get_CheckBox2()==1)
           if (publishThredds):
               print 'publishing to Thredds'
           if (publishGateway):
               print 'publishing to Gateway'  
                      
           status_dict = publishDatasetList(datasetNames, self.Session, publish=publishGateway, thredds=publishThredds, progressCallback=testProgress)

        # Show the published status
           for x in status_dict.keys():
                status = status_dict[ x ]
                dsetName, versionNo = x
                dsetVersionName = generateDatasetVersionId(x)
                guiLine = GUI_line[dsetName] # dsetVersionName]
            
                self.parent.parent.main_frame.status_label[selected_page][guiLine].configure(text=pub_controls.return_status_text( status) )
                dset = Dataset.lookup(dsetName, self.Session)
                if dset.has_warnings(self.Session):
                    warningLevel = dset.get_max_warning_level(self.Session)
                    if warningLevel>=ERROR_LEVEL:
                        buttonColor = "pink"
                        buttonText = "Error"
                    else:
                        buttonColor = "yellow"
                        buttonText = "Warning"
                    self.parent.parent.main_frame.ok_err[selected_page][guiLine].configure(
                        text = buttonText,
                        bg = buttonColor,
                        relief = 'raised',
                        command = pub_controls.Command( self.parent.parent.pub_buttonexpansion.extraction_widgets.error_extraction_button, dset ) )
                else:
                    self.parent.parent.main_frame.ok_err[selected_page][guiLine].configure(
                        text = 'Ok',
                        bg = dcolor1,
                        highlightcolor = dcolor1,
                        relief = 'sunken',
                        )
        except:
            pub_busy.busyEnd( self.parent.parent )  # catch here in order to turn off the busy cursor ganz
            raise
        finally:
           pub_busy.busyEnd( self.parent.parent )
           self.my_refresh()