Bearsampp 2026.9.23
Loading...
Searching...
No Matches
class.tool.python.php
Go to the documentation of this file.
1<?php
2/*
3 *
4 * * Copyright (c) 2021-2026 Bearsampp
5 * * License: GNU General Public License version 3 or later; see LICENSE.txt
6 * * Website: https://bearsampp.com
7 * * Github: https://github.com/Bearsampp
8 *
9 */
10
18class ToolPython extends Module
19{
23 const ROOT_CFG_VERSION = 'pythonVersion';
24
28 const LOCAL_CFG_EXE = 'pythonExe';
32 const LOCAL_CFG_IDLE_EXE = 'pythonIdleExe';
33
37 private $exe;
41 private $idleExe;
42
49 public function __construct($id, $type)
50 {
51 Log::initClass($this);
52 $this->reload($id, $type);
53 }
54
61 public function reload($id = null, $type = null)
62 {
64 Log::reloadClass($this);
65
66 $this->name = $bearsamppLang->getValue(Lang::PYTHON);
67 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
68 parent::reload($id, $type);
69
70 if ($this->bearsamppConfRaw !== false) {
71 $this->exe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
72 $this->idleExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_IDLE_EXE];
73 }
74
75 if (!$this->enable) {
76 Log::info($this->name . ' is not enabled!');
77
78 return;
79 }
80 if (!is_dir($this->currentPath)) {
81 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
82 }
83 if (!is_dir($this->symlinkPath)) {
84 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
85
86 return;
87 }
88 if (!is_file($this->bearsamppConf)) {
89 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
90 }
91 if (!is_file($this->exe)) {
92 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exe));
93 }
94 if (!is_file($this->idleExe)) {
95 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->idleExe));
96 }
97 }
98
104 public function setVersion($version)
105 {
106 global $bearsamppConfig;
107 $this->version = $version;
108 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
109 $this->reload();
110 }
111
117 public function getExe()
118 {
119 return $this->exe;
120 }
121
127 public function getIdleExe()
128 {
129 return $this->idleExe;
130 }
131}
132
global $bearsamppLang
const ERROR_EXE_NOT_FOUND
const ERROR_CONF_NOT_FOUND
const PYTHON
const ERROR_FILE_NOT_FOUND
static info($data, $file=null)
static reloadClass($classInstance)
static error($data, $file=null)
static initClass($classInstance)
setVersion($version)
reload($id=null, $type=null)
__construct($id, $type)
global $bearsamppConfig
Definition homepage.php:46