def setup_keyring(keyring_name):
    '''Setup the keyring'''
    keyring_path = os.path.join("test", "outputdata", keyring_name)
    # Delete the entire keyring
    shutil.rmtree(keyring_path, ignore_errors=True)
    os.makedirs(keyring_path)
    gpg = GPG(gnupghome=keyring_path, gpgbinary="gpg")
    for key_name in ["key1_private", "key1_public"]:
        with open(os.path.join("test", "inputdata", key_name + ".txt"), "r") as keyfile:
            key_str = "".join(keyfile.readlines())
        import_result = gpg.import_keys(key_str)
        print("Import result:", type(import_result))
        print(import_result.__dict__)
        if import_result.count == 1 and len(set(import_result.fingerprints)) == 1:
            print("Got one import result")
    return gpg
def delete_group(group_id=None):
    if request.is_xhr:
        ids = request.get_json()["ids"]
        if not (set(ids) & set(["1", "2", "3", "4", "5"])):
            data = []
            for group in Group.query.filter(Group.id.in_(ids)).all():
                group.delete()
                data.append({
                    "id": group.id,
                    "type": "delete",
                    "reverse": False,
                    "reverse_name": None,
                    "reverse_url": None
                })

            return jsonify(
                message="{} groups deleted.".format(len(data)),
                category="success",
                data=data,
                status=200
            )
        return jsonify(
            message=_("You cannot delete one of the standard groups."),
            category="danger",
            data=None,
            status=404
        )

    if group_id is not None:
        if group_id <= 5:  # there are 5 standard groups
            flash(_("You cannot delete the standard groups. "
                    "Try renaming it instead.", "danger"))
            return redirect(url_for("management.groups"))

        group = Group.query.filter_by(id=group_id).first_or_404()
        group.delete()
        flash(_("Group deleted."), "success")
        return redirect(url_for("management.groups"))

    flash(_("No group chosen."), "danger")
    return redirect(url_for("management.groups"))