public static void SendHeartbeat(string fileName, bool isWrite) { var arguments = new List<string> { GetCli(), "--key", WakaTimeConfigFile.ApiKey, "--file", fileName, "--plugin", WakaTimeConstants.EditorName + "/" + _editorVersion + " " + WakaTimeConstants.PluginName + "/" + _version }; if (isWrite) arguments.Add("--write"); var projectName = GetProjectName(); if (!string.IsNullOrEmpty(projectName)) { arguments.Add("--project"); arguments.Add(projectName); } var pythonBinary = PythonManager.GetPython(); if (pythonBinary != null) { var process = new RunProcess(pythonBinary, arguments.ToArray()); if (WakaTimeConfigFile.Debug) { Logger.Instance.Info("[\"" + pythonBinary + "\", \"" + string.Join("\", ", arguments) + "\"]"); process.Run(); Logger.Instance.Info("WakaTime CLI STDOUT:" + process.Output); Logger.Instance.Info("WakaTime CLI STDERR:" + process.Error); } else { process.RunInBackground(); } } else { Logger.Instance.Error("Could not send heartbeat because python is not installed."); } }
static string GetPathFromFixedPath() { string[] locations = { "pythonw", "python3", "python", "\\Python37\\pythonw", "\\Python36\\pythonw", "\\Python35\\pythonw", "\\Python34\\pythonw", "\\Python33\\pythonw", "\\Python32\\pythonw", "\\Python31\\pythonw", "\\Python30\\pythonw", "\\Python27\\pythonw", "\\Python26\\pythonw", "\\python37\\pythonw", "\\python36\\pythonw", "\\python35\\pythonw", "\\python34\\pythonw", "\\python33\\pythonw", "\\python32\\pythonw", "\\python31\\pythonw", "\\python30\\pythonw", "\\python27\\pythonw", "\\python26\\pythonw", "\\Python37\\python", "\\Python36\\python", "\\Python35\\python", "\\Python34\\python", "\\Python33\\python", "\\Python32\\python", "\\Python31\\python", "\\Python30\\python", "\\Python27\\python", "\\Python26\\python", "\\python37\\python", "\\python36\\python", "\\python35\\python", "\\python34\\python", "\\python33\\python", "\\python32\\python", "\\python31\\python", "\\python30\\python", "\\python27\\python", "\\python26\\python", }; foreach (var location in locations) { var process = new RunProcess(location, "--version"); process.Run(); if (!process.Success) continue; Logger.Instance.Info("Found python in standard location at: " + location.ToString()); return location; } return null; }
static bool IsCliLatestVersion() { var process = new RunProcess(PythonManager.GetPython(), GetCli(), "--version"); process.Run(); return process.Success && process.Error.Equals(WakaTimeConstants.CurrentWakaTimeCliVersion); }
static string GetPathFromMicrosoftRegister() { if (PlatformID.Win32NT != Environment.OSVersion.Platform) return null; try { var regex = new Regex(@"""([^""]*)\\([^""\\]+(?:\.[^"".\\]+))"""); var pythonKey = Registry.ClassesRoot.OpenSubKey(@"Python.File\shell\open\command"); var python = pythonKey.GetValue(null).ToString(); var match = regex.Match(python); if (!match.Success) return null; var directory = match.Groups[1].Value; var fullPath = Path.Combine(directory, "pythonw"); var process = new RunProcess(fullPath, "--version"); process.Run(); if (!process.Success) return null; Logger.Instance.Info("Found python via registry at: " + fullPath.ToString()); return fullPath; } catch (Exception) { return null; } }