Browse Source

Add CheckIsGitRepository, fix vlad git impl

pull/438/head
ionite34 11 months ago
parent
commit
5cf8b053f6
No known key found for this signature in database
GPG Key ID: B3404C5F3827849B
  1. 21
      StabilityMatrix.Avalonia/Helpers/UnixPrerequisiteHelper.cs
  2. 44
      StabilityMatrix.Avalonia/Helpers/WindowsPrerequisiteHelper.cs
  3. 17
      StabilityMatrix.Core/Helper/IPrerequisiteHelper.cs
  4. 46
      StabilityMatrix.Core/Models/Packages/VladAutomatic.cs

21
StabilityMatrix.Avalonia/Helpers/UnixPrerequisiteHelper.cs

@ -66,15 +66,9 @@ public class UnixPrerequisiteHelper : IPrerequisiteHelper
public async Task UnpackResourcesIfNecessary(IProgress<ProgressReport>? progress = null)
{
// Array of (asset_uri, extract_to)
var assets = new[]
{
(Assets.SevenZipExecutable, AssetsDir),
(Assets.SevenZipLicense, AssetsDir),
};
var assets = new[] { (Assets.SevenZipExecutable, AssetsDir), (Assets.SevenZipLicense, AssetsDir), };
progress?.Report(
new ProgressReport(0, message: "Unpacking resources", isIndeterminate: true)
);
progress?.Report(new ProgressReport(0, message: "Unpacking resources", isIndeterminate: true));
Directory.CreateDirectory(AssetsDir);
foreach (var (asset, extractDir) in assets)
@ -82,9 +76,7 @@ public class UnixPrerequisiteHelper : IPrerequisiteHelper
await asset.ExtractToDir(extractDir);
}
progress?.Report(
new ProgressReport(1, message: "Unpacking resources", isIndeterminate: false)
);
progress?.Report(new ProgressReport(1, message: "Unpacking resources", isIndeterminate: false));
}
public async Task InstallGitIfNecessary(IProgress<ProgressReport>? progress = null)
@ -146,8 +138,7 @@ public class UnixPrerequisiteHelper : IPrerequisiteHelper
if (result.ExitCode != 0)
{
Logger.Error(
"Git command [{Command}] failed with exit code "
+ "{ExitCode}:\n{StdOut}\n{StdErr}",
"Git command [{Command}] failed with exit code " + "{ExitCode}:\n{StdOut}\n{StdErr}",
command,
result.ExitCode,
result.StandardOutput,
@ -235,9 +226,9 @@ public class UnixPrerequisiteHelper : IPrerequisiteHelper
progress?.Report(new ProgressReport(1, "Installing Python", isIndeterminate: false));
}
public Task<string> GetGitOutput(string? workingDirectory = null, params string[] args)
public Task<ProcessResult> GetGitOutput(ProcessArgs args, string? workingDirectory = null)
{
throw new NotImplementedException();
return ProcessRunner.RunBashCommand(args.Prepend("git").ToArray(), workingDirectory ?? "");
}
[UnsupportedOSPlatform("Linux")]

44
StabilityMatrix.Avalonia/Helpers/WindowsPrerequisiteHelper.cs

@ -96,19 +96,17 @@ public class WindowsPrerequisiteHelper : IPrerequisiteHelper
result.EnsureSuccessExitCode();
}
public async Task<string> GetGitOutput(string? workingDirectory = null, params string[] args)
public Task<ProcessResult> GetGitOutput(ProcessArgs args, string? workingDirectory = null)
{
var process = await ProcessRunner.GetProcessOutputAsync(
return ProcessRunner.GetProcessResultAsync(
GitExePath,
string.Join(" ", args),
args,
workingDirectory: workingDirectory,
environmentVariables: new Dictionary<string, string>
{
{ "PATH", Compat.GetEnvPathWithExtensions(GitBinPath) }
}
);
return process;
}
public async Task InstallAllIfNecessary(IProgress<ProgressReport>? progress = null)
@ -122,15 +120,9 @@ public class WindowsPrerequisiteHelper : IPrerequisiteHelper
public async Task UnpackResourcesIfNecessary(IProgress<ProgressReport>? progress = null)
{
// Array of (asset_uri, extract_to)
var assets = new[]
{
(Assets.SevenZipExecutable, AssetsDir),
(Assets.SevenZipLicense, AssetsDir),
};
var assets = new[] { (Assets.SevenZipExecutable, AssetsDir), (Assets.SevenZipLicense, AssetsDir), };
progress?.Report(
new ProgressReport(0, message: "Unpacking resources", isIndeterminate: true)
);
progress?.Report(new ProgressReport(0, message: "Unpacking resources", isIndeterminate: true));
Directory.CreateDirectory(AssetsDir);
foreach (var (asset, extractDir) in assets)
@ -138,9 +130,7 @@ public class WindowsPrerequisiteHelper : IPrerequisiteHelper
await asset.ExtractToDir(extractDir);
}
progress?.Report(
new ProgressReport(1, message: "Unpacking resources", isIndeterminate: false)
);
progress?.Report(new ProgressReport(1, message: "Unpacking resources", isIndeterminate: false));
}
public async Task InstallPythonIfNecessary(IProgress<ProgressReport>? progress = null)
@ -262,11 +252,7 @@ public class WindowsPrerequisiteHelper : IPrerequisiteHelper
if (!Directory.Exists(TkinterExistsPath))
{
Logger.Info("Downloading Tkinter");
await downloadService.DownloadToFileAsync(
TkinterDownloadUrl,
TkinterZipPath,
progress: progress
);
await downloadService.DownloadToFileAsync(TkinterDownloadUrl, TkinterZipPath, progress: progress);
progress?.Report(
new ProgressReport(
progress: 1f,
@ -281,11 +267,7 @@ public class WindowsPrerequisiteHelper : IPrerequisiteHelper
}
progress?.Report(
new ProgressReport(
progress: 1f,
message: "Tkinter install complete",
type: ProgressType.Generic
)
new ProgressReport(progress: 1f, message: "Tkinter install complete", type: ProgressType.Generic)
);
}
@ -319,10 +301,7 @@ public class WindowsPrerequisiteHelper : IPrerequisiteHelper
public async Task InstallVcRedistIfNecessary(IProgress<ProgressReport>? progress = null)
{
var registry = Registry.LocalMachine;
var key = registry.OpenSubKey(
@"SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\X64",
false
);
var key = registry.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\X64", false);
if (key != null)
{
var buildId = Convert.ToUInt32(key.GetValue("Bld"));
@ -356,10 +335,7 @@ public class WindowsPrerequisiteHelper : IPrerequisiteHelper
message: "Installing prerequisites..."
)
);
var process = ProcessRunner.StartAnsiProcess(
VcRedistDownloadPath,
"/install /quiet /norestart"
);
var process = ProcessRunner.StartAnsiProcess(VcRedistDownloadPath, "/install /quiet /norestart");
await process.WaitForExitAsync();
progress?.Report(
new ProgressReport(

17
StabilityMatrix.Core/Helper/IPrerequisiteHelper.cs

@ -21,17 +21,22 @@ public interface IPrerequisiteHelper
/// <summary>
/// Run embedded git with the given arguments.
/// </summary>
Task RunGit(
ProcessArgs args,
Action<ProcessOutput>? onProcessOutput,
string? workingDirectory = null
);
Task RunGit(ProcessArgs args, Action<ProcessOutput>? onProcessOutput, string? workingDirectory = null);
/// <summary>
/// Run embedded git with the given arguments.
/// </summary>
Task RunGit(ProcessArgs args, string? workingDirectory = null);
Task<string> GetGitOutput(string? workingDirectory = null, params string[] args);
Task<ProcessResult> GetGitOutput(ProcessArgs args, string? workingDirectory = null);
async Task<bool> CheckIsGitRepository(string directory)
{
var result = await GetGitOutput(["rev-parse", "--is-inside-work-tree"], directory)
.ConfigureAwait(false);
return result.ExitCode == 0 && result.StandardOutput?.Trim().ToLowerInvariant() == "true";
}
Task InstallTkinterIfNecessary(IProgress<ProgressReport>? progress = null);
}

46
StabilityMatrix.Core/Models/Packages/VladAutomatic.cs

@ -204,7 +204,9 @@ public class VladAutomatic(
break;
default:
// CPU
await venvRunner.CustomInstall("launch.py --debug --test", onConsoleOutput).ConfigureAwait(false);
await venvRunner
.CustomInstall("launch.py --debug --test", onConsoleOutput)
.ConfigureAwait(false);
break;
}
@ -314,7 +316,11 @@ public class VladAutomatic(
);
await PrerequisiteHelper
.RunGit(new[] { "checkout", versionOptions.BranchName! }, onConsoleOutput, installedPackage.FullPath)
.RunGit(
new[] { "checkout", versionOptions.BranchName! },
onConsoleOutput,
installedPackage.FullPath
)
.ConfigureAwait(false);
var venvRunner = new PyVenvRunner(Path.Combine(installedPackage.FullPath!, "venv"));
@ -325,14 +331,17 @@ public class VladAutomatic(
try
{
var output = await PrerequisiteHelper
.GetGitOutput(installedPackage.FullPath, "rev-parse", "HEAD")
var result = await PrerequisiteHelper
.GetGitOutput(["rev-parse", "HEAD"], installedPackage.FullPath)
.EnsureSuccessExitCode()
.ConfigureAwait(false);
return new InstalledPackageVersion
{
InstalledBranch = versionOptions.BranchName,
InstalledCommitSha = output.Replace(Environment.NewLine, "").Replace("\n", ""),
InstalledCommitSha = result
.StandardOutput?.Replace(Environment.NewLine, "")
.Replace("\n", ""),
IsPrerelease = false
};
}
@ -343,7 +352,12 @@ public class VladAutomatic(
finally
{
progress?.Report(
new ProgressReport(1f, message: "Update Complete", isIndeterminate: false, type: ProgressType.Update)
new ProgressReport(
1f,
message: "Update Complete",
isIndeterminate: false,
type: ProgressType.Update
)
);
}
@ -354,7 +368,10 @@ public class VladAutomatic(
};
}
public override Task SetupModelFolders(DirectoryPath installDirectory, SharedFolderMethod sharedFolderMethod)
public override Task SetupModelFolders(
DirectoryPath installDirectory,
SharedFolderMethod sharedFolderMethod
)
{
switch (sharedFolderMethod)
{
@ -404,13 +421,19 @@ public class VladAutomatic(
configRoot["clip_models_path"] = Path.Combine(SettingsManager.ModelsDirectory, "CLIP");
configRoot["control_net_models_path"] = Path.Combine(SettingsManager.ModelsDirectory, "ControlNet");
var configJsonStr = JsonSerializer.Serialize(configRoot, new JsonSerializerOptions { WriteIndented = true });
var configJsonStr = JsonSerializer.Serialize(
configRoot,
new JsonSerializerOptions { WriteIndented = true }
);
File.WriteAllText(configJsonPath, configJsonStr);
return Task.CompletedTask;
}
public override Task UpdateModelFolders(DirectoryPath installDirectory, SharedFolderMethod sharedFolderMethod) =>
public override Task UpdateModelFolders(
DirectoryPath installDirectory,
SharedFolderMethod sharedFolderMethod
) =>
sharedFolderMethod switch
{
SharedFolderMethod.Symlink => base.UpdateModelFolders(installDirectory, sharedFolderMethod),
@ -476,7 +499,10 @@ public class VladAutomatic(
configRoot.Remove("clip_models_path");
configRoot.Remove("control_net_models_path");
var configJsonStr = JsonSerializer.Serialize(configRoot, new JsonSerializerOptions { WriteIndented = true });
var configJsonStr = JsonSerializer.Serialize(
configRoot,
new JsonSerializerOptions { WriteIndented = true }
);
File.WriteAllText(configJsonPath, configJsonStr);
return Task.CompletedTask;

Loading…
Cancel
Save