chrome/test/mini_installer/registry_operations.py
def CleanRegistryEntry(expectation_name, expectation, variable_expander):
    """Cleans registry keys and/or values based on expectations.

    Args:
        expectation_name: The registry key being cleaned.
        expectation: A dictionary describing the state of the key:
            'exists': Either the string 'forbidden', indicating that the key is
                to be deleted if it is found, or the string 'optional',
                indicating that specific values in the key are to be deleted if
                the key exists.
            'values' (optional): For a key with 'optional' existence, a
                dictionary mapping value names to empty dicts, indicating that
                the values are to be deleted.
        variable_expander: A VariableExpander object.

    Raises:
        AssertionError: If an expectation is not satisfied.
        WindowsError: If an error occurs while cleaning the registry.
    """
    key = variable_expander.Expand(expectation_name)
    assert not expectation['exists'] == 'required', (
        'Invalid expectation for CleanRegistryEntry operation: \'exists\' ' +
        'property for key %s must not be \'required\'' % key)
    root_key, sub_key = key.split('\\', 1)

    registry_view = _winreg.KEY_WOW64_32KEY
    if 'wow_key' in expectation:
        registry_view = _RegistryViewConstant(expectation['wow_key'])
    elif variable_expander.Expand('$MINI_INSTALLER_BITNESS') == '64':
        registry_view = _winreg.KEY_WOW64_64KEY

    try:
        # Query the Windows registry for the registry key. It will throw a
        # WindowsError if the key doesn't exist.
        key_handle = _winreg.OpenKey(_RootKeyConstant(root_key), sub_key, 0,
                                     (_winreg.KEY_SET_VALUE | registry_view))
    except WindowsError:
        # There is nothing to clean if the key doesn't exist.
        return

    if expectation['exists'] == 'forbidden':
        # RegDeleteTree must be called with a handle on some parent of the key
        # to be deleted in order for it to remove the key itself and not only
        # its values and subkeys. Open the root of the hive with the proper
        # permissions, then delete the key by name.
        key_handle = None
        root_handle = _winreg.OpenKey(
            _RootKeyConstant(root_key), None, 0,
            (win32con.DELETE | _winreg.KEY_ENUMERATE_SUB_KEYS
             | _winreg.KEY_QUERY_VALUE | _winreg.KEY_SET_VALUE
             | registry_view))
        win32api.RegDeleteTree(root_handle, sub_key)
        LOGGER.info('CleanRegistryEntry deleted key %s' % key)
        return

    assert 'values' in expectation and expectation['values'], (
        'Invalid expectation for CleanRegistryEntry operation: a \'values\' ' +
        'dictionary is required for optional key %s' % key)
    for value, value_expectation in expectation['values'].iteritems():
        value = variable_expander.Expand(value)
        assert 'type' not in value_expectation, (
            'Invalid expectation for CleanRegistryEntry operation: value ' +
            '%s\\%s must not specify a \'type\'' % (key, value))
        try:
            _winreg.DeleteValue(key_handle, value)
            LOGGER.info('CleanRegistryEntry deleted value %s\\%s' %
                        (key, value))
        except WindowsError as e:
            if e.winerror == winerror.ERROR_FILE_NOT_FOUND:
                continue
            raise
Cleans registry keys and/or values based on expectations.

    Args:
        expectation_name: The registry key being cleaned.
        expectation: A dictionary describing the state of the key:
            'exists': Either the string 'forbidden', indicating that the key is
                to be deleted if it is found, or the string 'optional',
                indicating that specific values in the key are to be deleted if
                the key exists.
            'values' (optional): For a key with 'optional' existence, a
                dictionary mapping value names to empty dicts, indicating that
                the values are to be deleted.
        variable_expander: A VariableExpander object.

    Raises:
        AssertionError: If an expectation is not satisfied.
        WindowsError: If an error occurs while cleaning the registry.
    
Cleans registry keys and/or values based on expectations.
Cleans registry keys and / or values based on expectations .
def CleanRegistryEntry(expectation_name, expectation, variable_expander):
    key = variable_expander.Expand(expectation_name)
    assert not expectation['exists'] == 'required', (
        'Invalid expectation for CleanRegistryEntry operation: \'exists\' ' +
        'property for key %s must not be \'required\'' % key)
    root_key, sub_key = key.split('\\', 1)
    registry_view = _winreg.KEY_WOW64_32KEY
    if 'wow_key' in expectation:
        registry_view = _RegistryViewConstant(expectation['wow_key'])
    elif variable_expander.Expand('$MINI_INSTALLER_BITNESS') == '64':
        registry_view = _winreg.KEY_WOW64_64KEY
    try:
        key_handle = _winreg.OpenKey(_RootKeyConstant(root_key), sub_key, 0,
                                     (_winreg.KEY_SET_VALUE | registry_view))
    except WindowsError:
        return
    if expectation['exists'] == 'forbidden':
        key_handle = None
        root_handle = _winreg.OpenKey(
            _RootKeyConstant(root_key), None, 0,
            (win32con.DELETE | _winreg.KEY_ENUMERATE_SUB_KEYS
             | _winreg.KEY_QUERY_VALUE | _winreg.KEY_SET_VALUE
             | registry_view))
        win32api.RegDeleteTree(root_handle, sub_key)
        LOGGER.info('CleanRegistryEntry deleted key %s' % key)
        return
    assert 'values' in expectation and expectation['values'], (
        'Invalid expectation for CleanRegistryEntry operation: a \'values\' ' +
        'dictionary is required for optional key %s' % key)
    for value, value_expectation in expectation['values'].iteritems():
        value = variable_expander.Expand(value)
        assert 'type' not in value_expectation, (
            'Invalid expectation for CleanRegistryEntry operation: value ' +
            '%s\\%s must not specify a \'type\'' % (key, value))
        try:
            _winreg.DeleteValue(key_handle, value)
            LOGGER.info('CleanRegistryEntry deleted value %s\\%s' %
                        (key, value))
        except WindowsError as e:
            if e.winerror == winerror.ERROR_FILE_NOT_FOUND:
                continue
            raise
def CleanRegistryEntry ( expectation_name , expectation , variable_expander ) : key = variable_expander . Expand ( expectation_name ) assert not expectation [ 'exists' ] == 'required' , ( 'Invalid expectation for CleanRegistryEntry operation: \'exists\' ' + 'property for key %s must not be \'required\'' % key ) root_key , sub_key = key . split ( '\\' , 1 ) registry_view = _winreg . KEY_WOW64_32KEY if 'wow_key' in expectation : registry_view = _RegistryViewConstant ( expectation [ 'wow_key' ] ) elif variable_expander . Expand ( '$MINI_INSTALLER_BITNESS' ) == '64' : registry_view = _winreg . KEY_WOW64_64KEY try : key_handle = _winreg . OpenKey ( _RootKeyConstant ( root_key ) , sub_key , 0 , ( _winreg . KEY_SET_VALUE | registry_view ) ) except WindowsError : return if expectation [ 'exists' ] == 'forbidden' : key_handle = None root_handle = _winreg . OpenKey ( _RootKeyConstant ( root_key ) , None , 0 , ( win32con . DELETE | _winreg . KEY_ENUMERATE_SUB_KEYS | _winreg . KEY_QUERY_VALUE | _winreg . KEY_SET_VALUE | registry_view ) ) win32api . RegDeleteTree ( root_handle , sub_key ) LOGGER . info ( 'CleanRegistryEntry deleted key %s' % key ) return assert 'values' in expectation and expectation [ 'values' ] , ( 'Invalid expectation for CleanRegistryEntry operation: a \'values\' ' + 'dictionary is required for optional key %s' % key ) for value , value_expectation in expectation [ 'values' ] . iteritems ( ) : value = variable_expander . Expand ( value ) assert 'type' not in value_expectation , ( 'Invalid expectation for CleanRegistryEntry operation: value ' + '%s\\%s must not specify a \'type\'' % ( key , value ) ) try : _winreg . DeleteValue ( key_handle , value ) LOGGER . info ( 'CleanRegistryEntry deleted value %s\\%s' % ( key , value ) ) except WindowsError as e : if e . winerror == winerror . ERROR_FILE_NOT_FOUND : continue raise
Cleans registry keys and/or values based on expectations.
Cleans registry keys and / or values based on expectations .
"""Cleans registry keys and/or values based on expectations.

    Args:
        expectation_name: The registry key being cleaned.
        expectation: A dictionary describing the state of the key:
            'exists': Either the string 'forbidden', indicating that the key is
                to be deleted if it is found, or the string 'optional',
                indicating that specific values in the key are to be deleted if
                the key exists.
            'values' (optional): For a key with 'optional' existence, a
                dictionary mapping value names to empty dicts, indicating that
                the values are to be deleted.
        variable_expander: A VariableExpander object.

    Raises:
        AssertionError: If an expectation is not satisfied.
        WindowsError: If an error occurs while cleaning the registry.
    """ # Query the Windows registry for the registry key. It will throw a # WindowsError if the key doesn't exist. # There is nothing to clean if the key doesn't exist. # RegDeleteTree must be called with a handle on some parent of the key # to be deleted in order for it to remove the key itself and not only # its values and subkeys. Open the root of the hive with the proper # permissions, then delete the key by name.
If an expectation is not satisfied.
If an expectation is not satisfied .
AssertionError
If an error occurs while cleaning the registry.
If an error occurs while cleaning the registry .
WindowsError
expectation_name
The registry key being cleaned.
The registry key being cleaned .
expectation
A dictionary describing the state of the key:
'exists': Either the string 'forbidden', indicating that the key is
to be deleted if it is found, or the string 'optional',
indicating that specific values in the key are to be deleted if
the key exists.
'values' (optional): For a key with 'optional' existence, a
dictionary mapping value names to empty dicts, indicating that
the values are to be deleted.
A dictionary describing the state of the key : ' exists ' : Either the string ' forbidden ' indicating that the key is to be deleted if it is found or the string ' optional ' indicating that specific values in the key are to be deleted if the key exists . ' values ' ( optional ) : For a key with ' optional ' existence a dictionary mapping value names to empty dicts indicating that the values are to be deleted .
variable_expander
A VariableExpander object.
A VariableExpander object .