예제 #1
0
    def _parse_global_options(self, item: Element) -> (dict, dict):
        """
        Parse global options within the xml
        :param item: Global Tag
        :return: dictionary of configuration items.
                list of actions.
        """
        global_misc = {}
        global_actions = {}

        for sub_item in item.iterchildren():
            if isinstance(sub_item.tag, str):
                if sub_item.tag.lower() == "pref":
                    config_param = ConfigParam()
                    config_param.parse_config_item(sub_item)
                    global_misc[config_param.name] = config_param

                if sub_item.tag.lower() == "action":
                    action = Action("", False, dict())
                    action.parse_action(sub_item)
                    default = sub_item.get("DEFAULT")
                    if not default:
                        raise ValueError(
                            "Auction Parser Error: missing name at line {0}".
                            format(str(sub_item.sourceline)))
                    else:
                        action.default_action = ParseFormats.parse_bool(
                            default)
                    global_actions[action.name] = action

        return global_misc, global_actions
예제 #2
0
    def parse_action(self, node: Element):
        """
        parsers an action from a xml element.
        :param node: xml node.
        """

        action_name = node.get("NAME").lower()

        # Verifies that a name was given to the action.
        if not action_name:
            raise ValueError("Auction Parser Error: missing name at line {0}".format(str(node.sourceline)))

        self.name = action_name

        for item in node.iterchildren():
            if isinstance(item.tag, str):
                if item.tag.lower() == "pref":
                    config_param = ConfigParam()
                    config_param.parse_config_item(item)
                    self.add_config_item(config_param)
예제 #3
0
    def _parse_interval(self, node: Element, start_at_least: datetime, resource_request_key: str) -> (
    datetime, Interval):
        """
        Parses an interval
        :param node: xml node
        :param start_at_least:start datetime
        :param resource_request_key: resource requets key
        :return: start date time for the interval and interval parsed.
        """
        misc_config = {}
        for subitem in node.iterchildren():
            if isinstance(subitem.tag, str):
                if subitem.tag.lower() == "pref":
                    config_param = ConfigParam()
                    config_param.parse_config_item(subitem)
                    misc_config[config_param.name] = config_param

        interval_dict = self._convert_interal_dict(misc_config)

        new_interval = ResourceRequestInterval(resource_request_key)
        new_interval.parse_interval(interval_dict, start_at_least)
        return new_interval.stop, new_interval
예제 #4
0
    def _parse_auction(self, node: Element, global_set: str,
                       global_misc_config: dict, global_actions: dict,
                       field_container: IpapFieldContainer):
        """
        Parses an auction node in the xml.

        :param node: Element  element to parse
        :param global_set: str global set
        :param global_misc_config: dict  dictionary with miscelaneous field configurations.
        :param global_actions: dict  dictionary with actions
        :param field_container: IpapFieldContainer container with all fields in the system.
        :return:
        """
        # get the Id property
        # deep copy global dictionaries, so we can overide them
        misc_config = deepcopy(global_misc_config)
        actions = deepcopy(global_actions)

        auction_id = node.get("ID").lower()
        (set_name, name) = self.parse_name(auction_id)
        if not set_name:
            if global_set.isnumeric():
                set_name = global_set
            else:
                set_name = str(self.domain)

        # Get Resource set and resource Id
        resurce_set = node.get("RESOURCE_SET").lower()
        resource_id = node.get("RESOURCE_ID").lower()

        templ_fields = {}

        # Iterates over children nodes
        for subitem in node.iterchildren():
            if isinstance(subitem.tag, str):
                if subitem.tag.lower() == "pref":
                    config_param = ConfigParam()
                    config_param.parse_config_item(subitem)
                    misc_config[config_param.name] = config_param

                elif subitem.tag.lower() == "field":
                    field_name, field = self._parse_field(subitem)
                    templ_fields[field_name] = field

                elif subitem.tag.lower() == "action":
                    action = Action("", False, dict())
                    action.parse_action(subitem)
                    action.default_action = True  # This is the default action,
                    actions[action.name] = action

        # get the default action
        action_default = None
        for action_name in actions:
            if actions[action.name].default_action:
                action_default = action

        auction_key = set_name + '.' + name
        resource_key = resurce_set + '.' + resource_id
        auction = Auction(auction_key, resource_key, action_default,
                          misc_config)
        templates = auction.build_templates(templ_fields)

        return auction, templates