Example #1
0
def popupKodiLog():
    dialog_text = ""
    log_file = open(getLogPath(), 'r')
    log_output = log_file.readlines()
    log_file.close()    
    for line in log_output:
        dialog_text = dialog_text + line
    showLogBox("Kodi Log", dialog_text)
    # Delete all of the downloaded VPN files
    if action == "downloads":
        debugTrace("Deleting all downloaded VPN files")
        removeDownloadedFiles()
        xbmcgui.Dialog().ok(
            addon_name,
            "Deleted all of the downloaded VPN files. They'll be downloaded again if required.\n"
        )

    # Copy the log file
    elif action == "log":
        log_path = ""
        dest_path = ""
        try:
            log_path = getLogPath()
            start_dir = ""
            dest_folder = xbmcgui.Dialog().browse(
                0, "Select folder to copy log file into", "files", "", False,
                False, start_dir, False)
            dest_path = "kodi " + datetime.datetime.now().strftime(
                "%y-%m-%d %H-%M-%S") + ".log"
            dest_path = dest_folder + dest_path.replace(" ", "_")
            # Write VPN log to log before copying
            writeVPNLog()
            debugTrace("Copying " + log_path + " to " + dest_path)
            addon = xbmcaddon.Addon(getID())
            infoTrace(
                "managefiles.py", "Copying log file to " + dest_path +
                ".  Using version " + addon.getSetting("version_number"))
            xbmcvfs.copy(log_path, dest_path)
        # Reset the connection before we do anything else
        resetVPNConnections(addon)            
        debugTrace("Deleting all generated ovpn files")
        # Delete the ovpn files and the generated flag file.
        removeGeneratedFiles()
        # Remove any user/password files
        cleanPassFiles()
        xbmcgui.Dialog().ok(addon_name, "Deleted all .ovpn files.  Validate a connection to recreate them.\n")


# Copy the log file        
elif action == "log":
    log_path = ""
    dest_path = ""
    try:
        log_path = getLogPath()
        start_dir = ""
        dest_folder = xbmcgui.Dialog().browse(0, "Select folder to copy log file into", "files", "", False, False, start_dir, False)
        dest_path = "kodi " + datetime.datetime.now().strftime("%y-%m-%d %H-%M-%S") + ".log"
        dest_path = dest_folder + dest_path.replace(" ", "_")
        # Write VPN log to log before copying
        writeVPNLog()
        debugTrace("Copying " + log_path + " to " + dest_path)
        addon = xbmcaddon.Addon("service.vpn.manager")
        infoTrace("managefiles.py", "Copying log file to " + dest_path + ".  Using version " + addon.getSetting("version_number"))
        xbmcvfs.copy(log_path, dest_path)
        dialog_message = "Copied log file to:\n" + dest_path
    except:
        errorTrace("Failed to copy log from " + log_path + " to " + dest_path)
        if xbmcvfs.exists(log_path):
            dialog_message = "Error copying log, try copying it to a different location."