From d2acf224f382c8f6ff299a1a52944c6eb31dade1 Mon Sep 17 00:00:00 2001 From: Netkas Date: Wed, 7 Dec 2022 22:57:42 -0500 Subject: [PATCH] Added PythonRunner https://git.n64.cc/nosial/ncc/-/issues/32 --- .../Classes/PythonExtension/PythonRunner.php | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/ncc/Classes/PythonExtension/PythonRunner.php diff --git a/src/ncc/Classes/PythonExtension/PythonRunner.php b/src/ncc/Classes/PythonExtension/PythonRunner.php new file mode 100644 index 0000000..d3b2baa --- /dev/null +++ b/src/ncc/Classes/PythonExtension/PythonRunner.php @@ -0,0 +1,53 @@ +Execute->Target = null; + $execution_unit->ExecutionPolicy = $policy; + $execution_unit->Data = Base64::encode(IO::fread($path)); + + return $execution_unit; + } + + /** + * @inheritDoc + */ + public static function getFileExtension(): string + { + return '.py'; + } + + /** + * @inheritDoc + */ + public static function prepareProcess(ExecutionPointer $pointer): Process + { + $python_bin = PathFinder::findRunner(Runners::python); + + if($pointer->ExecutionPolicy->Execute->Options !== null && count($pointer->ExecutionPolicy->Execute->Options) > 0) + return new Process(array_merge([$python_bin, $pointer->FilePointer], $pointer->ExecutionPolicy->Execute->Options)); + return new Process([$python_bin, $pointer->FilePointer]); + } +} \ No newline at end of file