Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/web/utils/mwplugin.py

156 lines
3.8 KiB

7 months ago
# coding:utf-8
# ---------------------------------------------------------------------------------
# MW-Linux面板
# ---------------------------------------------------------------------------------
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
# ---------------------------------------------------------------------------------
# Author: midoks <midoks@163.com>
# ---------------------------------------------------------------------------------
7 months ago
import os
7 months ago
import threading
7 months ago
import json
import core.mw as mw
7 months ago
class MwPlugin(object):
def_plugin_type = [
{
"title":"全部",
"type":0,
"ps":""
},
{
"title":"已安装",
"type":-1,
"ps":""
},
{
"title":"运行环境",
"type":1,
"ps":""
},
{
"title":"数据软件",
"type":2,
"ps":""
},
{
"title":"代码管理",
"type":3,
"ps":""
},
{
"title":"系统工具",
"type":4,
"ps":""
},
{
"title":"其他插件",
"type":5,
"ps":""
},
{
"title":"辅助插件",
"type":6,
"ps":""
}
]
7 months ago
__plugin_dir = 'plugins'
7 months ago
# lock
_instance_lock = threading.Lock()
7 months ago
"""插件类初始化"""
7 months ago
def __init__(self):
7 months ago
self.__plugin_dir = mw.getPluginDir()
7 months ago
@classmethod
def instance(cls, *args, **kwargs):
if not hasattr(MwPlugin, "_instance"):
with MwPlugin._instance_lock:
if not hasattr(MwPlugin, "_instance"):
MwPlugin._instance = MwPlugin(*args, **kwargs)
return MwPlugin._instance
7 months ago
# 插件搜索匹配
def searchKey(self, info, keyword):
try:
if info['title'].lower().find(keyword) > -1:
return True
if info['ps'].lower().find(keyword) > -1:
return True
if info['name'].lower().find(keyword) > -1:
return True
except Exception as e:
return False
# 对多版本共存进行处理
def makeCoexistList(self):
plugins_info = []
return plugins_info
def getPluginInfo(self, name,
keyword: str | None = None,
type: str | None = None,
):
info = []
path = self.__plugin_dir + '/' + name
info_path = path + '/info.json'
if not os.path.exists(info_path):
return info
try:
data = json.loads(mw.readFile(info_path))
except Exception as e:
return info
# 判断是否搜索
if keyword != '' and not self.searchKey(data, keyword):
return info
tmp_plugin_info = self.makeCoexistList(data, type)
print(tmp_plugin_info)
return info
def getAllPluginList(
self,
type: str | None = None,
keyword: str | None = None,
page: str | None = 1,
size: str | None = 10,
):
plugins_info = []
# print(mw.getPluginDir())
for name in os.listdir(self.__plugin_dir):
if name.startswith('.'):
continue
plugin_list = self.getPluginInfo(name,keyword,type=type)
# print(dirinfo)
return plugins_info
7 months ago
def getList(
self,
type: str | None = None,
keyword: str | None = None,
page: str | None = 1,
size: str | None = 10,
) -> object:
rdata = {}
rdata['type'] = self.def_plugin_type
# print(type,keyword,page,size)
7 months ago
self.getAllPluginList(type,keyword, page, size)
7 months ago
return rdata