mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-31 04:00:18 -07:00
New: Testing Custom Script executes the script and verifies the exit code
This commit is contained in:
parent
b9d240924f
commit
91082b2903
1 changed files with 19 additions and 32 deletions
|
@ -1,15 +1,14 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentValidation.Results;
|
using FluentValidation.Results;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Disk;
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Common.Extensions;
|
|
||||||
using NzbDrone.Common.Processes;
|
using NzbDrone.Common.Processes;
|
||||||
using NzbDrone.Common.Serializer;
|
using NzbDrone.Common.Serializer;
|
||||||
using NzbDrone.Core.Music;
|
using NzbDrone.Core.Music;
|
||||||
|
using NzbDrone.Core.ThingiProvider;
|
||||||
using NzbDrone.Core.Validation;
|
using NzbDrone.Core.Validation;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Notifications.CustomScript
|
namespace NzbDrone.Core.Notifications.CustomScript
|
||||||
|
@ -31,6 +30,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
|
||||||
|
|
||||||
public override string Link => "https://github.com/Lidarr/Lidarr/wiki/Custom-Post-Processing-Scripts";
|
public override string Link => "https://github.com/Lidarr/Lidarr/wiki/Custom-Post-Processing-Scripts";
|
||||||
|
|
||||||
|
public override ProviderMessage Message => new ProviderMessage("Testing will execute the script with the EventType set to Test, ensure your script handles this correctly", ProviderMessageType.Warning);
|
||||||
|
|
||||||
public override void OnGrab(GrabMessage message)
|
public override void OnGrab(GrabMessage message)
|
||||||
{
|
{
|
||||||
var artist = message.Artist;
|
var artist = message.Artist;
|
||||||
|
@ -162,20 +163,10 @@ namespace NzbDrone.Core.Notifications.CustomScript
|
||||||
failures.Add(new NzbDroneValidationFailure("Path", "File does not exist"));
|
failures.Add(new NzbDroneValidationFailure("Path", "File does not exist"));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var systemFolder in SystemFolders.GetSystemFolders())
|
|
||||||
{
|
|
||||||
if (systemFolder.IsParentPath(Settings.Path))
|
|
||||||
{
|
|
||||||
failures.Add(new NzbDroneValidationFailure("Path", $"Must not be a descendant of '{systemFolder}'"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (failures.Empty())
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var environmentVariables = new StringDictionary();
|
var environmentVariables = new StringDictionary();
|
||||||
environmentVariables.Add("Sonarr_EventType", "Test");
|
environmentVariables.Add("Lidarr_EventType", "Test");
|
||||||
|
|
||||||
var processOutput = ExecuteScript(environmentVariables);
|
var processOutput = ExecuteScript(environmentVariables);
|
||||||
|
|
||||||
|
@ -189,24 +180,20 @@ namespace NzbDrone.Core.Notifications.CustomScript
|
||||||
_logger.Error(ex);
|
_logger.Error(ex);
|
||||||
failures.Add(new NzbDroneValidationFailure(string.Empty, ex.Message));
|
failures.Add(new NzbDroneValidationFailure(string.Empty, ex.Message));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return new ValidationResult(failures);
|
return new ValidationResult(failures);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteScript(StringDictionary environmentVariables)
|
private ProcessOutput ExecuteScript(StringDictionary environmentVariables)
|
||||||
{
|
{
|
||||||
_logger.Debug("Executing external script: {0}", Settings.Path);
|
_logger.Debug("Executing external script: {0}", Settings.Path);
|
||||||
|
|
||||||
var process = _processProvider.StartAndCapture(Settings.Path, Settings.Arguments, environmentVariables);
|
var processOutput = _processProvider.StartAndCapture(Settings.Path, Settings.Arguments, environmentVariables);
|
||||||
|
|
||||||
_logger.Debug("Executed external script: {0} - Status: {1}", Settings.Path, process.ExitCode);
|
_logger.Debug("Executed external script: {0} - Status: {1}", Settings.Path, processOutput.ExitCode);
|
||||||
_logger.Debug($"Script Output: {System.Environment.NewLine}{string.Join(System.Environment.NewLine, process.Lines)}");
|
_logger.Debug($"Script Output: {System.Environment.NewLine}{string.Join(System.Environment.NewLine, processOutput.Lines)}");
|
||||||
}
|
|
||||||
|
|
||||||
private bool ValidatePathParent(string possibleParent, string path)
|
return processOutput;
|
||||||
{
|
|
||||||
return possibleParent.IsParentPath(path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue