def handle(self, *args, **options):
        email = options['email']
        try:
            profile = UserProfile.objects.get(email=email)
        except __HOLE__:
            raise CommandError("No such user.")

        if options['grant']:
            if profile.has_perm(options['permission'], profile.realm):
                raise CommandError("User already has permission for this realm.")
            else:
                if options['ack']:
                    do_change_is_admin(profile, True, permission=options['permission'])
                    print("Done!")
                else:
                    print("Would have granted %s %s rights for %s" % (email, options['permission'], profile.realm.domain))
        else:
            if profile.has_perm(options['permission'], profile.realm):
                if options['ack']:
                    do_change_is_admin(profile, False, permission=options['permission'])
                    print("Done!")
                else:
                    print("Would have removed %s's %s rights on %s" % (email, options['permission'],
                            profile.realm.domain))
            else:
                raise CommandError("User did not have permission for this realm!")
dataset/ETHPy150Open zulip/zulip/zerver/management/commands/knight.py/Command.handle