Beispiel #1
0
    def initializeFields(self, Session):
        """Initialize field names and options based on the configuration file."""
        from esgcet.model import Model, Experiment

        config = getConfig()
        projectSection = "project:" + self.name
        categoryOption = config.get(projectSection, "categories")
        categorySpecs = splitRecord(categoryOption)
        for category, categoryTypeS, isMandatoryS, isThreddsPropertyS, displayOrderS in categorySpecs:
            categoryType = getCategoryType(categoryTypeS)
            isMandatory = getBoolean(isMandatoryS)
            isThreddsProperty = getBoolean(isThreddsPropertyS)
            displayOrder = string.atoi(displayOrderS)
            self.fieldNames[category] = (categoryType, isMandatory, isThreddsProperty, displayOrder)

        categoryDefaultsOption = config.get(projectSection, "category_defaults", default=None, raw=True)
        if categoryDefaultsOption is not None:
            categoryDefaultsSpecs = splitRecord(categoryDefaultsOption)
            for category, categoryDefault in categoryDefaultsSpecs:
                self.categoryDefaults[category] = categoryDefault

        session = Session()

        # Find any new experiments. This allows experiments to be added to the config file without
        # running esginitialize.
        if self.fieldNames.has_key("experiment") and self.fieldNames["experiment"][WIDGET_TYPE] == ENUM:
            initializeExperiments(config, self.name, session)

        for category in self.getFieldNames():
            # At the moment some fields are predefined
            if category == "project":
                projects = splitRecord(config.get(projectSection, "project_options", default=""))
                self.validValues["project"] = [x[0] for x in projects]
            elif category == "model":
                models = session.query(Model).filter_by(project=self.name).all()
                self.validValues["model"] = [x.name for x in models]
            elif category == "experiment":
                experiments = session.query(Experiment).filter_by(project=self.name).all()
                self.validValues["experiment"] = [x.name for x in experiments]
            elif category == "creator":
                creators = splitRecord(config.get(projectSection, "creator_options", default=""))
                self.validValues["creator"] = [x[0] for x in creators]
                self.validMaps["creator"] = genMap(creators)
            elif category == "publisher":
                publishers = splitRecord(config.get(projectSection, "publisher_options", default=""))
                self.validValues["publisher"] = [x[0] for x in publishers]
                self.validMaps["publisher"] = genMap(publishers)
            else:
                categoryType = self.getFieldType(category)
                if categoryType == ENUM:
                    option = category + "_options"
                    self.validValues[category] = splitLine(config.get(projectSection, option), ",")

            self.context[category] = ""

        session.close()
Beispiel #2
0
    def get_pid_config(self, project_config_section, config):
        """ Returns the project specific pid config

         project_config_section
            The name of the project config section in esg.ini

        config
            The configuration (ini files)
        """
        pid_messaging_service_exchange_name = None
        if config.has_section(project_config_section):
            pid_messaging_service_exchange_name = config.get(project_config_section, 'pid_exchange_name', default=None)
        if not pid_messaging_service_exchange_name:
            raise ESGPublishError("Option 'pid_exchange_name' is missing in section '%s' of esg.ini." % project_config_section)

        # get credentials from config:project section of esg.ini
        if config.has_section(project_config_section):
            pid_messaging_service_credentials = []
            credentials = splitRecord(config.get(project_config_section, 'pid_credentials', default=''))
            if credentials:
                priority = 0
                for cred in credentials:
                    if len(cred) == 7 and isinstance(cred[6], int):
                        priority = cred[6]
                    elif len(cred) == 6:
                        priority += 1
                    else:
                        raise ESGPublishError("Misconfiguration: 'pid_credentials', section '%s' of esg.ini." % project_config_section)

                    ssl_enabled = False
                    if cred[5].strip().upper() == 'TRUE':
                        ssl_enabled = True

                    pid_messaging_service_credentials.append({'url': cred[0].strip(),
                                                              'port': cred[1].strip(),
                                                              'vhost': cred[2].strip(),
                                                              'user': cred[3].strip(),
                                                              'password': cred[4].strip(),
                                                              'ssl_enabled': ssl_enabled,
                                                              'priority': priority})

            else:
                raise ESGPublishError("Option 'pid_credentials' is missing in section '%s' of esg.ini." % project_config_section)
        else:
            raise ESGPublishError("Section '%s' not found in esg.ini." % project_config_section)

        return pid_messaging_service_exchange_name, pid_messaging_service_credentials
Beispiel #3
0
    def get_pid_config(self, project_config_section, config):
        """ Returns the project specific pid config

         project_config_section
            The name of the project config section in esg.ini

        config
            The configuration (ini files)
        """
        # get the PID configs
        pid_messaging_service_exchange_name = 'esgffed-exchange'

        # get credentials from config:project section of esg.ini
        if config.has_section(project_config_section):
            pid_messaging_service_credentials = []
            credentials = splitRecord(config.get(project_config_section, 'pid_credentials', default=''))
            if credentials:
                priority = 0
                for cred in credentials:
                    if len(cred) == 7 and isinstance(cred[6], int):
                        priority = cred[6]
                    elif len(cred) == 6:
                        priority += 1
                    else:
                        raise ESGPublishError(
                            "Misconfiguration: 'pid_credentials', section '%s' of esg.ini." % project_config_section)

                    ssl_enabled = False
                    if cred[5].strip().upper() == 'TRUE':
                        ssl_enabled = True

                    pid_messaging_service_credentials.append({'url': cred[0].strip(),
                                                              'port': cred[1].strip(),
                                                              'vhost': cred[2].strip(),
                                                              'user': cred[3].strip(),
                                                              'password': cred[4].strip(),
                                                              'ssl_enabled': ssl_enabled,
                                                              'priority': priority})

            else:
                raise ESGPublishError("Option 'pid_credentials' missing in section '%s' of esg.ini. "
                                      "Please contact your tier1 data node admin to get the proper values." % project_config_section)
        else:
            raise ESGPublishError("Section '%s' not found in esg.ini." % project_config_section)

        return pid_messaging_service_exchange_name, pid_messaging_service_credentials
Beispiel #4
0
    def initializeFields(self, Session):
        """Initialize field names and options based on the configuration file."""
        from esgcet.model import Model, Experiment
        config = getConfig()
        projectSection = 'project:' + self.name
        categoryOption = config.get(projectSection, 'categories')
        categorySpecs = splitRecord(categoryOption)
        for category, categoryTypeS, isMandatoryS, isThreddsPropertyS, displayOrderS in categorySpecs:
            categoryType = getCategoryType(categoryTypeS)
            isMandatory = getBoolean(isMandatoryS)
            isThreddsProperty = getBoolean(isThreddsPropertyS)
            displayOrder = string.atoi(displayOrderS)
            self.fieldNames[category] = (categoryType, isMandatory,
                                         isThreddsProperty, displayOrder)

        categoryDefaultsOption = config.get(projectSection,
                                            'category_defaults',
                                            default=None,
                                            raw=True)
        if categoryDefaultsOption is not None:
            categoryDefaultsSpecs = splitRecord(categoryDefaultsOption)
            for category, categoryDefault in categoryDefaultsSpecs:
                self.categoryDefaults[category] = categoryDefault

        session = Session()

        # Find any new experiments. This allows experiments to be added to the config file without
        # running esginitialize.
        if self.fieldNames.has_key('experiment') and self.fieldNames[
                'experiment'][WIDGET_TYPE] == ENUM:
            initializeExperiments(config, self.name, session)

        for category in self.getFieldNames():
            # At the moment some fields are predefined
            if category == "project":
                projects = splitRecord(
                    config.get(projectSection, 'project_options', default=''))
                self.validValues['project'] = [x[0] for x in projects]
            elif category == "model":
                models = session.query(Model).filter_by(
                    project=self.name).all()
                self.validValues['model'] = [x.name for x in models]
            elif category == "experiment":
                experiments = session.query(Experiment).filter_by(
                    project=self.name).all()
                self.validValues['experiment'] = [x.name for x in experiments]
            elif category == "creator":
                creators = splitRecord(
                    config.get(projectSection, 'creator_options', default=''))
                self.validValues['creator'] = [x[0] for x in creators]
                self.validMaps['creator'] = genMap(creators)
            elif category == "publisher":
                publishers = splitRecord(
                    config.get(projectSection, 'publisher_options',
                               default=''))
                self.validValues['publisher'] = [x[0] for x in publishers]
                self.validMaps['publisher'] = genMap(publishers)
            else:
                categoryType = self.getFieldType(category)
                if categoryType == ENUM:
                    option = category + "_options"
                    self.validValues[category] = splitLine(
                        config.get(projectSection, option), ',')

            self.context[category] = ''

        session.close()
    def __init__(self, parent):
        self.parent = parent
        self.Session = parent.parent.Session

        # ----------------------------------------------------------------------------------------
        # Display the Project selection
        # ----------------------------------------------------------------------------------------
        self.dataset_fields = {}

        projectOption = self.parent.parent.config.get("initialize", "project_options")
        projectSpecs = splitRecord(projectOption)
        projectName = projectSpecs[0][0]
        projectList = []
        for x in projectSpecs:
            projectList.append(x[0])
        projectList.sort()
        self.dataset_fields["Project"] = self.project_dataset = show_field(
            self.parent, self.parent.control_frame1, "Project", projectList, projectName, 1, 1
        )

        # Create and pack the LabeledWidgets for setting additional mandatory fields
        bnFont = tkFont.Font(
            self.parent.parent,
            family=pub_controls.label_button_font_type,
            size=pub_controls.label_button_font_size,
            weight=font_weight,
        )
        self.evt_fields_flg = False
        self.defaultGlobalValues = {}
        lw_dir = Pmw.LabeledWidget(
            self.parent.control_frame1, labelpos="w", label_font=bnFont, label_text="Set additional mandatory: "
        )
        lw_dir.component("hull").configure(relief="sunken", borderwidth=2)
        lw_dir.pack(side="top", expand=1, fill="both", padx=10, pady=10)
        cw_dir = Tkinter.Button(
            lw_dir.interior(),
            text="Fields",
            font=bnFont,
            background="lightblue",
            foreground="black",
            command=pub_controls.Command(self.evt_popup_fields_window, self.parent.parent, projectName),
        )
        cw_dir.pack(padx=10, pady=10, expand="yes", fill="both")
        self.save_dir_btn_color = cw_dir.cget("background")

        # Add additional mandatory fields to allow the user to set default settings
        #    handler = getHandlerByName(projectName, None, self.Session)
        #    list_fields = getQueryFields( handler )
        #    for x in list_fields:
        #        if handler.isMandatory( x ):
        #           if x.lower() != "project":
        #              field_options = handler.getFieldOptions(x)
        #              if field_options is not None:
        #                 field_options.insert(0, x+" (Default Global Setting)")
        #                 self.dataset_fields[x] = show_field( self.parent, self.parent.control_frame1, x.capitalize(), field_options , x+" (Default Global Setting)", 1, 1 )

        #    Pmw.alignlabels( self.dataset_fields.values() )

        # ----------------------------------------------------------------------------------------
        # Create and pack a work online or off line RadioSelect widget
        # ----------------------------------------------------------------------------------------
        self.parent.parent.offline = False
        self.parent.parent.offline_directories = None
        self.parent.parent.offline_datasetName = None
        self.on_off = Pmw.RadioSelect(
            self.parent.control_frame1,
            buttontype="radiobutton",
            orient="horizontal",
            labelpos="w",
            command=pub_controls.Command(self.evt_work_on_or_off_line),
            label_text="Work: ",
            label_font=bnFont,
            hull_borderwidth=2,
            hull_relief="ridge",
        )
        self.on_off.pack(side="top", expand=1, padx=10, pady=10)

        # Add some buttons to the radiobutton RadioSelect.
        for text in ("On-line", "Off-line"):
            self.on_off.add(text, font=bnFont)
        self.on_off.setvalue("On-line")

        # ----------------------------------------------------------------------------------------
        # Begin the creation of the file type selection
        # ----------------------------------------------------------------------------------------
        tagFont = tkFont.Font(
            self.parent.parent,
            family=pub_controls.button_group_font_type,
            size=pub_controls.button_group_font_size,
            weight=font_weight,
        )
        self.group_file_filter = Pmw.Group(
            self.parent.control_frame1,
            tag_text="Filter File Search",
            tag_font=tagFont,
            # hull_background = 'blue',
            tagindent=25,
        )

        dfFont = tkFont.Font(
            self.parent.parent,
            family=pub_controls.combobox_font_type,
            size=pub_controls.combobox_font_size,
            weight=font_weight,
        )
        self.data_filter = Pmw.ComboBox(
            self.group_file_filter.interior(),
            entryfield_value=pub_controls.datatypes[0],
            entry_font=dfFont,
            entry_state="readonly",
            entry_readonlybackground="aliceblue",
            listbox_font=dfFont,
            listbox_background="aliceblue",
            scrolledlist_items=pub_controls.datatypes,
        )

        self.data_filter.pack(side="top", fill="x", pady=5)
        self.group_file_filter.pack(side="top", fill="x", pady=3)
        # ----------------------------------------------------------------------------------------
        # End the creation of the file type selection
        # ----------------------------------------------------------------------------------------

        # ----------------------------------------------------------------------------------------
        # Begin the creation of the directory, file, and combo directoy box
        # ----------------------------------------------------------------------------------------
        glFont = tkFont.Font(
            self.parent.parent,
            family=pub_controls.button_group_font_type,
            size=pub_controls.button_group_font_size,
            weight=font_weight,
        )
        self.group_list_generation = Pmw.Group(
            self.parent.control_frame1, tag_text="Generate List", tag_font=glFont, tagindent=25
        )
        self.parent.control_frame2 = self.group_list_generation.interior()

        self.directory_icon = Tkinter.PhotoImage(file=file2_gif)
        self.file_icon = Tkinter.PhotoImage(file=folder2_gif)
        self.stop_icon = Tkinter.PhotoImage(file=stop_gif)

        # Create and pack the LabeledWidgets for the directory selction
        bnFont = tkFont.Font(
            self.parent.parent,
            family=pub_controls.label_button_font_type,
            size=pub_controls.label_button_font_size,
            weight=font_weight,
        )
        self.generating_file_list_flg = 0
        self.lw_dir = Pmw.LabeledWidget(
            self.parent.control_frame2, labelpos="w", label_font=bnFont, label_text="Generate list from: "
        )
        self.lw_dir.component("hull").configure(relief="sunken", borderwidth=2)
        self.lw_dir.pack(side="top", expand=1, fill="both", padx=10, pady=10)
        self.cw_dir = Tkinter.Button(
            self.lw_dir.interior(),
            text="Directory",
            font=bnFont,
            background="lightblue",
            foreground="black",
            command=pub_controls.Command(self.evt_popup_directory_window),
        )
        self.cw_dir.pack(padx=10, pady=10, expand="yes", fill="both")
        self.save_dir_btn_color = self.cw_dir.cget("background")

        # Create and pack the LabeledWidgets for the file selction
        self.lw_file = Pmw.LabeledWidget(
            self.parent.control_frame2, labelpos="w", label_font=bnFont, label_text="Generate list from: "
        )
        self.lw_file.component("hull").configure(relief="sunken", borderwidth=2)
        self.lw_file.pack(side="top", expand=1, fill="both", padx=10, pady=10)
        self.cw_file = Tkinter.Button(
            self.lw_file.interior(),
            text="Map File",
            font=bnFont,
            background="lightblue",
            foreground="black",
            command=pub_controls.Command(self.evt_popup_file_window),
        )
        self.cw_file.pack(padx=10, pady=10, expand="yes", fill="both")
        self.save_file_btn_color = self.cw_file.cget("background")

        # Set up directory combo box
        d, f = _scn_a_dir(self.parent)
        self.directory_combo = Pmw.ComboBox(
            self.parent.control_frame2,
            scrolledlist_items=d,
            entryfield_value=os.getcwd(),
            entry_font=("Times", 16, "bold"),
            entry_background="white",
            entry_foreground="black",
            selectioncommand=pub_controls.Command(self.evt_enter_directory),
        )
        self.directory_combo.component("entry").bind("<Key>", pub_controls.Command(self.evt_change_color))
        self.directory_combo.component("entry").bind("<Return>", pub_controls.Command(self.evt_enter_directory))
        self.directory_combo.component("entry").bind("<Tab>", pub_controls.Command(self.evt_tab))
        self.directory_combo.component("entry").bind("<BackSpace>", pub_controls.Command(self.evt_backspace))

        self.parent.control_frame2.pack(side="top", fill="x", pady=5)
        self.group_list_generation.pack(side="top", fill="x", pady=3)
        # ----------------------------------------------------------------------------------------
        # End the creation of the directory, file, and combo directoy box
        # ----------------------------------------------------------------------------------------

        # ----------------------------------------------------------------------------------------
        # Begin the regular expression widget
        #
        # We've decided that regular expression is no longer needed.
        # ----------------------------------------------------------------------------------------
        self.group_list = Pmw.Group(
            self.parent.control_frame1,
            tag_text="Regular Expressions",
            tag_font=("Times", 18, "bold"),
            hull_background="orange",
            tagindent=25,
        )
        ###################################################################################
        # To redisplay regular expression widget, just uncomment the 'pack' command below
        #      self.group_list.pack(side='top', fill='x')
        ###################################################################################

        self.scl1 = Pmw.ScrolledText(
            self.group_list.interior(),
            text_background="aliceblue",
            text_foreground="black",
            text_wrap="none",
            text_padx=5,
            text_pady=5,
            usehullsize=1,
            hull_width=100,
            hull_height=50,
        )
        # horizscrollbar_width=50,
        # vertscrollbar_width=50 )
        self.scl1.pack(side="top", expand=1, fill="both")

        # Create and pack the LabeledWidgets for the compiling of the regular expression
        self.generating_file_list_flg = 0
        self.lw_reg = Pmw.LabeledWidget(self.group_list.interior(), labelpos="w", label_text="Regular expression: ")
        self.lw_reg.component("hull").configure(relief="sunken", borderwidth=2)
        self.lw_reg.pack(side="top", expand=1, fill="both", padx=10, pady=10)
        self.cw_reg = Tkinter.Button(
            self.lw_reg.interior(), text="Go", command=pub_controls.Command(self.evt_compile_regular_expression)
        )
        self.cw_reg.pack(padx=10, pady=10, expand="yes", fill="both")
        self.save_reg_btn_color = self.cw_reg.cget("background")
Beispiel #6
0
    def __init__(self, parent):
        self.parent = parent
        self.Session = parent.parent.Session

        #----------------------------------------------------------------------------------------
        # Display the Project selection
        #----------------------------------------------------------------------------------------
        self.dataset_fields = {}

        projectOption = self.parent.parent.config.get('initialize',
                                                      'project_options')
        projectSpecs = splitRecord(projectOption)
        projectName = projectSpecs[0][0]
        projectList = []
        for x in projectSpecs:
            projectList.append(x[0])
        projectList.sort()
        self.dataset_fields["Project"] = self.project_dataset = show_field(
            self.parent, self.parent.control_frame1, "Project", projectList,
            projectName, 1, 1)

        # Create and pack the LabeledWidgets for setting additional mandatory fields
        bnFont = tkFont.Font(self.parent.parent,
                             family=pub_controls.label_button_font_type,
                             size=pub_controls.label_button_font_size,
                             weight=font_weight)
        self.evt_fields_flg = False
        self.defaultGlobalValues = {}
        lw_dir = Pmw.LabeledWidget(self.parent.control_frame1,
                                   labelpos='w',
                                   label_font=bnFont,
                                   label_text='Set additional mandatory: ')
        lw_dir.component('hull').configure(relief='sunken', borderwidth=2)
        lw_dir.pack(side='top', expand=1, fill='both', padx=10, pady=10)
        cw_dir = Tkinter.Button(lw_dir.interior(),
                                text='Fields',
                                font=bnFont,
                                background="lightblue",
                                foreground='black',
                                command=pub_controls.Command(
                                    self.evt_popup_fields_window,
                                    self.parent.parent, projectName))
        cw_dir.pack(padx=10, pady=10, expand='yes', fill='both')
        self.save_dir_btn_color = cw_dir.cget("background")

        # Add additional mandatory fields to allow the user to set default settings
        #    handler = getHandlerByName(projectName, None, self.Session)
        #    list_fields = getQueryFields( handler )
        #    for x in list_fields:
        #        if handler.isMandatory( x ):
        #           if x.lower() != "project":
        #              field_options = handler.getFieldOptions(x)
        #              if field_options is not None:
        #                 field_options.insert(0, x+" (Default Global Setting)")
        #                 self.dataset_fields[x] = show_field( self.parent, self.parent.control_frame1, x.capitalize(), field_options , x+" (Default Global Setting)", 1, 1 )

        #    Pmw.alignlabels( self.dataset_fields.values() )

        #----------------------------------------------------------------------------------------
        # Create and pack a work online or off line RadioSelect widget
        #----------------------------------------------------------------------------------------
        self.parent.parent.offline = False
        self.parent.parent.offline_directories = None
        self.parent.parent.offline_datasetName = None
        self.on_off = Pmw.RadioSelect(
            self.parent.control_frame1,
            buttontype='radiobutton',
            orient='horizontal',
            labelpos='w',
            command=pub_controls.Command(self.evt_work_on_or_off_line, ),
            label_text='Work: ',
            label_font=bnFont,
            hull_borderwidth=2,
            hull_relief='ridge',
        )
        self.on_off.pack(side='top', expand=1, padx=10, pady=10)

        # Add some buttons to the radiobutton RadioSelect.
        for text in ('On-line', 'Off-line'):
            self.on_off.add(text, font=bnFont)
        self.on_off.setvalue('On-line')

        #----------------------------------------------------------------------------------------
        # Begin the creation of the file type selection
        #----------------------------------------------------------------------------------------
        tagFont = tkFont.Font(self.parent.parent,
                              family=pub_controls.button_group_font_type,
                              size=pub_controls.button_group_font_size,
                              weight=font_weight)
        self.group_file_filter = Pmw.Group(
            self.parent.control_frame1,
            tag_text='Filter File Search',
            tag_font=tagFont,
            #hull_background = 'blue',
            tagindent=25)

        dfFont = tkFont.Font(self.parent.parent,
                             family=pub_controls.combobox_font_type,
                             size=pub_controls.combobox_font_size,
                             weight=font_weight)
        self.data_filter = Pmw.ComboBox(
            self.group_file_filter.interior(),
            entryfield_value=pub_controls.datatypes[0],
            entry_font=dfFont,
            entry_state='readonly',
            entry_readonlybackground="aliceblue",
            listbox_font=dfFont,
            listbox_background="aliceblue",
            scrolledlist_items=pub_controls.datatypes,
        )

        self.data_filter.pack(side='top', fill='x', pady=5)
        self.group_file_filter.pack(side='top', fill='x', pady=3)
        #----------------------------------------------------------------------------------------
        # End the creation of the file type selection
        #----------------------------------------------------------------------------------------

        #----------------------------------------------------------------------------------------
        # Begin the creation of the directory, file, and combo directoy box
        #----------------------------------------------------------------------------------------
        glFont = tkFont.Font(self.parent.parent,
                             family=pub_controls.button_group_font_type,
                             size=pub_controls.button_group_font_size,
                             weight=font_weight)
        self.group_list_generation = Pmw.Group(self.parent.control_frame1,
                                               tag_text='Generate List',
                                               tag_font=glFont,
                                               tagindent=25)
        self.parent.control_frame2 = self.group_list_generation.interior()

        self.directory_icon = Tkinter.PhotoImage(file=file2_gif)
        self.file_icon = Tkinter.PhotoImage(file=folder2_gif)
        self.stop_icon = Tkinter.PhotoImage(file=stop_gif)

        # Create and pack the LabeledWidgets for the directory selction
        bnFont = tkFont.Font(self.parent.parent,
                             family=pub_controls.label_button_font_type,
                             size=pub_controls.label_button_font_size,
                             weight=font_weight)
        self.generating_file_list_flg = 0
        self.lw_dir = Pmw.LabeledWidget(self.parent.control_frame2,
                                        labelpos='w',
                                        label_font=bnFont,
                                        label_text='Generate list from: ')
        self.lw_dir.component('hull').configure(relief='sunken', borderwidth=2)
        self.lw_dir.pack(side='top', expand=1, fill='both', padx=10, pady=10)
        self.cw_dir = Tkinter.Button(self.lw_dir.interior(),
                                     text='Directory',
                                     font=bnFont,
                                     background="lightblue",
                                     foreground='black',
                                     command=pub_controls.Command(
                                         self.evt_popup_directory_window))
        self.cw_dir.pack(padx=10, pady=10, expand='yes', fill='both')
        self.save_dir_btn_color = self.cw_dir.cget("background")

        # Create and pack the LabeledWidgets for the file selction
        self.lw_file = Pmw.LabeledWidget(self.parent.control_frame2,
                                         labelpos='w',
                                         label_font=bnFont,
                                         label_text='Generate list from: ')
        self.lw_file.component('hull').configure(relief='sunken',
                                                 borderwidth=2)
        self.lw_file.pack(side='top', expand=1, fill='both', padx=10, pady=10)
        self.cw_file = Tkinter.Button(self.lw_file.interior(),
                                      text='Map File',
                                      font=bnFont,
                                      background="lightblue",
                                      foreground='black',
                                      command=pub_controls.Command(
                                          self.evt_popup_file_window))
        self.cw_file.pack(padx=10, pady=10, expand='yes', fill='both')
        self.save_file_btn_color = self.cw_file.cget("background")

        # Set up directory combo box
        d, f = _scn_a_dir(self.parent)
        self.directory_combo = Pmw.ComboBox(
            self.parent.control_frame2,
            scrolledlist_items=d,
            entryfield_value=os.getcwd(),
            entry_font=('Times', 16, 'bold'),
            entry_background='white',
            entry_foreground='black',
            selectioncommand=pub_controls.Command(self.evt_enter_directory))
        self.directory_combo.component('entry').bind(
            "<Key>", pub_controls.Command(self.evt_change_color))
        self.directory_combo.component('entry').bind(
            "<Return>", pub_controls.Command(self.evt_enter_directory))
        self.directory_combo.component('entry').bind(
            '<Tab>', pub_controls.Command(self.evt_tab))
        self.directory_combo.component('entry').bind(
            "<BackSpace>", pub_controls.Command(self.evt_backspace))

        self.parent.control_frame2.pack(side="top", fill='x', pady=5)
        self.group_list_generation.pack(side='top', fill='x', pady=3)
        #----------------------------------------------------------------------------------------
        # End the creation of the directory, file, and combo directoy box
        #----------------------------------------------------------------------------------------

        #----------------------------------------------------------------------------------------
        # Begin the regular expression widget
        #
        # We've decided that regular expression is no longer needed.
        #----------------------------------------------------------------------------------------
        self.group_list = Pmw.Group(self.parent.control_frame1,
                                    tag_text='Regular Expressions',
                                    tag_font=('Times', 18, 'bold'),
                                    hull_background='orange',
                                    tagindent=25)
        ###################################################################################
        # To redisplay regular expression widget, just uncomment the 'pack' command below
        #      self.group_list.pack(side='top', fill='x')
        ###################################################################################

        self.scl1 = Pmw.ScrolledText(self.group_list.interior(),
                                     text_background='aliceblue',
                                     text_foreground='black',
                                     text_wrap='none',
                                     text_padx=5,
                                     text_pady=5,
                                     usehullsize=1,
                                     hull_width=100,
                                     hull_height=50)
        #horizscrollbar_width=50,
        #vertscrollbar_width=50 )
        self.scl1.pack(side='top', expand=1, fill='both')

        # Create and pack the LabeledWidgets for the compiling of the regular expression
        self.generating_file_list_flg = 0
        self.lw_reg = Pmw.LabeledWidget(self.group_list.interior(),
                                        labelpos='w',
                                        label_text='Regular expression: ')
        self.lw_reg.component('hull').configure(relief='sunken', borderwidth=2)
        self.lw_reg.pack(side='top', expand=1, fill='both', padx=10, pady=10)
        self.cw_reg = Tkinter.Button(self.lw_reg.interior(),
                                     text='Go',
                                     command=pub_controls.Command(
                                         self.evt_compile_regular_expression))
        self.cw_reg.pack(padx=10, pady=10, expand='yes', fill='both')
        self.save_reg_btn_color = self.cw_reg.cget("background")
    def __init__(self, parent):
        self.parent = parent
        self.Session = parent.parent.Session
        self.select_button = {}
        self.select_labelV = {}
        self.select_label = {}

        # ----------------------------------------------------------------------------------------
        # Begin the creation of the dataset ID pulldown query selection
        # ----------------------------------------------------------------------------------------
        glFont = tkFont.Font(
            self.parent.parent,
            family=pub_controls.button_group_font_type,
            size=pub_controls.button_group_font_size,
            weight=font_weight,
        )
        bnFont = tkFont.Font(
            self.parent.parent,
            family=pub_controls.label_button_font_type,
            size=pub_controls.label_button_font_size,
            weight=font_weight,
        )
        self.group_query = Pmw.Group(self.parent.control_frame4, tag_text="Query ID", tag_font=glFont, tagindent=25)

        # ----------------------------------------------------------------------------------------
        # Create and pack the EntryFields
        # ----------------------------------------------------------------------------------------
        self.query_entry = Pmw.EntryField(
            self.group_query.interior(),
            labelpos="w",
            label_text="Dataset Id:",
            label_font=bnFont,
            entry_width=200,
            validate=None,
            command=pub_controls.Command(self.evt_show_data_set_from_id),
        )

        self.query_entry.pack(side="left", expand=1, padx=10, pady=10)
        # ----------------------------------------------------------------------------------------
        # End the creation of the dataset ID pulldown query selection
        # ----------------------------------------------------------------------------------------

        # ----------------------------------------------------------------------------------------
        # Begin the creation of the project pulldown query selection
        # ----------------------------------------------------------------------------------------
        self.button_controls = Pmw.Group(
            self.parent.control_frame4, tag_text="Query Project Infomation", tag_font=glFont, tagindent=25
        )

        # ----------------------------------------------------------------------------------------
        # Create an instance of the notebook
        # ----------------------------------------------------------------------------------------
        ntk = generate_notebook(parent, self.Session)
        parent.parent.ntk = ntk  # Set the first instance of the notebook

        self.bdataset_sframe = Pmw.ScrolledFrame(self.button_controls.interior())
        self.bdataset_sframe.pack(side="top")
        self.bdataset_frame = self.bdataset_sframe.interior()

        # ----------------------------------------------------------------------------------------
        # Display the Project selection
        # ----------------------------------------------------------------------------------------
        projectOption = self.parent.parent.config.get("initialize", "project_options")
        projectSpecs = splitRecord(projectOption)
        projectName = projectSpecs[0][0]
        projectList = []
        for x in projectSpecs:
            projectList.append(x[0])
        projectList.sort()

        parent.query_fields = {}
        parent.validate = {}
        parent.query_fields["project"] = show_field(
            self.parent, self.bdataset_frame, "Project", projectList, projectName, 1, 1, for_query=True
        )
        parent.validate["project"] = 1

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

        validate = []
        mandatory = []
        options = {}
        for x in list_fields:
            if handler.getFieldType(x) is not None:
                validate.append(handler.getFieldType(x))
            else:
                validate.append(2)
            options[x] = handler.getFieldOptions(x)
            mandatory.append(handler.isMandatory(x))

        for j in range(1, 5):
            for i in range(len(list_fields)):
                if list_fields[i] is not "project":
                    if options[list_fields[i]] is None:
                        value = ""
                    else:
                        value = options[list_fields[i]]  # ganz bug fix [0]
                    if validate[i] == 1:
                        options[list_fields[i]].insert(0, "-Any-")
                        value = "-Any-"
                    if j == validate[i]:
                        parent.query_fields[list_fields[i]] = show_field(
                            self.parent,
                            self.bdataset_frame,
                            list_fields[i].capitalize(),
                            options[list_fields[i]],
                            value,
                            mandatory[i],
                            validate[i],
                            for_query=True,
                        )
                        parent.validate[list_fields[i]] = validate[i]

        Pmw.alignlabels(parent.query_fields.values())

        # ----------------------------------------------------------------------------------------
        # Create button to update extraction
        # ----------------------------------------------------------------------------------------
        w = Tkinter.Button(
            self.button_controls.interior(),
            text="Query Data Information",
            font=bnFont,
            background="lightblue",
            command=pub_controls.Command(ntk.new_query_page, parent, None),
        )
        w.pack(side="top", padx=0, pady=3)

        self.button_controls.pack(side="top", fill="x", pady=3)
Beispiel #8
0
def getData(inpath, extra_metadata):
    # pdb.set_trace()
    f = cdms2.open(inpath)

    # get a handle to the main module so we can call his routines
    main = sys.modules['__main__']
 
    # load info from esg.ini
    cfg = loadConfig("esg.ini")

    # load info from this run's transient config
    x = SaneConfigParser({})
    x.read(extra_metadata)

    # pdb.set_trace()
    output = dif_switch()
    
    for mode in ['thredds_aggregation_services',
                 'thredds_file_services',
                 'thredds_offline_services']:
        s = splitRecord(cfg.get('DEFAULT', mode))[0]
        iform(output, 'service/')
        iform(output, 'serviceType="%s"' % s[0])
        iform(output, 'base="%s"' % s[1])
        iform(output, 'name="%s"' % s[2])
        iform(output, 'desc="%s"' % DEFAULT_THREDDS_SERVICE_DESCRIPTIONS[s[0]])
        iform(output, 'property/')
        iform(output, 'name="requires_authorization"')
        iform(output,
              'value="%s"' % DEFAULT_THREDDS_SERVICE_AUTH_REQUIRED[s[0]], -1)
        for app in DEFAULT_THREDDS_SERVICE_APPLICATIONS[s[0]]:
            iform(output, '  property/')
            iform(output, 'name="application"')
            iform(output, 'value="%s"' % app, -1)

        iform(output, "", 0)
    
    iform(output, 'property/')
    iform(output, 'name="catalog_version"')
    iform(output, 'value="2"', -1)

    iform(output, 'dataset/')
    iform(output, 'restrictAccess="esg-user"')
    project = x.get('DEFAULT', 'project')

    iform(output, "ID=%s" % safe_quote(safe_interpolate(cfg,
                                                'project:' + project,
                                                'dataset_id',
                                                x)))
          
    iform(output, "name=%s" % safe_quote(safe_interpolate(cfg,
                                                  'project:' + project,
                                                  'dataset_name_format',
                                                  x)))

    for name, value in x.items('DEFAULT'):
        iform(output, 'property/')
        iform(output, 'name="%s"' % name)
        iform(output, 'value="%s"' % value, -1)
        
    iform(output, 'metadata/')
    iform(output, 'variables/')
    # pdb.set_trace()

    for v in f.variables.keys():
        iform(output, 'variable/')
        iform(output, 'name="%s"' % safe_getattr(f.variables[v], "id", "name"))

        vname = vocabulary_name(f.variables[v])
        iform(output, 'vocabulary_name="%s"' % vname)
        iform(output, 'units="%s"' % safe_getattr(f.variables[v],
                                                  "units"))
        iform(output, safe_getattr(f.variables[v], "long_name"), -1)
        
    for v in f.axes.keys():
        iform(output, 'variable/')
        iform(output, 'name="%s"' % v)
        vname = vocabulary_name(f.axes[v])
        iform(output, 'vocabulary_name="%s"' % vname)
        iform(output, 'units="%s"' % safe_getattr(f.axes[v], "units"))
        iform(output, safe_getattr(f.axes[v], "long_name"), -1)

    # pdb.set_trace()
    try:
        n = output.name
        if n == '<stdout>':
            rval = None
        else:
            rval = 'file:' + n
    except:
        rval = 'string:' + output.getvalue()

    return rval