Ejemplo n.º 1
0
    def __init__(self, recipe_name=None, data=None):
        self.recipe_name = recipe_name
        self.plist = Plist()
        self.recipe = Recipe()
        self.base_recipe_dict = RecipeForm.get_dict_from_recipe_name(
            "base.xml")
        self.recipe_dict = RecipeForm.get_dict_from_recipe_name(
            self.recipe_name)
        self.plist = Plist(self.recipe_dict)
        # If form is filled out
        if data is not None:
            custom_plist = CustomPlist()
            # We parse the expected outputs from the recipe
            for key, value in self.base_recipe_dict['outputs'].items():
                setattr(
                    custom_plist, key,
                    self.get_value_from_post_data(value, data, type(value)))
            for key, value in self.recipe_dict['outputs'].items():
                setattr(
                    custom_plist, key,
                    self.get_value_from_post_data(value, data, type(value)))

            # Then we add recipe information
            self.plist.PayloadContent.append(custom_plist)
            self.plist.PayloadRemovalDisallowed = str_to_bool(
                data.get("PayloadRemovalDisallowed", False))
            self.recipe.group_name = data.get("group_id")
            self.recipe.plist = self.plist
Ejemplo n.º 2
0
 def __init__(self, recipe=None, *args, **kwargs):
     super().__init__(*args, **kwargs)
     if recipe is not None:
         self.PayloadDisplayName = recipe.get('PayloadDisplayName',
                                              '<no name>')
         self.PayloadDescription = recipe.get('PayloadDescription',
                                              '<no description>')
         self.PayloadIdentifier = recipe.get('PayloadIdentifier',
                                             '<no identifier>')
         self.PayloadOrganization = recipe.get('PayloadOrganization',
                                               '<no organization>')
         self.PayloadRemovalDisallowed = recipe.get(
             str_to_bool('PayloadRemovalDisallowed'), False)
         self.PayloadType = recipe.get('PayloadType', '<no type>')
         self.PayloadUUID = str(uuid.uuid1()).upper()
         self.PayloadVersion = str(
             recipe.get('PayloadVersion', '<no version>'))
Ejemplo n.º 3
0
    def __init__(self, recipe_name=None, data=None):
        self.recipe_name = recipe_name
        self.plist = Plist()
        self.recipe = Recipe()
        self.outputs = {}
        self.base_recipe_dict = RecipeForm.get_dict_from_recipe_name("base.xml")
        self.recipe_dict = RecipeForm.get_dict_from_recipe_name(self.recipe_name)
        self.plist = Plist(self.recipe_dict)
        # If form is filled out
        if data is not None:
            self.outputs = self.parse_for_output(self.base_recipe_dict, {})
            self.outputs = self.parse_for_output(self.recipe_dict, self.outputs)
            custom_plist = CustomPlist()
            # We parse the expected outputs from the recipe
            dict_iterate = dict(self.base_recipe_dict['outputs'], **self.recipe_dict['outputs'])
            for key, value in dict_iterate.items():
                setattr(custom_plist, key, self.get_value_from_post_data(value, data))

            # Then we add recipe information
            self.plist.PayloadContent.append(custom_plist)
            self.plist.PayloadRemovalDisallowed = str_to_bool(data.get("PayloadRemovalDisallowed", False))
            self.recipe.group_name = data.get("group_id")
            self.recipe.plist = self.plist
Ejemplo n.º 4
0
    def get_value_from_post_data(self, value, data):
        # $key?(yes):(no)
        match = re.search("^\$(.*)\?\((.*)\):\((.*)\)$", value)
        if match:
            values = dict(key=match.group(1),
                          yes=match.group(2),
                          no=match.groups(3))
            if values['key'] in data:
                return self.get_value_from_post_data(values['yes'], data)
            else:
                return self.get_value_from_post_data(values['no'], data)

        # $key?(yes):
        match = re.search("^\$(.*)\?\((.*)\):$", value)
        if match:
            values = dict(key=match.group(1),
                          yes=match.group(2))
            if values['key'] in data:
                return self.get_value_from_post_data(values['yes'], data)
            return None

        # $key?:(no)
        match = re.search("^\$(.*)\?:\((.*)\)$", value)
        if match:
            values = dict(key=match.group(1),
                          no=match.group(2))
            if values['key'] not in data:
                return self.get_value_from_post_data(values['no'], data)
            return None

        # $key?
        match = re.search("^\$(.*)\?$", value)
        if match:
            values = dict(key=match.group(1))
            if values['key'] in data:
                return self.get_value_from_post_data("$" + values['key'], data)
            return None

        # $key
        match = re.search("^\$(.*)", value)
        if match:
            values = dict(key=match.group(1))
            if values['key'] in data:
                data_type = self.outputs[values['key']]['input_type']
                if data_type == "boolean":
                    return str_to_bool(data[values['key']])
                elif data_type == "integer":
                    return int(data[values['key']])
                else:
                    return data[values['key']]
            return None

        # @UUID
        match = re.search("^@UUID$", value)
        if match:
            return str(uuid.uuid1()).upper()

        # @constant
        match = re.search("^@(.*)", value)
        if match:
            if match.group(1) in ("YES", "NO"):
                return bool(match.group(1))
            return match.group(1)
Ejemplo n.º 5
0
    def get_value_from_post_data(self, value, data):
        # $key?(yes):(no)
        match = re.search("^\$(.*)\?\((.*)\):\((.*)\)$", value)
        if match:
            values = dict(key=match.group(1),
                          yes=match.group(2),
                          no=match.groups(3))
            if values['key'] in data:
                return self.get_value_from_post_data(values['yes'], data)
            else:
                return self.get_value_from_post_data(values['no'], data)

        # $key?(yes):
        match = re.search("^\$(.*)\?\((.*)\):$", value)
        if match:
            values = dict(key=match.group(1), yes=match.group(2))
            if values['key'] in data:
                return self.get_value_from_post_data(values['yes'], data)
            return None

        # $key?:(no)
        match = re.search("^\$(.*)\?:\((.*)\)$", value)
        if match:
            values = dict(key=match.group(1), no=match.group(2))
            if values['key'] not in data:
                return self.get_value_from_post_data(values['no'], data)
            return None

        # $key?
        match = re.search("^\$(.*)\?$", value)
        if match:
            values = dict(key=match.group(1))
            if values['key'] in data:
                return self.get_value_from_post_data("$" + values['key'], data)
            return None

        # $key
        match = re.search("^\$(.*)", value)
        if match:
            values = dict(key=match.group(1))
            if values['key'] in data:
                data_type = self.outputs[values['key']]['input_type']
                if data_type == "boolean":
                    return str_to_bool(data[values['key']])
                elif data_type == "integer":
                    return int(data[values['key']])
                else:
                    return data[values['key']]
            return None

        # @UUID
        match = re.search("^@UUID$", value)
        if match:
            return str(uuid.uuid1()).upper()

        # @constant
        match = re.search("^@(.*)", value)
        if match:
            if match.group(1) in ("YES", "NO"):
                return bool(match.group(1))
            return match.group(1)