def main():
    global log, utils, bitc
    args = Args()
    args.parse()
    log = logger.create("BitcasaFileFetcher", args)
    from helpers import utils
    from bitcasadownload import BitcasaDownload
    from lib import BitcasaUtils
    from lib.gdrive import GoogleDrive

    if args.run_level == Args.RUN_LEVEL_MAIN:
        client = None
        if not args.args.upload or not args.args.local:
            bitcasa_utils = BitcasaUtils()
            if bitcasa_utils.test_auth():
                args.args.token = bitcasa_utils.token
            else:
                log.error("Bitcasa Access token not set or invalid. Use the following commands to get one.")
                log.info("python BitcasaFileLister")
                return
            client = bitcasa_utils.create_client()
        if args.args.upload:
            if args.args.provider == "gdrive":
                g = GoogleDrive()
                if not g.test_auth():
                    log.error("Google Drive Access token not set or invalid. Use the following command to get one.")
                    log.info("python BitcasaFileFetcher oauth --provider gdrive")
                    return
        log.debug("Initializing download")
        bitc = BitcasaDownload(args.args, client, should_exit)
        if should_exit.is_set():
            log.info("Exiting")
            return
        input_thread = threading.Thread(target=handle_input, name="Handle Exit")
        input_thread.daemon = True
        input_thread.start()
        if args.args.single:
            bitc.process_single()
        else:
            bitc.process()
    elif args.run_level == Args.RUN_LEVEL_OAUTH:
        if args.args.provider == "bitcasa":
            run_server(args.args.nolaunch)
        elif args.args.provider == "gdrive":
            g = GoogleDrive()
            try:
                g.get_service(True, not args.args.nolaunch)
            except:
                log.exception("Error authenticating to Google drive")

    elif args.run_level == Args.RUN_LEVEL_TEST:
        if args.args.provider == "bitcasa":
            bitcasa_utils = BitcasaUtils()
            if bitcasa_utils.test_auth():
                log.info("Connected to Bitcasa successfully")
            else:
                log.info("Error connecting to Bitcasa")
        elif args.args.provider == "gdrive":
            g = GoogleDrive()
            if g.test_auth():
                log.info("Connected to Google Drive successfully")
            else:
                log.info("Error connecting to Google drive")
    else:
        log.error("An error occurred processing your command. Please check the syntax and try again")
            
     
    log.info("Done")