Bearsampp 2025.8.29
Loading...
Searching...
No Matches
class.tool.python.php
Go to the documentation of this file.
1<?php
2/*
3 *
4 * * Copyright (c) 2021-2024 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{
20 const ROOT_CFG_VERSION = 'pythonVersion';
21
22 const LOCAL_CFG_EXE = 'pythonExe';
23 const LOCAL_CFG_IDLE_EXE = 'pythonIdleExe';
24
25 private $exe;
26 private $idleExe;
27
34 public function __construct($id, $type) {
35 Util::logInitClass($this);
36 $this->reload($id, $type);
37 }
38
45 public function reload($id = null, $type = null) {
48
49 $this->name = $bearsamppLang->getValue(Lang::PYTHON);
50 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
51 parent::reload($id, $type);
52
53 if ($this->bearsamppConfRaw !== false) {
54 $this->exe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
55 $this->idleExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_IDLE_EXE];
56 }
57
58 if (!$this->enable) {
59 Util::logInfo($this->name . ' is not enabled!');
60 return;
61 }
62 if (!is_dir($this->currentPath)) {
63 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
64 }
65 if (!is_dir($this->symlinkPath)) {
66 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
67 return;
68 }
69 if (!is_file($this->bearsamppConf)) {
70 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
71 }
72 if (!is_file($this->exe)) {
73 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exe));
74 }
75 if (!is_file($this->idleExe)) {
76 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->idleExe));
77 }
78 }
79
85 public function setVersion($version) {
86 global $bearsamppConfig;
87 $this->version = $version;
88 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
89 $this->reload();
90 }
91
97 public function getExe() {
98 return $this->exe;
99 }
100
106 public function getIdleExe() {
107 return $this->idleExe;
108 }
109}
global $bearsamppLang
const ERROR_EXE_NOT_FOUND
const ERROR_CONF_NOT_FOUND
const PYTHON
const ERROR_FILE_NOT_FOUND
setVersion($version)
reload($id=null, $type=null)
__construct($id, $type)
static logError($data, $file=null)
static logInitClass($classInstance)
static logInfo($data, $file=null)
static logReloadClass($classInstance)
global $bearsamppConfig
Definition homepage.php:27