[+] preparations for pip

This commit is contained in:
2024-07-25 18:58:53 +03:00
parent 209004c9cb
commit c12a91bf86
2 changed files with 12 additions and 14 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ __title__ = 'KuiToi-Server'
__description__ = 'BeamingDrive Multiplayer server compatible with BeamMP clients.' __description__ = 'BeamingDrive Multiplayer server compatible with BeamMP clients.'
__url__ = 'https://github.com/kuitoi/kuitoi-Server' __url__ = 'https://github.com/kuitoi/kuitoi-Server'
__version__ = '0.4.7' __version__ = '0.4.7'
__build__ = 2462 # Я это считаю лог файлами __build__ = 2469 # Я это считаю лог файлами
__author__ = 'SantaSpeen' __author__ = 'SantaSpeen'
__author_email__ = 'admin@kuitoi.su' __author_email__ = 'admin@kuitoi.su'
__license__ = "FPA" __license__ = "FPA"
+11 -13
View File
@@ -10,13 +10,14 @@ import asyncio
import importlib import importlib
import inspect import inspect
import os import os
import subprocess
import sys import sys
import types import types
from contextlib import contextmanager from contextlib import contextmanager
from pathlib import Path from pathlib import Path
from threading import Thread from threading import Thread
from pip._internal.utils.entrypoints import main as pip_main
from core import get_logger from core import get_logger
@@ -101,20 +102,9 @@ class KuiToi:
self.log.debug("Requests add_command") self.log.debug("Requests add_command")
return console.add_command(key, func, man, desc, custom_completer) return console.add_command(key, func, man, desc, custom_completer)
def install_and_import(self, package):
self.log.debug(f"Import package: {package}")
try:
# Попробуйте импортировать пакет
importlib.import_module(package)
except ImportError:
# Если пакет не установлен, установите его
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
finally:
# Попробуйте еще раз импортировать пакет
return importlib.import_module(package)
class PluginsLoader: class PluginsLoader:
_pip_dir = str(Path("pip-packets").resolve())
def __init__(self, plugins_dir): def __init__(self, plugins_dir):
self.loop = asyncio.get_event_loop() self.loop = asyncio.get_event_loop()
@@ -128,6 +118,14 @@ class PluginsLoader:
ev.register("_plugins_get", lambda x: list(self.plugins.keys())) ev.register("_plugins_get", lambda x: list(self.plugins.keys()))
console.add_command("plugins", lambda x: self.loaded_str[:-2]) console.add_command("plugins", lambda x: self.loaded_str[:-2])
console.add_command("pl", lambda x: self.loaded_str[:-2]) console.add_command("pl", lambda x: self.loaded_str[:-2])
console.add_command("install", self._pip_install)
sys.path.append(self._pip_dir)
def _pip_install(self, x):
if len(x) > 0:
pip_main(['install', x[0], '--target', self._pip_dir])
else:
return "Invalid syntax"
async def load(self): async def load(self):
self.log.debug("Loading plugins...") self.log.debug("Loading plugins...")