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

44
StabilityMatrix.Avalonia/Helpers/WindowsPrerequisiteHelper.cs

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

17
StabilityMatrix.Core/Helper/IPrerequisiteHelper.cs

@ -21,17 +21,22 @@ public interface IPrerequisiteHelper
/// <summary> /// <summary>
/// Run embedded git with the given arguments. /// Run embedded git with the given arguments.
/// </summary> /// </summary>
Task RunGit( Task RunGit(ProcessArgs args, Action<ProcessOutput>? onProcessOutput, string? workingDirectory = null);
ProcessArgs args,
Action<ProcessOutput>? onProcessOutput,
string? workingDirectory = null
);
/// <summary> /// <summary>
/// Run embedded git with the given arguments. /// Run embedded git with the given arguments.
/// </summary> /// </summary>
Task RunGit(ProcessArgs args, string? workingDirectory = null); 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); Task InstallTkinterIfNecessary(IProgress<ProgressReport>? progress = null);
} }

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

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

Loading…
Cancel
Save