Пример #1
0
 def _option(feature):
     params = feature.split()
     name = params[0]
     type = params[1][1:]
     default = None
     min = None
     max = None
     var = []
     if type == "combo":
         choices = params[2:]
         for choice in choices:
             if choice == "///":
                 continue
             elif choice[0] == "*":
                 default = choice[1:]
                 var.append(choice[1:])
             else:
                 var.append(choice)
     elif type == "check":
         default = int(params[2])
     elif type in ("string", "file", "path"):
         if len(params) > 2:
             default = params[2]
         else:
             default = ""
     elif type == "spin":
         default = int(params[2])
         min = int(params[3])
         max = int(params[4])
     option = Option(name, type, default, min, max, var)
     self.features.set_option(option.name, option)
     return
Пример #2
0
    def _feature(self, features):
        """
        Does not conform to the CECP spec regarding `done` and instead reads all
        the features atomically.
        """
        if features.startswith("option"):
            features = features.replace("\"", "")
            params = features.split("=")[1].split()
            name = params[0]
            type = params[1][1:]
            default = None
            min = None
            max = None
            var = []
            if type == "combo":
                choices = params[2:]
                for choice in choices:
                    if choice == "///":
                        continue
                    elif choice[0] == "*":
                        default = choice[1:]
                        var.append(choice[1:])
                    else:
                        var.append(choice)
            elif type == "check":
                default = int(params[2])
            elif type in ("string", "file", "path"):
                if len(params) > 2:
                    default = params[2]
                else:
                    default = ""
            elif type == "spin":
                default = int(params[2])
                min = int(params[3])
                max = int(params[4])
            option = Option(name, type, default, min, max, var)
            self.features.set_option(option.name, option)
            return

        features = features.split()
        feature_map = [feature.split("=") for feature in features]
        for (key, value) in feature_map:
            value = value.strip("\"")
            if key == "variant":
                self.features.set_feature(key, value.split(","))
            else:
                self.features.set_feature(key, value)
Пример #3
0
    def _feature(self, features):
        """
        Does not conform to CECP spec regarding `done` and instead reads all
        features atomically.
        """
        if features.startswith("option"):
            features = features.replace("\"", "")
            params = features.split("=")[1].split()
            name = params[0]
            type = params[1][1:]
            min = None
            max = None
            var = []
            if type == "combo":
                choices = params[2:]
                for choice in choices:
                    if choice == "///":
                        continue
                    elif choice[0] == "*":
                        default = choice[1:]
                        var.append(choice[1:])
                    else:
                        var.append(choice)
                print(var)
                print(default)
            else:
                default = int(params[2])
                min = int(params[3])
                max = int(params[4])
            option = Option(name, type, default, min, max, var)
            self.features._features["option"][option.name] = option
            return

        features = features.split()
        feature_map = [feature.split("=") for feature in features]
        for (key, value) in feature_map:
            value = value.strip("\"")
            if key == "variant":
                self.features._set_feature(key, value.split(","))
            else:
                self.features._set_feature(key, value)
Пример #4
0
    def _option(self, arg):
        current_parameter = None

        name = []
        type = []
        default = []
        min = None
        max = None
        current_var = None
        var = []

        for token in arg.split(" "):
            if token == "name" and not name:
                current_parameter = "name"
            elif token == "type" and not type:
                current_parameter = "type"
            elif token == "default" and not default:
                current_parameter = "default"
            elif token == "min" and min is None:
                current_parameter = "min"
            elif token == "max" and max is None:
                current_parameter = "max"
            elif token == "var":
                current_parameter = "var"
                if current_var is not None:
                    var.append(" ".join(current_var))
                current_var = []
            elif current_parameter == "name":
                name.append(token)
            elif current_parameter == "type":
                type.append(token)
            elif current_parameter == "default":
                default.append(token)
            elif current_parameter == "var":
                current_var.append(token)
            elif current_parameter == "min":
                try:
                    min = int(token)
                except ValueError:
                    LOGGER.exception("exception parsing option min")
            elif current_parameter == "max":
                try:
                    max = int(token)
                except ValueError:
                    LOGGER.exception("exception parsing option max")

        if current_var is not None:
            var.append(" ".join(current_var))

        type = " ".join(type)

        default = " ".join(default)
        if type == "check":
            if default == "true":
                default = True
            elif default == "false":
                default = False
            else:
                default = None
        elif type == "spin":
            try:
                default = int(default)
            except ValueError:
                LOGGER.exception("exception parsing option spin default")
                default = None

        option = Option(" ".join(name), type, default, min, max, var)
        self.options[option.name] = option