def combine(self, *args):
        """
        Combine the provided values according to the method for this
        configuration item. Order matters -- values are assumed to be
        in the order they were specified by the user. The resulting value
        is also checked to patch the specified type.

        """
        args = [a for a in args if a is not None]
        if not args:
            return self.valid_categories[self.category]
        if self.method == 'keep' or len(args) == 1:
            value = args[0]
        elif self.method == 'replace':
            value = args[-1]
        elif self.method == 'merge':
            if self.category == 'list':
                value = merge_lists(*args, duplicates='last', dict_type=OrderedDict)
            elif self.category == 'dict':
                value = merge_dicts(*args,
                                    should_merge_lists=True,
                                    should_normalize=False,
                                    list_duplicates='last',
                                    dict_type=OrderedDict)
            else:
                raise ValueError('Unexpected category for merge : "{}"'.format(self.category))
        elif callable(self.method):
            value = self.method(*args)
        else:
            raise ValueError('Unexpected method: "{}"'.format(self.method))

        return value
Exemplo n.º 2
0
 def set(self, param, value):
     if param in [
             'id', 'section_id', 'number_of_iterations', 'workload_name',
             'label'
     ]:
         if value is not None:
             setattr(self, param, value)
     elif param in [
             'boot_parameters', 'runtime_parameters', 'workload_parameters',
             'flash'
     ]:
         setattr(
             self, param,
             merge_dicts(getattr(self, param),
                         value,
                         list_duplicates='last',
                         dict_type=OrderedDict,
                         should_normalize=False))
     elif param in ['instrumentation']:
         setattr(
             self, param,
             merge_lists(getattr(self, param), value, duplicates='last'))
     else:
         raise ValueError(
             'Unexpected workload spec parameter: {}'.format(param))
Exemplo n.º 3
0
    def combine(self, *args):
        """
        Combine the provided values according to the method for this
        configuration item. Order matters -- values are assumed to be
        in the order they were specified by the user. The resulting value
        is also checked to patch the specified type.

        """
        args = [a for a in args if a is not None]
        if not args:
            return self.valid_categories[self.category]
        if self.method == 'keep' or len(args) == 1:
            value = args[0]
        elif self.method == 'replace':
            value = args[-1]
        elif self.method == 'merge':
            if self.category == 'list':
                value = merge_lists(*args,
                                    duplicates='last',
                                    dict_type=OrderedDict)
            elif self.category == 'dict':
                value = merge_dicts(*args,
                                    should_merge_lists=True,
                                    should_normalize=False,
                                    list_duplicates='last',
                                    dict_type=OrderedDict)
            else:
                raise ValueError('Unexpected category for merge : "{}"'.format(
                    self.category))
        elif callable(self.method):
            value = self.method(*args)
        else:
            raise ValueError('Unexpected method: "{}"'.format(self.method))

        return value
 def set(self, param, value):
     if param in ['id', 'section_id', 'number_of_iterations', 'workload_name', 'label']:
         if value is not None:
             setattr(self, param, value)
     elif param in ['boot_parameters', 'runtime_parameters', 'workload_parameters', 'flash', 'classifiers']:
         setattr(self, param, merge_dicts(getattr(self, param), value, list_duplicates='last',
                                          dict_type=OrderedDict, should_normalize=False))
     elif param in ['instrumentation']:
         setattr(self, param, merge_lists(getattr(self, param), value, duplicates='last'))
     else:
         raise ValueError('Unexpected workload spec parameter: {}'.format(param))
Exemplo n.º 5
0
 def _set_raw_list(self, name, value):
     old_value = self._raw_config.get(name, [])
     new_value = merge_lists(old_value, value, duplicates='last')
     self._raw_config[identifier(name)] = new_value
 def _set_raw_list(self, name, value):
     old_value = self._raw_config.get(name, [])
     new_value = merge_lists(old_value, value, duplicates='last')
     self._raw_config[identifier(name)] = new_value
 def set_load_defaults(self, value):
     self._load_defaults = value
     if value:
         self.packages = merge_lists(self.default_packages,
                                     self.packages,
                                     duplicates='last')
Exemplo n.º 8
0
 def test_merge_lists(self):
     result = merge_lists([1, 2, 3], 7)
     assert_equal(result, [1, 2, 3, 7])
     result = merge_lists([1, 2, 3], 1, duplicates='last')
     assert_equal(result, [2, 3, 1])
 def set_load_defaults(self, value):
     self._load_defaults = value
     if value:
         self.packages = merge_lists(self.default_packages, self.packages, duplicates='last')