Skip to content

Commit

Permalink
Merge pull request #196 from AndersMalmgren/current_dir_merge
Browse files Browse the repository at this point in the history
Current dir merge
  • Loading branch information
AndersMalmgren authored Sep 8, 2020
2 parents 2595a11 + f30dcfe commit 4e51cae
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
3 changes: 2 additions & 1 deletion FreePIE.Console/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public void Start(string[] args)
persistanceManager.Load();

System.Console.WriteLine("Starting script parser");
scriptEngine.Start(script);

scriptEngine.Start(script, args[0]);
waitUntilStopped.WaitOne();
}
catch (Exception e)
Expand Down
5 changes: 5 additions & 0 deletions FreePIE.Core/Common/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public string GetFilename(string path)
return Path.GetFileName(path);
}

public string GetDirectoryName(string path)
{
return Path.GetDirectoryName(path);
}

public void Delete(string path)
{
File.Delete(path);
Expand Down
1 change: 1 addition & 0 deletions FreePIE.Core/Common/IFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public interface IFileSystem
string GetFilename(string path);
void Delete(string path);
void CreateDirectory(string path);
string GetDirectoryName(string path);
}
}
4 changes: 2 additions & 2 deletions FreePIE.Core/ScriptEngine/IScriptEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace FreePIE.Core.ScriptEngine
{
public interface IScriptEngine
{
void Start(string script);
void Start(string script, string scriptPath = null);
void Stop();
}
}
}
25 changes: 13 additions & 12 deletions FreePIE.Core/ScriptEngine/Python/PythonScriptEngine.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
Expand All @@ -11,20 +10,15 @@
using FreePIE.Core.Common.Extensions;
using FreePIE.Core.Contracts;
using FreePIE.Core.Model.Events;
using FreePIE.Core.Persistence;
using FreePIE.Core.Persistence.Paths;
using FreePIE.Core.ScriptEngine.Globals;
using FreePIE.Core.ScriptEngine.ThreadTiming;
using IronPython;
using IronPython.Compiler;
using IronPython.Hosting;
using IronPython.Modules;
using IronPython.Runtime.Operations;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting.Hosting.Providers;
using Microsoft.Scripting.Runtime;
using IronPython.Runtime.Exceptions;
using Microsoft.Scripting.Utils;

namespace FreePIE.Core.ScriptEngine.Python
{
Expand Down Expand Up @@ -80,6 +74,7 @@ public class PythonScriptEngine : IScriptEngine
private readonly IThreadTimingFactory threadTimingFactory;
private readonly IPaths paths;
private readonly ILog log;
private readonly IFileSystem fileSystem;
private static Microsoft.Scripting.Hosting.ScriptEngine engine;
private IEnumerable<IPlugin> usedPlugins;
private InterlockableBool stopRequested;
Expand All @@ -105,17 +100,19 @@ public PythonScriptEngine(
IEventAggregator eventAggregator,
IThreadTimingFactory threadTimingFactory,
IPaths paths,
ILog log)
ILog log,
IFileSystem fileSystem)
{
this.parser = parser;
this.globalProviders = globalProviders;
this.eventAggregator = eventAggregator;
this.threadTimingFactory = threadTimingFactory;
this.paths = paths;
this.log = log;
this.fileSystem = fileSystem;
}

public void Start(string script)
public void Start(string script, string scriptPath = null)
{
thread = new Thread(obj1 =>
{
Expand Down Expand Up @@ -148,7 +145,8 @@ public void Start(string script)

pluginStarted.Wait();

Engine.SetSearchPaths(GetPythonPaths());
var additionalPaths = new [] { scriptPath }.Where(p => !string.IsNullOrEmpty(p)).Select(p => fileSystem.GetDirectoryName(p));
Engine.SetSearchPaths(GetPythonPaths(additionalPaths));

script = PreProcessScript(script, usedGlobalEnums, globals);
}, logToFile: true);
Expand Down Expand Up @@ -179,9 +177,12 @@ void RunLoop(string script, ScriptScope scope)
});
}

ICollection<string> GetPythonPaths()
ICollection<string> GetPythonPaths(IEnumerable<string> additionalPaths)
{
return new Collection<string> { paths.GetApplicationPath("pylib") };
var pythonPaths = new Collection<string> { paths.GetApplicationPath("pylib") };
pythonPaths.AddRange(additionalPaths);

return pythonPaths;
}

private void CatchThreadAbortedException(Action func)
Expand Down
3 changes: 2 additions & 1 deletion FreePIE.GUI/Views/Main/Menu/MainMenuViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ public void RunScript()
PublishScriptStateChange();

currentScriptEngine = scriptEngineFactory();
currentScriptEngine.Start(activeDocument.FileContent);

currentScriptEngine.Start(activeDocument.FileContent, activeDocument.FilePath);
}

public void StopScript()
Expand Down

0 comments on commit 4e51cae

Please sign in to comment.