2024.8.23
Loading...
Searching...
No Matches
class.tool.python.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
10/**
11 * Class ToolPython
12 *
13 * This class represents a Python tool module in the Bearsampp application.
14 * It extends the abstract Module class and provides specific functionalities
15 * for managing Python executables and configurations.
16 */
17class ToolPython extends Module
18{
19 const ROOT_CFG_VERSION = 'pythonVersion';
20
21 const LOCAL_CFG_EXE = 'pythonExe';
22 const LOCAL_CFG_CP_EXE = 'pythonCpExe';
23 const LOCAL_CFG_IDLE_EXE = 'pythonIdleExe';
24
25 private $exe;
26 private $cpExe;
27 private $idleExe;
28
29 /**
30 * Constructor for the ToolPython class.
31 *
32 * @param string $id The ID of the module.
33 * @param string $type The type of the module.
34 */
35 public function __construct($id, $type) {
36 Util::logInitClass($this);
37 $this->reload($id, $type);
38 }
39
40 /**
41 * Reloads the module configuration based on the provided ID and type.
42 *
43 * @param string|null $id The ID of the module. If null, the current ID is used.
44 * @param string|null $type The type of the module. If null, the current type is used.
45 */
46 public function reload($id = null, $type = null) {
49
50 $this->name = $bearsamppLang->getValue(Lang::PYTHON);
51 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
52 parent::reload($id, $type);
53
54 if ($this->bearsamppConfRaw !== false) {
55 $this->exe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
56 $this->cpExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CP_EXE];
57 $this->idleExe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_IDLE_EXE];
58 }
59
60 if (!$this->enable) {
61 Util::logInfo($this->name . ' is not enabled!');
62 return;
63 }
64 if (!is_dir($this->currentPath)) {
65 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
66 }
67 if (!is_dir($this->symlinkPath)) {
68 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
69 return;
70 }
71 if (!is_file($this->bearsamppConf)) {
72 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
73 }
74 if (!is_file($this->exe)) {
75 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exe));
76 }
77 if (!is_file($this->cpExe)) {
78 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->cpExe));
79 }
80 if (!is_file($this->idleExe)) {
81 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->idleExe));
82 }
83 }
84
85 /**
86 * Sets the version of the Python module and reloads the configuration.
87 *
88 * @param string $version The version to set.
89 */
90 public function setVersion($version) {
91 global $bearsamppConfig;
92 $this->version = $version;
93 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
94 $this->reload();
95 }
96
97 /**
98 * Gets the path to the Python executable.
99 *
100 * @return string The path to the Python executable.
101 */
102 public function getExe() {
103 return $this->exe;
104 }
105
106 /**
107 * Gets the path to the Python CP executable.
108 *
109 * @return string The path to the Python CP executable.
110 */
111 public function getCpExe() {
112 return $this->cpExe;
113 }
114
115 /**
116 * Gets the path to the Python IDLE executable.
117 *
118 * @return string The path to the Python IDLE executable.
119 */
120 public function getIdleExe() {
121 return $this->idleExe;
122 }
123}
global $bearsamppLang
const PYTHON
const ERROR_FILE_NOT_FOUND
const ERROR_CONF_NOT_FOUND
const ERROR_EXE_NOT_FOUND
__construct($id, $type)
reload($id=null, $type=null)
setVersion($version)
static logReloadClass($classInstance)
static logError($data, $file=null)
static logInitClass($classInstance)
static logInfo($data, $file=null)
global $bearsamppConfig
Definition homepage.php:26