MDL-59995 core_admin: added setting to define Python bin path

This commit is contained in:
Mark Nelson
2017-09-12 12:29:56 +08:00
parent 32f9550e85
commit 391663ce28
4 changed files with 33 additions and 5 deletions
+28 -5
View File
@@ -40,15 +40,38 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso
*/
const REQUIRED_PIP_PACKAGE_VERSION = '0.0.2';
/**
* The path to the Python bin.
*
* @var string
*/
protected $pathtopython;
/**
* The constructor.
*/
public function __construct() {
global $CFG;
// Set the python location if there is a value.
if (!empty($CFG->pathtopython)) {
$this->pathtopython = $CFG->pathtopython;
}
}
/**
* Is the plugin ready to be used?.
*
* @return bool
* @return bool|string Returns true on success, a string detailing the error otherwise
*/
public function is_ready() {
if (empty($this->pathtopython)) {
$settingurl = new \moodle_url('/admin/settings.php', array('section' => 'systempaths'));
return get_string('pythonpathnotdefined', 'mlbackend_python', $settingurl->out());
}
// Check the installed pip package version.
$cmd = 'python -m moodlemlbackend.version';
$cmd = "{$this->pathtopython} -m moodlemlbackend.version";
$output = null;
$exitcode = null;
@@ -84,7 +107,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso
// Obtain the physical route to the file.
$datasetpath = $this->get_file_path($dataset);
$cmd = 'python -m moodlemlbackend.training ' .
$cmd = "{$this->pathtopython} -m moodlemlbackend.training " .
escapeshellarg($uniqueid) . ' ' .
escapeshellarg($outputdir) . ' ' .
escapeshellarg($datasetpath);
@@ -125,7 +148,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso
// Obtain the physical route to the file.
$datasetpath = $this->get_file_path($dataset);
$cmd = 'python -m moodlemlbackend.prediction ' .
$cmd = "{$this->pathtopython} -m moodlemlbackend.prediction " .
escapeshellarg($uniqueid) . ' ' .
escapeshellarg($outputdir) . ' ' .
escapeshellarg($datasetpath);
@@ -168,7 +191,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso
// Obtain the physical route to the file.
$datasetpath = $this->get_file_path($dataset);
$cmd = 'python -m moodlemlbackend.evaluation ' .
$cmd = "{$this->pathtopython} -m moodlemlbackend.evaluation " .
escapeshellarg($uniqueid) . ' ' .
escapeshellarg($outputdir) . ' ' .
escapeshellarg($datasetpath) . ' ' .