'Merge new options with current options, returning changed options.
The new option wins if it is "higher" than the existing option.'

def merge_options(self, **options):

    changed = {}
    for (name, value) in options.items():
        option_type = self.OPTIONS[name][0]
        self.assert_option_value_allowed(option_type, value)
        current = getattr(self, name)
        if (option_type == u'bool'):
            if (value and (not current)):
                changed[name] = value
                setattr(self, name, True)
        elif (option_type == u'int'):
            value = int(value)
            if (value > current):
                changed[name] = value
                setattr(self, name, value)
        elif (option_type == u'int_all'):
            if (text_type(value).lower() == u'all'):
                if (current != u'all'):
                    changed[name] = u'all'
                    setattr(self, name, u'all')
            else:
                value = int(value)
                if (value > current):
                    changed[name] = value
                    setattr(self, name, value)
        else:
            assert (option_type == u'text')
            if (value and (value != current)):
                changed[name] = value
                setattr(self, name, value)
    if changed:
        self.state = self.STATE_INIT
    return changed
