예제 #1
0
 def __init__(self, directory):
     # debugging (note: latter test for windows paths)
     if directory[:1] != "/" and not re.search(r'^[a-zA-Z]:\\', directory):
         Messager.debug(
             "Project config received relative directory ('%s'), configuration may not be found."
             % directory,
             duration=-1)
     self.directory = directory
예제 #2
0
 def __init__(self, projectconf):
     self.data = {}
     self.val = True
     self.projectconf = projectconf
     for t in projectconf.get_entity_types():
         self.data[t] = []
     for t in projectconf.get_event_types():
         self.data[t] = []
     for t in projectconf.get_relation_types():
         self.data[t] = []
     for t in projectconf.get_attribute_types():
         self.data[t] = []
     for t in projectconf.get_equiv_types():
         self.data[t] = []
     try:
         nodes = projectconf.get_rules_type_hierarchy()
         if not nodes:
             raise KeyError
         for node in nodes:
             vrule = ValidationRule(node)
             self.data[vrule.type].append(vrule)
     except KeyError:
         self.val = False
         Messager.debug("No rules defined")
예제 #3
0
 def __init__(self, projectconf):
     self.data = {}
     self.val = True
     self.projectconf = projectconf
     for t in projectconf.get_entity_types():
         self.data[t] = []
     for t in projectconf.get_event_types():
         self.data[t] = []
     for t in projectconf.get_relation_types():
         self.data[t] = []
     for t in projectconf.get_attribute_types():
         self.data[t] = []
     for t in projectconf.get_equiv_types():
         self.data[t] = []
     try:
         nodes = projectconf.get_rules_type_hierarchy()
         if not nodes:
             raise KeyError
         for node in nodes:
             vrule = ValidationRule(node)
             self.data[vrule.type].append(vrule)
     except KeyError:
         self.val = False
         Messager.debug("No rules defined")
예제 #4
0
 def __init__(self, directory):
     # debugging (note: latter test for windows paths)
     if directory[:1] != "/" and not re.search(r'^[a-zA-Z]:\\', directory):
         Messager.debug("Project config received relative directory ('%s'), configuration may not be found." % directory, duration=-1)
     self.directory = directory
예제 #5
0
    def __init__(self, terms, args=[]):
        self.terms, self.args = terms, args

        if len(terms) == 0 or len([t for t in terms if t == ""]) != 0:
            Messager.debug("Empty term in configuration" % (a, args), duration=-1)
            raise InvalidProjectConfigException

        # unused if any of the terms marked with "!"
        self.unused = False
        for i in range(len(self.terms)):
            if self.terms[i][0] == "!":
                self.terms[i]= self.terms[i][1:]
                self.unused = True
        self.children = []

        # The first of the listed terms is used as the primary term for
        # storage. Due to format restrictions, this form must not have
        # e.g. space or other forms.
        self.__primary_term = normalize_to_storage_form(self.terms[0])
        # TODO: this might not be the ideal place to put this warning
        if self.__primary_term != self.terms[0]:
            Messager.warning("Note: in configuration, term '%s' is not appropriate for storage (should match '^[a-zA-Z0-9_-]*$'), using '%s' instead. (Revise configuration file to get rid of this message. Terms other than the first are not subject to this restriction.)" % (self.terms[0], self.__primary_term), -1)
            self.terms[0] = self.__primary_term

        # TODO: cleaner and more localized parsing
        self.arguments = {}
        self.arg_list = []
        self.mandatory_arguments = []
        self.multiple_allowed_arguments = []
        self.keys_by_type = {}
        for a in self.args:
            a = a.strip()
            m = re.match(r'^(.*?):(.*)$', a)
            if not m:
                Messager.warning("Project configuration: Failed to parse argument %s (args: %s)" % (a, args), 5)
                raise InvalidProjectConfigException
            key, atypes = m.groups()

            if key[-1:] not in ("?", "*"):
                mandatory_key = True
            else:
                mandatory_key = False

            if key[-1:] in ("*", "+"):
                multiple_allowed = True
            else:
                multiple_allowed = False

            if key[-1:] in ("?", "*", "+"):
                key = key[:-1]

            if key in self.arguments:
                Messager.warning("Project configuration: error parsing: %s argument '%s' appears multiple times." % key, 5)
                raise InvalidProjectConfigException

            self.arg_list.append(key)
            
            if mandatory_key:
                self.mandatory_arguments.append(key)

            if multiple_allowed:
                self.multiple_allowed_arguments.append(key)

            for atype in atypes.split("|"):
                if atype.strip() == "":
                    Messager.warning("Project configuration: error parsing: empty type for argument '%s'." % a, 5)
                    raise InvalidProjectConfigException

                # Check disabled; need to support arbitrary UTF values for attributes.conf.
                # TODO: consider checking for similar for appropriate confs.
#                 if atype not in reserved_macro_string and normalize_to_storage_form(atype) != atype:
#                     Messager.warning("Project configuration: '%s' is not a valid argument (should match '^[a-zA-Z0-9_-]*$')" % atype, 5)
#                     raise InvalidProjectConfigException

                if key not in self.arguments:
                    self.arguments[key] = []
                self.arguments[key].append(atype)

                if atype not in self.keys_by_type:
                    self.keys_by_type[atype] = []
                self.keys_by_type[atype].append(key)
예제 #6
0
    def __init__(self, terms, args=[]):
        self.terms, self.args = terms, args

        if len(terms) == 0 or len([t for t in terms if t == ""]) != 0:
            Messager.debug("Empty term in configuration" % (a, args),
                           duration=-1)
            raise InvalidProjectConfigException

        # unused if any of the terms marked with "!"
        self.unused = False
        for i in range(len(self.terms)):
            if self.terms[i][0] == "!":
                self.terms[i] = self.terms[i][1:]
                self.unused = True
        self.children = []

        # The first of the listed terms is used as the primary term for
        # storage. Due to format restrictions, this form must not have
        # e.g. space or other forms.
        self.__primary_term = normalize_to_storage_form(self.terms[0])
        # TODO: this might not be the ideal place to put this warning
        if self.__primary_term != self.terms[0]:
            Messager.warning(
                "Note: in configuration, term '%s' is not appropriate for storage (should match '^[a-zA-Z0-9_-]*$'), using '%s' instead. (Revise configuration file to get rid of this message. Terms other than the first are not subject to this restriction.)"
                % (self.terms[0], self.__primary_term), -1)
            self.terms[0] = self.__primary_term

        # TODO: cleaner and more localized parsing
        self.arguments = {}
        self.arg_list = []
        self.mandatory_arguments = []
        self.multiple_allowed_arguments = []
        self.keys_by_type = {}
        for a in self.args:
            a = a.strip()
            m = re.match(r'^(.*?):(.*)$', a)
            if not m:
                Messager.warning(
                    "Project configuration: Failed to parse argument %s (args: %s)"
                    % (a, args), 5)
                raise InvalidProjectConfigException
            key, atypes = m.groups()

            if key[-1:] not in ("?", "*"):
                mandatory_key = True
            else:
                mandatory_key = False

            if key[-1:] in ("*", "+"):
                multiple_allowed = True
            else:
                multiple_allowed = False

            if key[-1:] in ("?", "*", "+"):
                key = key[:-1]

            if key in self.arguments:
                Messager.warning(
                    "Project configuration: error parsing: %s argument '%s' appears multiple times."
                    % key, 5)
                raise InvalidProjectConfigException

            self.arg_list.append(key)

            if mandatory_key:
                self.mandatory_arguments.append(key)

            if multiple_allowed:
                self.multiple_allowed_arguments.append(key)

            for atype in atypes.split("|"):
                if atype.strip() == "":
                    Messager.warning(
                        "Project configuration: error parsing: empty type for argument '%s'."
                        % a, 5)
                    raise InvalidProjectConfigException

                # Check disabled; need to support arbitrary UTF values for attributes.conf.
                # TODO: consider checking for similar for appropriate confs.


#                 if atype not in reserved_macro_string and normalize_to_storage_form(atype) != atype:
#                     Messager.warning("Project configuration: '%s' is not a valid argument (should match '^[a-zA-Z0-9_-]*$')" % atype, 5)
#                     raise InvalidProjectConfigException

                if key not in self.arguments:
                    self.arguments[key] = []
                self.arguments[key].append(atype)

                if atype not in self.keys_by_type:
                    self.keys_by_type[atype] = []
                self.keys_by_type[atype].append(key)