# Path: lib/sitkaAPI.py
# def APIDelete(url, absolute=False):
#     """
#     DELETE Wrapper around APICall
#     :param url:
#     :param absolute:
#     :return:
#     """
#     log = Logger("APIDelete")
#     log.info("Making Call: DELETE {}".format(url))
#     return APICall(url, absolute, method=requests.delete)
# 
# def APIGet(url, absolute=False):
#     """
#     GET Wrapper around APIGet
#     :param url:
#     :param absolute:
#     :return:
#     """
#     log = Logger("APIGet")
#     #log.info("Making Call: GET {}".format(url))
#     return APICall(url, absolute, method=requests.get)
# 
# Path: lib/env.py
# def setEnvFromFile(batFilePath, verbose = False):
# 
# Path: lib/userinput.py
# def query_yes_no(question, default="yes"):
#     """Ask a yes/no question via raw_input() and return their answer.
# 
#     "question" is a string that is presented to the user.
#     "default" is the presumed answer if the user just hits <Enter>.
#         It must be "yes" (the default), "no" or None (meaning
#         an answer is required of the user).
# 
#     The "answer" return value is True for "yes" or False for "no".
#     """
#     valid = {"yes": True, "y": True, "ye": True,
#              "no": False, "n": False}
#     if default is None:
#         prompt = " [y/n] "
#     elif default == "yes":
#         prompt = " [Y/n] "
#     elif default == "no":
#         prompt = " [y/N] "
#     else:
#         raise ValueError("invalid default answer: '%s'" % default)
# 
#     while True:
#         print(question + prompt)
#         choice = raw_input().lower()
#         if default is not None and choice == '':
#             return valid[default]
#         elif choice in valid:
#             return valid[choice]
#         else:
#             print("Please respond with 'yes' or 'no' (or 'y' or 'n').\n")


import argparse
import os
import logging
import sys, traceback
import re
from os import path
from lib.sitkaAPI import APIDelete, APIGet
from lib.exception import *
from lib import env
from lib.userinput import query_yes_no
sys.path.append(path.abspath(path.join(path.dirname(__file__), "..")))

"""

# THIS SCRIPT is DANGEROUS and intentionally hard to use.

"""

def fileDeleter(args):

    log = Logger("APIFileDeleter")

    if args.dryrun == False:
        foldertext = ""
        if args.folder is not None:
            foldertext = "FROM FOLDER '{}' ".format(args.folder)
        print "\n\n\nTHIS WILL DELETE ALL VISIT FILES ON THE API {}THAT MATCH THE PATTERN: '{}'".format(foldertext, args.pattern)

# Path: lib/sitkaAPI.py
# def APIDelete(url, absolute=False):
#     """
#     DELETE Wrapper around APICall
#     :param url:
#     :param absolute:
#     :return:
#     """
#     log = Logger("APIDelete")
#     log.info("Making Call: DELETE {}".format(url))
#     return APICall(url, absolute, method=requests.delete)
# 
# def APIGet(url, absolute=False):
#     """
#     GET Wrapper around APIGet
#     :param url:
#     :param absolute:
#     :return:
#     """
#     log = Logger("APIGet")
#     #log.info("Making Call: GET {}".format(url))
#     return APICall(url, absolute, method=requests.get)
# 
# Path: lib/env.py
# def setEnvFromFile(batFilePath, verbose = False):
# 
# Path: lib/userinput.py
# def query_yes_no(question, default="yes"):
#     """Ask a yes/no question via raw_input() and return their answer.
# 
#     "question" is a string that is presented to the user.
#     "default" is the presumed answer if the user just hits <Enter>.
#         It must be "yes" (the default), "no" or None (meaning
#         an answer is required of the user).
# 
#     The "answer" return value is True for "yes" or False for "no".
#     """
#     valid = {"yes": True, "y": True, "ye": True,
#              "no": False, "n": False}
#     if default is None:
#         prompt = " [y/n] "
#     elif default == "yes":
#         prompt = " [Y/n] "
#     elif default == "no":
#         prompt = " [y/N] "
#     else:
#         raise ValueError("invalid default answer: '%s'" % default)
# 
#     while True:
#         print(question + prompt)
#         choice = raw_input().lower()
#         if default is not None and choice == '':
#             return valid[default]
#         elif choice in valid:
#             return valid[choice]
#         else:
#             print("Please respond with 'yes' or 'no' (or 'y' or 'n').\n")


# Path: utilities/APIFileDeleter.py
import argparse
import os
import logging
import sys, traceback
import re
from os import path
from lib.sitkaAPI import APIDelete, APIGet
from lib.exception import *
from lib import env
from lib.userinput import query_yes_no

sys.path.append(path.abspath(path.join(path.dirname(__file__), "..")))

"""

# THIS SCRIPT is DANGEROUS and intentionally hard to use.

"""

def fileDeleter(args):

    log = Logger("APIFileDeleter")

    if args.dryrun == False:
        foldertext = ""
        if args.folder is not None:
            foldertext = "FROM FOLDER '{}' ".format(args.folder)
        print "\n\n\nTHIS WILL DELETE ALL VISIT FILES ON THE API {}THAT MATCH THE PATTERN: '{}'".format(foldertext, args.pattern)

        if not query_yes_no("Are you sure?") or not query_yes_no("\nNo, seriously! You're about to delete data on CM.org. Are you sure!?? (hint: BE SURE!!!)"):