|
|
|
@ -8,7 +8,10 @@ |
|
|
|
|
# Author: midoks <midoks@163.com> |
|
|
|
|
# --------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
import os |
|
|
|
|
import threading |
|
|
|
|
import json |
|
|
|
|
import core.mw as mw |
|
|
|
|
|
|
|
|
|
class MwPlugin(object): |
|
|
|
|
|
|
|
|
@ -55,12 +58,14 @@ class MwPlugin(object): |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
__plugin_dir = 'plugins' |
|
|
|
|
|
|
|
|
|
# lock |
|
|
|
|
_instance_lock = threading.Lock() |
|
|
|
|
|
|
|
|
|
"""docstring for MwPlugin""" |
|
|
|
|
"""插件类初始化""" |
|
|
|
|
def __init__(self): |
|
|
|
|
pass |
|
|
|
|
self.__plugin_dir = mw.getPluginDir() |
|
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
|
def instance(cls, *args, **kwargs): |
|
|
|
@ -70,6 +75,66 @@ class MwPlugin(object): |
|
|
|
|
MwPlugin._instance = MwPlugin(*args, **kwargs) |
|
|
|
|
return MwPlugin._instance |
|
|
|
|
|
|
|
|
|
# 插件搜索匹配 |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
def getList( |
|
|
|
|
self, |
|
|
|
@ -81,6 +146,9 @@ class MwPlugin(object): |
|
|
|
|
rdata = {} |
|
|
|
|
rdata['type'] = self.def_plugin_type |
|
|
|
|
# print(type,keyword,page,size) |
|
|
|
|
|
|
|
|
|
self.getAllPluginList(type,keyword, page, size) |
|
|
|
|
|
|
|
|
|
return rdata |
|
|
|
|
|
|
|
|
|
|
|
|
|
|