@@ -0,0 +1,2372 @@
+from argparse import ArgumentParser%0A%0Afrom bioblend import galaxy%0A%0A%0Adef extract_users(user_list, all_users):%0A    selected_users = %5B%5D%0A    for old_user in user_list:%0A        for user in all_users:%0A            if user%5Bu'email'%5D == old_user:%0A                selected_users.append(user)%0A                continue%0A    return selected_users%0A%0A%0Adef get_user_apikeys(galaxy_instance, users):%0A    selected_api_keys = %5B%5D%0A    for user in users:%0A        api_key = galaxy_instance.users.get_user_apikey(user%5Bu'id'%5D)%0A        if api_key == 'Not available.':%0A            api_key = galaxy_instance.users.create_user_apikey(user%5Bu'id'%5D)%0A        selected_api_keys.append(api_key)%0A    return selected_api_keys%0A%0A%0Adef purge_user_histories(api_key, GalaxyURL):%0A    gui = galaxy.GalaxyInstance(url=GalaxyURL, key=api_key)%0A    histories = gui.histories.get_histories()%0A    for history in histories:%0A        print(%22purging history %25s%22 %25 history%5Bu'id'%5D)%0A        gui.histories.delete_history(history%5Bu'id'%5D, purge=True)%0A%0A%0Adef _parse_cli_options():%0A    %22%22%22%0A    Parse command line options, returning %60parse_args%60 from %60ArgumentParser%60.%0A    %22%22%22%0A    parser = ArgumentParser(%0A        description='bioblend-managed deletion of histories from a provided %5C%0A                     list of galaxy user emails',%0A        usage=%22 python %25(prog)s %3Coptions%3E%22)%0A    parser.add_argument(%22-g%22, %22--admin-galaxy-url%22,%0A                        dest=%22admin_galaxy_url%22,%0A                        required=True,%0A                        help=%22Galaxy url of an admin%22)%0A    parser.add_argument(%22-a%22, %22--api-key%22,%0A                        required=True,%0A                        dest=%22api_key%22,%0A                        help=%22Admin API key%22)%0A    parser.add_argument(%22-e%22, %22--emails%22,%0A                        required=True,%0A                        dest=%22emails%22,%0A                        nargs='+',%0A                        help=%22A list of user emails%22)%0A    return parser.parse_args()%0A%0A%0Adef __main__():%0A    args = _parse_cli_options()%0A    ADMIN_KEY = args.api_key%0A    GalaxyURL = args.admin_galaxy_url%0A    gi = galaxy.GalaxyInstance(url=GalaxyURL, key=ADMIN_KEY)%0A    all_users = gi.users.get_users()%0A    selected_users = extract_users(args.emails, all_users)%0A    user_api_keys = get_user_apikeys(gi, selected_users)%0A    for api_key in user_api_keys:%0A        purge_user_histories(api_key, GalaxyURL)%0A%0A%0Aif __name__ == %22__main__%22:%0A    __main__()%0A

implement script to purge old user histories