<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def gpg_unstash_key( appname, key_id, config_dir=None, gpghome=None ):
 """ Remove a public key locally from our local app keyring Return True on success Return False on error """


    assert is_valid_appname(appname)
    if gpghome is None:
        config_dir = get_config_dir( config_dir )
        keydir = get_gpg_home( appname, config_dir=config_dir )
    else:
        keydir = gpghome

    gpg = gnupg.GPG( homedir=keydir )
    res = gpg.delete_keys( [key_id] )
    if res.status == 'Must delete secret key first':
        # this is a private key 
        res = gpg.delete_keys( [key_id], secret=True )

    try:
        assert res.status == 'ok', "Failed to delete key (%s)" % res
    except AssertionError, e:
        log.exception(e)
        log.error("Failed to delete key '%s'" % key_id)
        log.debug("res: %s" % res.__dict__)
        return False

    return True