mirror of
https://github.com/kuitoi/kuitoi-Server.git
synced 2026-06-19 15:11:25 +00:00
[+] Add supports for pip packets
This commit is contained in:
@@ -7,17 +7,15 @@
|
|||||||
# Licence: FPA
|
# Licence: FPA
|
||||||
# (c) kuitoi.su 2023
|
# (c) kuitoi.su 2023
|
||||||
import asyncio
|
import asyncio
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
@@ -118,12 +116,19 @@ 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)
|
sys.path.append(self._pip_dir)
|
||||||
|
os.makedirs(self._pip_dir, exist_ok=True)
|
||||||
|
console.add_command("install", self._pip_install)
|
||||||
|
|
||||||
def _pip_install(self, x):
|
def _pip_install(self, x):
|
||||||
|
self.log.debug(f"_pip_install {x}")
|
||||||
if len(x) > 0:
|
if len(x) > 0:
|
||||||
pip_main(['install', x[0], '--target', self._pip_dir])
|
try:
|
||||||
|
subprocess.check_call(['pip', 'install', *x, '--target', self._pip_dir])
|
||||||
|
return "Success"
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
self.log.debug(f"error: {e}")
|
||||||
|
return f"Failed to install packages"
|
||||||
else:
|
else:
|
||||||
return "Invalid syntax"
|
return "Invalid syntax"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user