
import argparse, os, shutil
from lires.config import LRS_HOME, LOG_DIR, TMP_DIR

def main():
    parser = argparse.ArgumentParser(description="Remove data generated by lires")
    parser.add_argument("--cache", action = "store_true", help = "Remove caches")
    parser.add_argument("--log", action = "store_true", help = "Remove log")
    parser.add_argument("--all", action = "store_true", help = "Remove all data! (including database, use with caution!)")

    args = parser.parse_args()
    if args.all:
        prompt_msgs = [
            "WARNING:", 
            "This action is going to delete ALL DATA in: {}".format(LRS_HOME),
            "Please make sure that the application is not running",
            "Proceed? (y/[else]): "
        ]
        if input("\n".join(prompt_msgs)) == "y":
            if os.path.exists(LRS_HOME):
                shutil.rmtree(LRS_HOME)
            print("success.")
        else:
            print("abort.")

    elif args.cache:
        if os.path.exists(TMP_DIR):
            shutil.rmtree(TMP_DIR)
            print("success.")
    
    elif args.log:
        if os.path.exists(LOG_DIR):
            shutil.rmtree(LOG_DIR)
            print("success.")
    else:
        parser.print_help()

if __name__ == "__main__":
    main()