forked from Relfos/neo-debugger-tools
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#164 Python support
- Loading branch information
Showing
16 changed files
with
963 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
|
||
namespace Neo_Boa_Proxy_Lib | ||
{ | ||
public class PythonCompilerProxy | ||
{ | ||
public static bool Execute(string outputFilePath, string pythonExecutableName, Action<string> logCallback) | ||
{ | ||
bool success = false; | ||
var proc = new Process(); | ||
var info = new ProcessStartInfo(); | ||
|
||
var loadCode = $"from boa.compiler import Compiler;Compiler.load_and_save('{outputFilePath}')"; | ||
info.FileName = pythonExecutableName; | ||
info.Arguments = $"-c \"{loadCode}\""; | ||
|
||
info.UseShellExecute = false; | ||
info.RedirectStandardInput = false; | ||
info.RedirectStandardOutput = true; | ||
info.RedirectStandardError = true; | ||
info.CreateNoWindow = true; | ||
proc.EnableRaisingEvents = true; | ||
|
||
proc.StartInfo = info; | ||
|
||
try | ||
{ | ||
logCallback("Starting compilation..."); | ||
|
||
proc.Start(); | ||
proc.WaitForExit(); | ||
|
||
var log = FetchLog(proc.StandardOutput.ReadToEnd()); | ||
string last = null; | ||
foreach (var temp in log) | ||
{ | ||
var line = temp.Replace("\r", ""); | ||
if (string.IsNullOrEmpty(line)) | ||
{ | ||
continue; | ||
} | ||
logCallback(line); | ||
last = line; | ||
} | ||
|
||
if (log.Length == 0) | ||
{ | ||
success = true; | ||
} | ||
|
||
log = FetchLog(proc.StandardError.ReadToEnd()); | ||
foreach (var line in log) | ||
{ | ||
logCallback(line); | ||
} | ||
|
||
if (log.Length > 0) | ||
{ | ||
success = false; | ||
} | ||
|
||
if (proc.ExitCode != 0 || !success) | ||
{ | ||
logCallback("Error during compilation."); | ||
} | ||
else | ||
{ | ||
success = true; | ||
logCallback("Compilation successful."); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
logCallback(ex.Message); | ||
} | ||
|
||
return success; | ||
} | ||
|
||
private static string[] FetchLog(string content) | ||
{ | ||
return content.Split('\n').Where(x => !string.IsNullOrEmpty(x)).ToArray(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.