Skip to content

Commit

Permalink
improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
the-database committed Nov 29, 2024
1 parent b6ebcc9 commit 8f9dd8e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions MangaJaNaiConverterGui/Services/IPythonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface IPythonService
Task<bool> IsPythonUpdated();
bool AreModelsInstalled();
string BackendDirectory { get; }
string LogsDirectory { get; }
string PythonDirectory { get; }
string ModelsDirectory { get; }
string PythonPath { get; }
Expand Down
17 changes: 2 additions & 15 deletions MangaJaNaiConverterGui/Services/PythonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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")}""";
}
}

Expand Down
15 changes: 12 additions & 3 deletions MangaJaNaiConverterGui/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
{
Expand Down Expand Up @@ -1090,7 +1090,7 @@ public async Task<string[]> 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))
Expand Down Expand Up @@ -1254,6 +1254,11 @@ await Task.Run(async () =>
{
IsExtractingBackend = true;

if (!Directory.Exists(_pythonService.LogsDirectory))
{
Directory.CreateDirectory(_pythonService.LogsDirectory);
}

if (!_pythonService.AreModelsInstalled())
{
await DownloadModels();
Expand Down Expand Up @@ -1380,7 +1385,9 @@ public async Task<string[]> 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
{
Expand All @@ -1390,6 +1397,7 @@ public async Task<string[]> InstallUpdatePythonDependencies()
if (!string.IsNullOrEmpty(e.Data))
{
//Debug.WriteLine($"STDERR = {e.Data}");
outputFile.WriteLine(e.Data);
BackendSetupSubStatusQueueEnqueue(e.Data);
}
};
Expand All @@ -1399,6 +1407,7 @@ public async Task<string[]> InstallUpdatePythonDependencies()
if (!string.IsNullOrEmpty(e.Data))
{
result = e.Data;
outputFile.WriteLine(e.Data);
//Debug.WriteLine($"STDOUT = {e.Data}");
BackendSetupSubStatusQueueEnqueue(e.Data);
}
Expand Down
2 changes: 1 addition & 1 deletion MangaJaNaiConverterGui/backend/src/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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."
Expand Down

0 comments on commit 8f9dd8e

Please sign in to comment.