예제 #1
0
    def __init__(self, infile=None, files=None):
        if infile is None:
            if files is None:
                files = Files()
            infile = files.get_value("PIO_SPEC_FILE")

        EntryID.__init__(self, infile)
예제 #2
0
파일: files.py 프로젝트: IMMM-SFA/im3-cime
    def __init__(self, comp_interface="mct"):
        """
        initialize an object

        >>> files = Files()
        >>> files.get_value('CASEFILE_HEADERS',resolved=False)
        '$CIMEROOT/config/config_headers.xml'
        """
        cimeroot = get_cime_root()
        infile = os.path.join(cimeroot, "config", get_model(),
                              "config_files.xml")
        expect(os.path.isfile(infile),
               "Could not find or open file {}".format(infile))
        schema = os.path.join(cimeroot, "config", "xml_schemas",
                              "entry_id.xsd")
        EntryID.__init__(self, infile, schema=schema)
        config_files_override = os.path.join(os.path.dirname(cimeroot),
                                             ".config_files.xml")
        # variables COMP_ROOT_DIR_{} are mutable, all other variables are read only
        self.COMP_ROOT_DIR = {}
        self._comp_interface = comp_interface
        # .config_file.xml at the top level may overwrite COMP_ROOT_DIR_ nodes in config_files

        if os.path.isfile(config_files_override):
            self.read(config_files_override)
            self.overwrite_existing_entries()
예제 #3
0
파일: pio.py 프로젝트: Katetc/cime
    def __init__(self, infile=None, files=None):
        if infile is None:
            if files is None:
                files = Files()
            infile = files.get_value("PIO_SPEC_FILE")

        EntryID.__init__(self, infile)
예제 #4
0
파일: pio.py 프로젝트: zswolff/E3SM
    def __init__(self, comp_classes, infile=None, files=None):
        if infile is None:
            if files is None:
                files = Files()
            infile = files.get_value("PIO_SPEC_FILE")

        EntryID.__init__(self, infile)

        self._components = list(comp_classes)
예제 #5
0
    def __init__(self, infile=None):
        """
        initialize an object
        """
        if infile is None:
            files = Files()
            infile = files.get_value("CONFIG_DRV_FILE")

        EntryID.__init__(self,infile)
예제 #6
0
파일: files.py 프로젝트: ekluzek/cime
    def __init__(self):
        """
        initialize an object

        >>> files = Files()
        >>> files.get_value('CASEFILE_HEADERS',resolved=False)
        '$CIMEROOT/cime_config/config_headers.xml'
        """
        infile = os.path.join(get_cime_root(), "cime_config", get_model(), "config_files.xml")
        EntryID.__init__(self, infile)
예제 #7
0
 def __init__(self, infile):
     """
     initialize an object
     """
     files = Files()
     schema = None
     # not checking schema on external components yet
     cimeroot = get_cime_root()
     if cimeroot in os.path.abspath(infile):
         schema = files.get_schema("CONFIG_CPL_FILE")
     EntryID.__init__(self, infile, schema=schema)
예제 #8
0
파일: files.py 프로젝트: gold2718/cime
    def __init__(self):
        """
        initialize an object

        >>> files = Files()
        >>> files.get_value('CASEFILE_HEADERS',resolved=False)
        '$CIMEROOT/cime_config/config_headers.xml'
        """
        infile = os.path.join(get_cime_root(), "cime_config", get_model(),
                              "config_files.xml")
        EntryID.__init__(self, infile)
예제 #9
0
    def __init__(self, infile):
        """
        initialize an object
        """
        files = Files()
        schema = None
        # not checking schema on external components yet
        cimeroot = get_cime_root()
        if  cimeroot in os.path.abspath(infile):
            schema = files.get_schema("CONFIG_DRV_FILE")

        EntryID.__init__(self, infile, schema=schema)
예제 #10
0
    def __init__(self, infile=None):
        """
        initialize an object

        >>> files = Files()
        >>> files.get_value('CASEFILE_HEADERS',resolved=False)
        '$CIMEROOT/cime_config/config_headers.xml'
        """
        if infile is None:
            files = Files()
            infile = files.get_value('CASEFILE_HEADERS', resolved=True)
        EntryID.__init__(self, infile)
예제 #11
0
파일: headers.py 프로젝트: apcraig/cime
    def __init__(self,infile=None):
        """
        initialize an object

        >>> files = Files()
        >>> files.get_value('CASEFILE_HEADERS',resolved=False)
        '$CIMEROOT/config/config_headers.xml'
        """
        if infile is None:
            files = Files()
            infile = files.get_value('CASEFILE_HEADERS', resolved=True)
        EntryID.__init__(self, infile)
예제 #12
0
파일: files.py 프로젝트: apcraig/cime
    def __init__(self):
        """
        initialize an object

        >>> files = Files()
        >>> files.get_value('CASEFILE_HEADERS',resolved=False)
        '$CIMEROOT/config/config_headers.xml'
        """
        cimeroot = get_cime_root()
        infile = os.path.join(cimeroot, "config", get_model(), "config_files.xml")
        expect(os.path.isfile(infile), "Could not find or open file {}".format(infile))
        schema = os.path.join(cimeroot, "config", "xml_schemas", "entry_id.xsd")
        EntryID.__init__(self, infile, schema=schema)
예제 #13
0
    def __init__(self, infile):
        """
        initialize an object
        """
        files = Files()
        schema = files.get_schema("CONFIG_DRV_FILE")
        if schema is not None:
            # not checking schema on external components yet
            cimeroot = get_cime_root()
            if cimeroot in os.path.abspath(infile):
                self.validate_xml_file(infile, schema)

        EntryID.__init__(self, infile)
예제 #14
0
파일: compsets.py 프로젝트: quantheory/cime
 def get_compset_var_settings(self, compset, grid):
     '''
     Variables can be set in config_compsets.xml in entry id settings with compset and grid attributes
     find and return id value pairs here
     '''
     nodes = self.get_nodes("entry")
     # Get an empty entryid obj to use
     entryidobj = EntryID()
     result = []
     for node in nodes:
         value = entryidobj.get_default_value(node, {"grid":grid, "compset":compset})
         if value is not None:
             result.append((node.get("id"), value))
     return result
예제 #15
0
    def __init__(self, case_root, infile):
        if case_root is None:
            case_root = os.getcwd()

        if os.path.isabs(infile):
            fullpath = infile
        else:
            fullpath = os.path.join(case_root, infile)

        EntryID.__init__(self, fullpath)
        if not os.path.isfile(fullpath):
            headerobj = Headers()
            headernode = headerobj.get_header_node(os.path.basename(fullpath))
            self.root.append(headernode)
예제 #16
0
    def __init__(self, case_root, infile):
        if case_root is None:
            case_root = os.getcwd()

        if os.path.isabs(infile):
            fullpath = infile
        else:
            fullpath = os.path.join(case_root, infile)

        EntryID.__init__(self, fullpath)
        if not os.path.isfile(fullpath):
            headerobj = Headers()
            headernode = headerobj.get_header_node(os.path.basename(fullpath))
            self.root.append(headernode)
예제 #17
0
파일: env_base.py 프로젝트: sarats/ACME
    def get_value(self, vid, attribute=None, resolved=True, subgroup=None):
        """
        Get a value for entry with id attribute vid.
        or from the values field if the attribute argument is provided
        and matches
        """
        value = None
        vid, comp, iscompvar = self.check_if_comp_var(vid, attribute)
        logger.debug("vid {} comp {} iscompvar {}".format(vid, comp, iscompvar))
        if iscompvar:
            if comp is None:
                if subgroup is not None:
                    comp = subgroup
                else:
                    logger.debug("Not enough info to get value for {}".format(vid))
                    return value
            if attribute is None:
                attribute = {"compclass" : comp}
            else:
                attribute["compclass"] = comp
            node = self.scan_optional_child("entry", {"id":vid})
            if node is not None:
                type_str = self._get_type_info(node)
                values = self.get_optional_child("values", root=node)
                node = values if values is not None else node
                val = self.get_element_text("value", attribute, root=node)
                if val is not None:
                    if val.startswith("$"):
                        value = val
                    else:
                        value = convert_to_type(val,type_str, vid)
                return value

        return EntryID.get_value(self, vid, attribute=attribute, resolved=resolved, subgroup=subgroup)
예제 #18
0
    def __init__(self):
        """
        initialize an object

        >>> files = Files()
        >>> files.get_value('CASEFILE_HEADERS',resolved=False)
        '$CIMEROOT/config/config_headers.xml'
        """
        cimeroot = get_cime_root()
        infile = os.path.join(cimeroot, "config", get_model(),
                              "config_files.xml")
        expect(os.path.isfile(infile),
               "Could not find or open file {}".format(infile))
        schema = os.path.join(cimeroot, "config", "xml_schemas",
                              "entry_id.xsd")
        EntryID.__init__(self, infile, schema=schema)
예제 #19
0
    def __init__(self, infile, comp_class):
        """
        initialize a Component obect from the component xml file in infile
        associate the component class with comp_class if provided.
        """
        self._comp_class = comp_class
        if infile == 'testingonly':
            self.filename = infile
            return
        files = Files()
        schema = None
        EntryID.__init__(self, infile)
        schema = files.get_schema("CONFIG_{}_FILE".format(comp_class), attributes={"version":"{}".format(self.get_version())})

        if schema is not None:
            self.validate_xml_file(infile, schema)
예제 #20
0
    def _set_value(self,
                   node,
                   value,
                   vid=None,
                   subgroup=None,
                   ignore_type=False,
                   compclass=None):
        if vid is None:
            vid = self.get(node, "id")
        vid, _, iscompvar = self.check_if_comp_var(vid, node=node)

        if iscompvar:
            expect(compclass is not None,
                   "compclass must be specified if is comp var")
            attribute = {"compclass": compclass}
            str_value = self.get_valid_value_string(node, value, vid,
                                                    ignore_type)
            values = self.get_optional_child("values", root=node)
            node = values if values is not None else node
            val = self.set_element_text("value",
                                        str_value,
                                        attribute,
                                        root=node)
        else:
            val = EntryID._set_value(self, node, value, vid, subgroup,
                                     ignore_type)
        return val
예제 #21
0
    def get_value(self, vid, attribute=None, resolved=True, subgroup=None):
        """
        Get a value for entry with id attribute vid.
        or from the values field if the attribute argument is provided
        and matches
        """
        value = None
        vid, comp, iscompvar = self.check_if_comp_var(vid, attribute)
        logger.debug("vid {} comp {} iscompvar {}".format(vid, comp, iscompvar))
        if iscompvar:
            if comp is None:
                if subgroup is not None:
                    comp = subgroup
                else:
                    logger.debug("Not enough info to get value for {}".format(vid))
                    return value
            if attribute is None:
                attribute = {"compclass" : comp}
            else:
                attribute["compclass"] = comp
            node = self.scan_optional_child("entry", {"id":vid})
            if node is not None:
                type_str = self._get_type_info(node)
                values = self.get_optional_child("values", root=node)
                node = values if values is not None else node
                val = self.get_element_text("value", attribute, root=node)
                if val is not None:
                    if val.startswith("$"):
                        value = val
                    else:
                        value = convert_to_type(val,type_str, vid)
                return value

        return EntryID.get_value(self, vid, attribute=attribute, resolved=resolved, subgroup=subgroup)
예제 #22
0
    def get_children(self, name=None, attributes=None, root=None):
        if self.locked and name == "entry" and attributes is not None and attributes.keys(
        ) == ["id"]:
            entry_id = attributes["id"]
            if root is None or self.name(root) == "file":
                if entry_id in self._id_map:
                    return self._id_map[entry_id]
                else:
                    return []
            else:
                expect(
                    self.name(root) == "group",
                    "Unexpected elem '{}' for {}, attrs {}".format(
                        self.name(root), self.filename, self.attrib(root)))
                group_id = self.get(root, "id")
                if group_id in self._group_map and entry_id in self._group_map[
                        group_id]:
                    return [self._group_map[group_id][entry_id]]
                else:
                    return []

        else:
            # Non-compliant look up
            return EntryID.get_children(self,
                                        name=name,
                                        attributes=attributes,
                                        root=root)
예제 #23
0
 def get_compset_var_settings(self, compset, grid):
     '''
     Variables can be set in config_compsets.xml in entry id settings with compset and grid attributes
     find and return id value pairs here
     '''
     nodes = self.get_nodes("entry")
     # Get an empty entryid obj to use
     entryidobj = EntryID()
     result = []
     for node in nodes:
         value = entryidobj.get_default_value(node, {
             "grid": grid,
             "compset": compset
         })
         if value is not None:
             result.append((node.get("id"), value))
     return result
예제 #24
0
파일: compsets.py 프로젝트: bertinia/cime
    def get_compset_var_settings(self, compset, grid):
        '''
        Variables can be set in config_compsets.xml in entry id settings with compset and grid attributes
        find and return id value pairs here
        '''
        entries = self.get_optional_child("entries")
        result = []
        if entries is not None:
            nodes = self.get_children("entry", root=entries)
            # Get an empty entryid obj to use
            entryidobj = EntryID()
            for node in nodes:
                value = entryidobj.get_default_value(node, {"grid":grid, "compset":compset})
                if value is not None:
                    result.append((self.get(node, "id"), value))

        return result
예제 #25
0
    def __init__(self, infile):
        """
        initialize an object
        """
        files = Files()

        # use xmllint to validate infile
        xmllint = find_executable("xmllint")
        if xmllint is not None:
            # all components refer to the same schema so referencing config_drv_file is okay
            schema = files.get_schema("CONFIG_DRV_FILE")
            if schema is not None:
                logger.debug("Checking file %s against %s" % (infile, schema))
                run_cmd_no_fail("%s --noout --schema %s %s" %
                                (xmllint, schema, infile))

        EntryID.__init__(self, infile)
예제 #26
0
    def get_compset_var_settings(self, compset, grid):
        '''
        Variables can be set in config_compsets.xml in entry id settings with compset and grid attributes
        find and return id value pairs here
        '''
        entries = self.get_optional_child("entries")
        result = []
        if entries is not None:
            nodes = self.get_children("entry", root=entries)
            # Get an empty entryid obj to use
            entryidobj = EntryID()
            for node in nodes:
                value = entryidobj.get_default_value(node, {
                    "grid": grid,
                    "compset": compset
                })
                if value is not None:
                    result.append((self.get(node, "id"), value))

        return result
예제 #27
0
    def __init__(self, case_root, infile, schema=None, read_only=False):
        if case_root is None:
            case_root = os.getcwd()

        if os.path.isabs(infile):
            fullpath = infile
        else:
            fullpath = os.path.join(case_root, infile)

        EntryID.__init__(self, fullpath, schema=schema, read_only=read_only)

        self._id_map = None
        self._group_map = None

        if not os.path.isfile(fullpath):
            headerobj = Headers()
            headernode = headerobj.get_header_node(os.path.basename(fullpath))
            self.add_child(headernode)
        else:
            self._setup_cache()
예제 #28
0
    def __init__(self, case_root, infile, schema=None, read_only=False):
        if case_root is None:
            case_root = os.getcwd()

        if os.path.isabs(infile):
            fullpath = infile
        else:
            fullpath = os.path.join(case_root, infile)

        EntryID.__init__(self, fullpath, schema=schema, read_only=read_only)

        self._id_map = None
        self._group_map = None

        if not os.path.isfile(fullpath):
            headerobj = Headers()
            headernode = headerobj.get_header_node(os.path.basename(fullpath))
            self.add_child(headernode)
        else:
            self._setup_cache()
예제 #29
0
 def scan_children(self, nodename, attributes=None, root=None):
     if self.locked and nodename == "entry" and attributes is not None and attributes.keys(
     ) == ["id"]:
         return EnvBase.get_children(self,
                                     name=nodename,
                                     attributes=attributes,
                                     root=root)
     else:
         return EntryID.scan_children(self,
                                      nodename,
                                      attributes=attributes,
                                      root=root)
예제 #30
0
파일: env_base.py 프로젝트: apcraig/cime
    def _set_value(self, node, value, vid=None, subgroup=None, ignore_type=False, compclass=None):
        if vid is None:
            vid = node.get("id")
        vid, _, iscompvar = self.check_if_comp_var(vid, None)

        if iscompvar:
            attribute = {"compclass":compclass}
            str_value = self.get_valid_value_string(node, value, vid, ignore_type)
            val = self.set_element_text("value", str_value, attribute, root=node)
        else:
            val = EntryID._set_value(self, node, value, vid, subgroup, ignore_type)
        return val
예제 #31
0
파일: files.py 프로젝트: Katetc/cime
    def __init__(self):
        """
        initialize an object

        >>> files = Files()
        >>> files.get_value('CASEFILE_HEADERS',resolved=False)
        '$CIMEROOT/config/config_headers.xml'
        """
        cimeroot = get_cime_root()
        infile = os.path.join(cimeroot, "config", get_model(), "config_files.xml")
        expect(os.path.isfile(infile), "Could not find or open file {}".format(infile))
        schema = os.path.join(cimeroot, "config", "xml_schemas", "entry_id.xsd")
        EntryID.__init__(self, infile, schema=schema)
        config_files_override = os.path.join(os.path.dirname(cimeroot),".config_files.xml")
        # variables COMP_ROOT_DIR_{} are mutable, all other variables are read only
        self.COMP_ROOT_DIR = {}

        # .config_file.xml at the top level may overwrite COMP_ROOT_DIR_ nodes in config_files

        if os.path.isfile(config_files_override):
            self.read(config_files_override)
            self.overwrite_existing_entries()
예제 #32
0
    def _set_value(self, node, value, vid=None, subgroup=None, ignore_type=False, compclass=None):
        if vid is None:
            vid = self.get(node, "id")
        vid, _, iscompvar = self.check_if_comp_var(vid, node=node)

        if iscompvar:
            expect(compclass is not None, "compclass must be specified if is comp var")
            attribute = {"compclass":compclass}
            str_value = self.get_valid_value_string(node, value, vid, ignore_type)
            values = self.get_optional_child("values", root=node)
            node = values if values is not None else node
            val = self.set_element_text("value", str_value, attribute, root=node)
        else:
            val = EntryID._set_value(self, node, value, vid, subgroup, ignore_type)
        return val
예제 #33
0
    def get_children(self, name=None, attributes=None, root=None):
        if self.locked and name == "entry" and attributes is not None and attributes.keys() == ["id"]:
            entry_id = attributes["id"]
            if root is None or self.name(root) == "file":
                if entry_id in self._id_map:
                    return self._id_map[entry_id]
                else:
                    return []
            else:
                expect(self.name(root) == "group", "Unexpected elem '{}' for {}, attrs {}".format(self.name(root), self.filename, self.attrib(root)))
                group_id = self.get(root, "id")
                if group_id in self._group_map and entry_id in self._group_map[group_id]:
                    return [self._group_map[group_id][entry_id]]
                else:
                    return []

        else:
            # Non-compliant look up
            return EntryID.get_children(self, name=name, attributes=attributes, root=root)
예제 #34
0
    def _set_value(self,
                   node,
                   value,
                   vid=None,
                   subgroup=None,
                   ignore_type=False,
                   component=None):
        if vid is None:
            vid = node.get("id")
        vid, _, iscompvar = self.check_if_comp_var(vid, None)

        if iscompvar:
            attribute = {"component": component}
            type_str = self._get_type_info(node)
            val = self.set_element_text("value",
                                        convert_to_string(
                                            value, type_str, vid),
                                        attribute,
                                        root=node)
            return val
        val = EntryID._set_value(self, node, value, vid, subgroup, ignore_type)
        return val
예제 #35
0
파일: env_base.py 프로젝트: lxu16/origin
    def _set_value(self,
                   node,
                   value,
                   vid=None,
                   subgroup=None,
                   ignore_type=False,
                   component=None):
        if vid is None:
            vid = node.get("id")
        vid, _, iscompvar = self.check_if_comp_var(vid, None)

        if iscompvar:
            attribute = {"component": component}
            str_value = self.get_valid_value_string(node, value, vid,
                                                    ignore_type)
            val = self.set_element_text("value",
                                        str_value,
                                        attribute,
                                        root=node)
        else:
            val = EntryID._set_value(self, node, value, vid, subgroup,
                                     ignore_type)
        return val
예제 #36
0
 def change_file(self, newfile, copy=False):
     self.unlock()
     EntryID.change_file(self, newfile, copy=copy)
     self._setup_cache()
예제 #37
0
 def get_nodes_by_id(self, varid):
     varid, _, _ = self.check_if_comp_var(varid, None)
     return EntryID.get_nodes_by_id(self, varid)
예제 #38
0
 def get_nodes_by_id(self, varid):
     varid, _, _ = self.check_if_comp_var(varid, None)
     return EntryID.get_nodes_by_id(self, varid)
예제 #39
0
 def change_file(self, newfile, copy=False):
     self.unlock()
     EntryID.change_file(self, newfile, copy=copy)
     self._setup_cache()
예제 #40
0
 def get_value(self, name, attribute=None, resolved=False, subgroup=None):
     expect(subgroup is None, "This class does not support subgroups")
     return EntryID.get_value(self, name, attribute, resolved)
예제 #41
0
 def scan_children(self, nodename, attributes=None, root=None):
     if self.locked and nodename == "entry" and attributes is not None and attributes.keys() == ["id"]:
         return EnvBase.get_children(self, name=nodename, attributes=attributes, root=root)
     else:
         return EntryID.scan_children(self, nodename, attributes=attributes, root=root)