From 8f9dd8e93650b56e5ba213babc72c3f6ceab782b Mon Sep 17 00:00:00 2001 From: the-database <25811902+the-database@users.noreply.github.com> Date: Thu, 28 Nov 2024 22:01:06 -0500 Subject: [PATCH] improve logging --- .../Services/IPythonService.cs | 1 + .../Services/PythonService.cs | 17 ++--------------- .../ViewModels/MainWindowViewModel.cs | 15 ++++++++++++--- .../backend/src/pyproject.toml | 2 +- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/MangaJaNaiConverterGui/Services/IPythonService.cs b/MangaJaNaiConverterGui/Services/IPythonService.cs index 547c214..6f9fbcf 100644 --- a/MangaJaNaiConverterGui/Services/IPythonService.cs +++ b/MangaJaNaiConverterGui/Services/IPythonService.cs @@ -10,6 +10,7 @@ public interface IPythonService Task IsPythonUpdated(); bool AreModelsInstalled(); string BackendDirectory { get; } + string LogsDirectory { get; } string PythonDirectory { get; } string ModelsDirectory { get; } string PythonPath { get; } diff --git a/MangaJaNaiConverterGui/Services/PythonService.cs b/MangaJaNaiConverterGui/Services/PythonService.cs index f5745cd..7027680 100644 --- a/MangaJaNaiConverterGui/Services/PythonService.cs +++ b/MangaJaNaiConverterGui/Services/PythonService.cs @@ -42,6 +42,7 @@ public PythonService(IUpdateManagerService? updateManagerService = null) public string BackendDirectory => (_updateManagerService?.IsInstalled ?? false) ? Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"MangaJaNaiConverterGui") : Path.GetFullPath(@".\backend"); + public string LogsDirectory => Path.Combine(BackendDirectory, "logs"); public string ModelsDirectory => Path.Combine(BackendDirectory, "models"); public string PythonDirectory => Path.Combine(BackendDirectory, "python"); public string PythonPath => Path.GetFullPath(Path.Join(PythonDirectory, PYTHON_DOWNLOADS["win32"].Path)); @@ -190,23 +191,9 @@ public string InstallUpdatePythonDependenciesCommand { get { - string[] dependencies = { - "spandrel==0.4.0", - "spandrel_extra_arches==0.2.0", - "opencv-python==4.10.0.84", - "rarfile==4.2", - "numpy==2.1.3", - "chainner_ext==0.3.10", - "sanic==24.6.0", - "pynvml==11.5.3", - "psutil==6.1.0", - "pyvips==2.2.3", - "pyvips-binary==8.16.0" - }; - var relPythonPath = @".\python\python\python.exe"; - return $@"{relPythonPath} -m pip install torch==2.5.1 torchvision --index-url https://download.pytorch.org/whl/cu124 && {relPythonPath} -m pip install {string.Join(" ", dependencies)}"; + return $@"{relPythonPath} -m pip install wheel && {relPythonPath} -m pip install torch==2.5.1 torchvision --index-url https://download.pytorch.org/whl/cu124 && {relPythonPath} -m pip install ""{Path.GetFullPath(@".\backend\src")}"""; } } diff --git a/MangaJaNaiConverterGui/ViewModels/MainWindowViewModel.cs b/MangaJaNaiConverterGui/ViewModels/MainWindowViewModel.cs index e36887d..23e6af0 100644 --- a/MangaJaNaiConverterGui/ViewModels/MainWindowViewModel.cs +++ b/MangaJaNaiConverterGui/ViewModels/MainWindowViewModel.cs @@ -1006,7 +1006,7 @@ public async Task RunCommand(string command) process.StartInfo.StandardErrorEncoding = Encoding.UTF8; // Create a StreamWriter to write the output to a log file - using (var outputFile = new StreamWriter("error.log", append: true)) + using (var outputFile = new StreamWriter(Path.Combine(_pythonService.LogsDirectory, "upscale.log"), append: true)) { process.ErrorDataReceived += (sender, e) => { @@ -1090,7 +1090,7 @@ public async Task InitializeDeviceList() // Create a StreamWriter to write the output to a log file try { - using var outputFile = new StreamWriter("error.log", append: true); + using var outputFile = new StreamWriter(Path.Combine(_pythonService.LogsDirectory, "upscale.log"), append: true); process.ErrorDataReceived += (sender, e) => { if (!string.IsNullOrEmpty(e.Data)) @@ -1254,6 +1254,11 @@ await Task.Run(async () => { IsExtractingBackend = true; + if (!Directory.Exists(_pythonService.LogsDirectory)) + { + Directory.CreateDirectory(_pythonService.LogsDirectory); + } + if (!_pythonService.AreModelsInstalled()) { await DownloadModels(); @@ -1380,7 +1385,9 @@ public async Task InstallUpdatePythonDependencies() process.StartInfo.WorkingDirectory = _pythonService.BackendDirectory; var result = string.Empty; - + using var outputFile = new StreamWriter(Path.Combine(_pythonService.LogsDirectory, "install.log")); + outputFile.WriteLine($"Working Directory: {process.StartInfo.WorkingDirectory}"); + outputFile.WriteLine($"Run Command: {cmd}"); // Create a StreamWriter to write the output to a log file try { @@ -1390,6 +1397,7 @@ public async Task InstallUpdatePythonDependencies() if (!string.IsNullOrEmpty(e.Data)) { //Debug.WriteLine($"STDERR = {e.Data}"); + outputFile.WriteLine(e.Data); BackendSetupSubStatusQueueEnqueue(e.Data); } }; @@ -1399,6 +1407,7 @@ public async Task InstallUpdatePythonDependencies() if (!string.IsNullOrEmpty(e.Data)) { result = e.Data; + outputFile.WriteLine(e.Data); //Debug.WriteLine($"STDOUT = {e.Data}"); BackendSetupSubStatusQueueEnqueue(e.Data); } diff --git a/MangaJaNaiConverterGui/backend/src/pyproject.toml b/MangaJaNaiConverterGui/backend/src/pyproject.toml index eefb002..b6a6f45 100644 --- a/MangaJaNaiConverterGui/backend/src/pyproject.toml +++ b/MangaJaNaiConverterGui/backend/src/pyproject.toml @@ -4,6 +4,7 @@ requires-python = ">=3.11" dynamic = ["version"] dependencies = [ "chainner_ext==0.3.10", + "numpy==2.1.3", "opencv-python==4.10.0.84", "psutil==6.0.0", "pynvml==11.5.3", @@ -15,7 +16,6 @@ dependencies = [ "spandrel==0.4.0", "torch==2.5.1", "torchvision==0.20.1", - "numpy==2.1.3" ] authors = [{name = "the-database"}] description = "Upscaling manga images and archives with PyTorch models."