Beispiel #1
0
    def check_version(self, min_version, max_version, main_node):
        if min_version is None and max_version is None:  # any version is OK
            return True

        if min_version is None:
            min_version = float('-inf')
        if max_version is None:
            max_version = float('inf')

        min_version = VersionWrapper(min_version)
        max_version = VersionWrapper(max_version)

        parse_context = ParseContext(self.execution_context)
        version_parser = Choice([
            PostProcessNodeParser(StringLiteral(ErrorHandler.IGNORE),
                                  VersionWrapper),
            EnumParser({PREFIX + 'fromPackageVersion': _FromPackageVersion()})
        ])
        lang_min_version = ZeroOnePredicate(URIRef(PREFIX + "langMinVersion"), version_parser, ErrorHandler.FATAL). \
            parse(parse_context, self.graph, main_node)
        lang_max_version = ZeroOnePredicate(URIRef(PREFIX + "langMaxVersion"), version_parser, ErrorHandler.FATAL). \
            parse(parse_context, self.graph, main_node)
        lang_min_version = lang_min_version or VersionWrapper(float('-inf'))
        lang_max_version = lang_max_version or VersionWrapper(float('inf'))

        # First try to check without retrieving package version (for efficiency)
        if not isinstance(
                lang_min_version,
                _FromPackageVersion) and max_version < lang_min_version:
            return False
        if not isinstance(
                lang_max_version,
                _FromPackageVersion) and min_version > lang_max_version:
            return False

        pmin_version = ZeroOnePredicate(URIRef(PREFIX + "packageMinVersion"), StringLiteral(ErrorHandler.FATAL), ErrorHandler.FATAL). \
            parse(parse_context, self.graph, main_node)
        pmax_version = ZeroOnePredicate(URIRef(PREFIX + "packageMaxVersion"), StringLiteral(ErrorHandler.FATAL), ErrorHandler.FATAL). \
            parse(parse_context, self.graph, main_node)
        if lang_min_version is _FromPackageVersion or lang_max_version is _FromPackageVersion or \
                pmin_version is not None or pmax_version is not None:
            try:
                package = OnePredicate(URIRef(PREFIX + "debianPackage"), StringLiteral(ErrorHandler.FATAL), ErrorHandler.IGNORE). \
                    parse(parse_context, self.graph, main_node)
            except ParseException:
                return False
            real_version = ThePackageManaging.determine_package_version(
                package)
            if real_version is None:  # no such Debian package
                return False
            if lang_min_version is _FromPackageVersion:
                if VersionWrapper(real_version) > max_version:
                    return False
            if lang_max_version is _FromPackageVersion:
                if VersionWrapper(real_version) < min_version:
                    return False
            if (pmin_version is not None and VersionWrapper(real_version) < VersionWrapper(pmin_version)) or \
                    (pmax_version is not None and VersionWrapper(real_version) > VersionWrapper(pmax_version)):
                return False
        return True
Beispiel #2
0
 def construct_command_line(self, node, script_str, params, inline=False):
     """
     :param node:
     :param script_str:
     :param params: script params, a list of 2-tuples
     :param inline: use inline script, not scriptURL
     :return: a list of strings
     """
     parse_context = InterpreterParseContext(self.execution_context,
                                             script_str, params)
     pred = URIRef(PREFIX +
                   ('inlineCommand' if inline else 'scriptCommand'))
     parser = ZeroOnePredicate(pred, MainParser(), ErrorHandler.FATAL)
     return parser.parse(parse_context, self.graph, node)
Beispiel #3
0
    def parse(self, parse_context, graph, node):
        klass = URIRef(MAIN_NAMESPACE + "Command")
        check_node_class(self.subclasses, parse_context, graph, node, klass,
                         ErrorMode.IGNORE)

        base = BaseScriptInfoParser(self.transformer, self.script_kind).parse(
            parse_context, graph, node)
        more = CommandScriptInfo()

        str1_parser = ZeroOnePredicate(URIRef(MAIN_NAMESPACE + "scriptURL"),
                                       IRILiteral(ErrorMode.WARNING),
                                       ErrorMode.WARNING)
        str1 = str1_parser.parse(parse_context, graph, node)
        str2_parser = ZeroOnePredicate(
            URIRef(MAIN_NAMESPACE + "commandString"),
            StringLiteral(ErrorMode.WARNING), ErrorMode.WARNING)
        str2 = str2_parser.parse(parse_context, graph, node)
        # if str1 is None and str2 is None:
        #     msg = parse_context.translate("Both :scriptURL and :commandString can't be missing in node {node}.").format(node=node)
        #     parse_context.throw(ErrorMode.WARNING, msg)
        if str1 is not None and str2 is not None:
            msg = parse_context.translate(
                "Both :scriptURL and :commandString can't be present in node {node}."
            ).format(node=node)
            parse_context.throw(ErrorMode.WARNING, msg)
        more.script_url = str1
        more.command_string = str2

        if not more.script_url and len(more.params) != 0:

            def s():
                return parse_context.translate("Cannot provide params for commandString script {node}.").\
                    format(node=node)

            parse_context.throw(ErrorMode.FATAL, s)

        min_parser = ZeroOnePredicate(URIRef(MAIN_NAMESPACE + "minVersion"),
                                      StringLiteral(ErrorMode.WARNING),
                                      ErrorMode.WARNING)
        more.min_version = min_parser.parse(parse_context, graph, node)
        max_parser = ZeroOnePredicate(URIRef(MAIN_NAMESPACE + "maxVersion"),
                                      StringLiteral(ErrorMode.WARNING),
                                      ErrorMode.WARNING)
        more.max_version = max_parser.parse(parse_context, graph, node)

        language_parser = OnePredicate(URIRef(MAIN_NAMESPACE + "language"),
                                       IRILiteral(ErrorMode.WARNING),
                                       ErrorMode.WARNING)
        more.language = language_parser.parse(parse_context, graph, node)

        params_parser = ZeroOnePredicate(URIRef(MAIN_NAMESPACE + "params"),
                                         ListParser(_ParamParser(),
                                                    ErrorMode.FATAL),
                                         ErrorMode.WARNING,
                                         default_value=[])
        more.params = params_parser.parse(parse_context, graph, node)

        return ScriptInfo(base=base, more=more)
Beispiel #4
0
    def parse(self, parse_context, graph, node):
        result = BaseScriptInfo(transformer=self.transformer,
                                ns=node,
                                script_kind=self.script_kind)
        float_parser = FloatLiteral(ErrorMode.WARNING)

        def float_msg():
            return parse_context.translate(
                "Preservance, stability, and preference for the node {node} should be 0..1"
                .format(node))

        float_parser = CheckedNodeParser(float_parser, _check_numrange,
                                         ErrorMode.WARNING, float_msg)
        preservance_parser = ZeroOnePredicate(
            URIRef(MAIN_NAMESPACE + "preservance"), float_parser, 1.0,
            ErrorMode.WARNING)
        stability_parser = ZeroOnePredicate(
            URIRef(MAIN_NAMESPACE + "stability"), float_parser, 1.0,
            ErrorMode.WARNING)
        preference_parser = ZeroOnePredicate(
            URIRef(MAIN_NAMESPACE + "preference"), float_parser, 1.0,
            ErrorMode.WARNING)
        result.preservance = preservance_parser.parse(parse_context, graph,
                                                      node)
        result.stability = stability_parser.parse(parse_context, graph, node)
        result.preference = preference_parser.parse(parse_context, graph, node)
        if self.script_kind == ScriptKindEnum.TRANSFORMER:
            transformer_kind_parser = OnePredicate(
                URIRef(MAIN_NAMESPACE + "transformerKind"),
                Providers.transformer_kind_parser(), ErrorMode.WARNING)
            result.transformer_kind = transformer_kind_parser.parse(
                parse_context, graph, node)
        elif self.script_kind == ScriptKindEnum.VALIDATOR:
            result.validator_kind = Providers.validator_kind_parser().parse(
                parse_context, graph, node)
        ok_result_node_parser = StringLiteral(ErrorMode.WARNING)
        ok_result_parser = ZeroOnePredicate(
            URIRef(MAIN_NAMESPACE + "okResult"), ok_result_node_parser,
            ErrorMode.WARNING)
        result.ok_result = ok_result_parser.parse(parse_context, graph, node)
        return result
    def parse(self, parse_context, graph, node):
        klass = URIRef(MAIN_NAMESPACE + "Transformer")
        check_node_class(self.subclasses, parse_context, graph, node, klass,
                         ErrorHandler.IGNORE)

        result = Transformer()

        source_namespaces_parser = OneOrMorePredicate(
            URIRef(MAIN_NAMESPACE + "sourceNamespace"),
            IRILiteral(ErrorHandler.WARNING), ErrorHandler.WARNING)
        result.source_namespaces = source_namespaces_parser.parse(
            parse_context, graph, node)
        target_namespaces_parser = ZeroOrMorePredicate(
            URIRef(MAIN_NAMESPACE + "targetNamespace"),
            IRILiteral(ErrorHandler.WARNING))
        result.target_namespaces = target_namespaces_parser.parse(
            parse_context, graph, node)

        precedence_parser = ZeroOnePredicate(
            URIRef(MAIN_NAMESPACE + "precedence"),
            IRILiteral(ErrorHandler.WARNING), ErrorHandler.WARNING)
        result.precedence = precedence_parser.parse(parse_context, graph, node)
        inwardness_parser = ZeroOnePredicate(
            URIRef(MAIN_NAMESPACE + "inward"),
            BooleanLiteral(ErrorHandler.WARNING), ErrorHandler.WARNING, True)
        result.inwardness = inwardness_parser.parse(parse_context, graph, node)
        ignore_target_parser = ZeroOnePredicate(
            URIRef(MAIN_NAMESPACE + "ignoreTarget"),
            BooleanLiteral(ErrorHandler.WARNING), ErrorHandler.WARNING)
        result.ignore_target = ignore_target_parser.parse(
            parse_context, graph, node)
        universal_parser = ZeroOnePredicate(
            URIRef(MAIN_NAMESPACE + "universal"),
            BooleanLiteral(ErrorHandler.WARNING), ErrorHandler.WARNING)
        result.universal = universal_parser.parse(parse_context, graph, node)

        script_node_parser = ScriptInfoParser(result, self.subclasses,
                                              ScriptKindEnum.TRANSFORMER)
        script_parser = OneOrMorePredicate(URIRef(
            (MAIN_NAMESPACE + "script")), script_node_parser,
                                           ErrorHandler.WARNING)
        result.scripts = script_parser.parse(parse_context, graph, node)

        return result
Beispiel #6
0
 def parse(self, parse_context, graph, node):
     result = BaseScriptInfo(transformer=self.transformer,
                             script_kind=self.script_kind)
     # TODO: Check 0..1 range
     float_parser = FloatLiteral(ErrorHandler.WARNING)
     preservance_parser = ZeroOnePredicate(
         URIRef(MAIN_NAMESPACE + "preservance"), float_parser, 1.0,
         ErrorHandler.WARNING)
     stability_parser = ZeroOnePredicate(
         URIRef(MAIN_NAMESPACE + "stability"), float_parser, 1.0,
         ErrorHandler.WARNING)
     preference_parser = ZeroOnePredicate(
         URIRef(MAIN_NAMESPACE + "preference"), float_parser, 1.0,
         ErrorHandler.WARNING)
     result.preservance = preservance_parser.parse(parse_context, graph,
                                                   node)
     result.stability = stability_parser.parse(parse_context, graph, node)
     result.preference = preference_parser.parse(parse_context, graph, node)
     if self.script_kind == ScriptKindEnum.TRANSFORMER:
         transformer_kind_parser = OnePredicate(
             URIRef(MAIN_NAMESPACE + "transformerKind"),
             Providers.transformer_kind_parser(), ErrorHandler.WARNING)
         result.transformer_kind = transformer_kind_parser.parse(
             parse_context, graph, node)
     elif self.script_kind == ScriptKindEnum.VALIDATOR:
         result.validator_kind = Providers.validator_kind_parser().parse(
             parse_context, graph, node)
     ok_result_node_parser = StringLiteral(ErrorHandler.WARNING)
     ok_result_parser = ZeroOnePredicate(
         URIRef(MAIN_NAMESPACE + "okResult"), ok_result_node_parser,
         ErrorHandler.WARNING)
     result.ok_result = ok_result_parser.parse(parse_context, graph, node)
     return result