linkkf 로직수정중
This commit is contained in:
@@ -7,9 +7,8 @@ import traceback
|
||||
import zipfile
|
||||
|
||||
import requests
|
||||
from support import SupportFile, SupportSubprocess, SupportYaml
|
||||
|
||||
from framework import F
|
||||
from support import SupportFile, SupportSubprocess, SupportYaml
|
||||
|
||||
|
||||
class PluginManager:
|
||||
@@ -30,13 +29,13 @@ class PluginManager:
|
||||
tmps = os.listdir(plugin_path)
|
||||
add_plugin_list = []
|
||||
for t in tmps:
|
||||
if not t.startswith('_') and os.path.isdir(os.path.join(plugin_path, t)):
|
||||
if t.startswith('_') == False and t.startswith('.') == False and os.path.isdir(os.path.join(plugin_path, t)) and t != 'false' and t != 'tmp':
|
||||
add_plugin_list.append(t)
|
||||
cls.all_package_list[t] = {'pos':'normal', 'path':os.path.join(plugin_path, t), 'loading':(F.config.get('plugin_loading_only_devpath', None) != True)}
|
||||
|
||||
plugins = plugins + add_plugin_list
|
||||
except Exception as exception:
|
||||
F.logger.error('Exception:%s', exception)
|
||||
except Exception as e:
|
||||
F.logger.error(f"Exception:{str(e)}")
|
||||
F.logger.error(traceback.format_exc())
|
||||
|
||||
if F.config.get('plugin_loading_only_devpath', None) == True:
|
||||
@@ -59,12 +58,12 @@ class PluginManager:
|
||||
tmps = os.listdir(__)
|
||||
add_plugin_list = []
|
||||
for t in tmps:
|
||||
if not t.startswith('_') and os.path.isdir(os.path.join(__, t)):
|
||||
if t.startswith('_') == False and t.startswith('.') == False and os.path.isdir(os.path.join(__, t)) and t != 'false' and t != 'tmp':
|
||||
add_plugin_list.append(t)
|
||||
cls.all_package_list[t] = {'pos':'dev', 'path':os.path.join(__, t), 'loading':True}
|
||||
plugins = plugins + add_plugin_list
|
||||
except Exception as exception:
|
||||
F.logger.error('Exception:%s', exception)
|
||||
except Exception as e:
|
||||
F.logger.error(f"Exception:{str(e)}")
|
||||
F.logger.error(traceback.format_exc())
|
||||
|
||||
# plugin_loading_list
|
||||
@@ -79,8 +78,8 @@ class PluginManager:
|
||||
cls.all_package_list[_]['loading'] = False
|
||||
cls.all_package_list[_]['status'] = 'not_include_loading_list'
|
||||
plugins = new_plugins
|
||||
except Exception as exception:
|
||||
F.logger.error('Exception:%s', exception)
|
||||
except Exception as e:
|
||||
F.logger.error(f"Exception:{str(e)}")
|
||||
F.logger.error(traceback.format_exc())
|
||||
|
||||
# plugin_except_list
|
||||
@@ -95,8 +94,8 @@ class PluginManager:
|
||||
cls.all_package_list[_]['loading'] = False
|
||||
cls.all_package_list[_]['status'] = 'include_except_list'
|
||||
plugins = new_plugins
|
||||
except Exception as exception:
|
||||
F.logger.error('Exception:%s', exception)
|
||||
except Exception as e:
|
||||
F.logger.error(f"Exception:{str(e)}")
|
||||
F.logger.error(traceback.format_exc())
|
||||
return plugins
|
||||
|
||||
@@ -113,43 +112,26 @@ class PluginManager:
|
||||
for plugin_name in plugins:
|
||||
F.logger.debug(f'[+] PLUGIN LOADING Start.. [{plugin_name}]')
|
||||
entity = cls.all_package_list[plugin_name]
|
||||
entity['version'] = '3'
|
||||
try:
|
||||
mod = __import__('%s' % (plugin_name), fromlist=[])
|
||||
mod_plugin_info = None
|
||||
try:
|
||||
mod_plugin_info = getattr(mod, 'plugin_info')
|
||||
entity['module'] = mod
|
||||
except Exception as exception:
|
||||
F.logger.info(f'[!] PLUGIN_INFO not exist : [{plugin_name}] - is FF')
|
||||
|
||||
if mod_plugin_info == None:
|
||||
try:
|
||||
mod = __import__(f'{plugin_name}.setup', fromlist=['setup'])
|
||||
entity['version'] = '4'
|
||||
except Exception as e:
|
||||
F.logger.error(f'Exception:{str(e)}')
|
||||
F.logger.error(traceback.format_exc())
|
||||
F.logger.warning(f'[!] NOT normal plugin : [{plugin_name}]')
|
||||
mod = __import__(f'{plugin_name}.setup', fromlist=['setup'])
|
||||
except Exception as e:
|
||||
F.logger.error(f'Exception:{str(e)}')
|
||||
F.logger.error(traceback.format_exc())
|
||||
F.logger.warning(f'[!] NOT normal plugin : [{plugin_name}]')
|
||||
continue
|
||||
|
||||
try:
|
||||
if entity['version'] != '4':
|
||||
mod_blue_print = getattr(mod, 'blueprint')
|
||||
else:
|
||||
entity['setup_mod'] = mod
|
||||
entity['P'] = getattr(mod, 'P')
|
||||
mod_blue_print = getattr(entity['P'], 'blueprint')
|
||||
entity['setup_mod'] = mod
|
||||
entity['P'] = getattr(mod, 'P')
|
||||
mod_blue_print = getattr(entity['P'], 'blueprint')
|
||||
if mod_blue_print:
|
||||
F.app.register_blueprint(mod_blue_print)
|
||||
except Exception as exception:
|
||||
#logger.error('Exception:%s', exception)
|
||||
#logger.error(traceback.format_exc())
|
||||
F.logger.warning(f'[!] BLUEPRINT not exist : [{plugin_name}]')
|
||||
cls.plugin_list[plugin_name] = entity
|
||||
#system.LogicPlugin.current_loading_plugin_list[plugin_name]['status'] = 'success'
|
||||
#system.LogicPlugin.current_loading_plugin_list[plugin_name]['info'] = mod_plugin_info
|
||||
except Exception as exception:
|
||||
F.logger.error('Exception:%s', exception)
|
||||
except Exception as e:
|
||||
F.logger.error(f"Exception:{str(e)}")
|
||||
F.logger.error(traceback.format_exc())
|
||||
F.logger.debug('no blueprint')
|
||||
cls.all_package_list[plugin_name]['loading'] = False
|
||||
@@ -157,36 +139,50 @@ class PluginManager:
|
||||
cls.all_package_list[plugin_name]['log'] = traceback.format_exc()
|
||||
|
||||
|
||||
|
||||
if not F.config['run_celery']:
|
||||
try:
|
||||
with F.app.app_context():
|
||||
F.db.create_all()
|
||||
except Exception as exception:
|
||||
F.logger.error('Exception:%s', exception)
|
||||
except Exception as e:
|
||||
F.logger.error(f"Exception:{str(e)}")
|
||||
F.logger.error(traceback.format_exc())
|
||||
F.logger.debug('db.create_all error')
|
||||
|
||||
if F.config['run_celery']:
|
||||
for key, entity in cls.plugin_list.items():
|
||||
try:
|
||||
mod_plugin_load = getattr(entity['P'], 'plugin_load_celery')
|
||||
if mod_plugin_load:
|
||||
def func(mod_plugin_load, key):
|
||||
try:
|
||||
#F.logger.debug(f'[!] plugin_load_celery threading start : [{key}]')
|
||||
mod_plugin_load()
|
||||
#F.logger.debug(f'[!] plugin_load_celery threading end : [{key}]')
|
||||
except Exception as e:
|
||||
F.logger.error(f"Exception:{str(e)}")
|
||||
F.logger.error(traceback.format_exc())
|
||||
t = threading.Thread(target=func, args=(mod_plugin_load, key))
|
||||
t.setDaemon(True)
|
||||
t.start()
|
||||
except Exception as e:
|
||||
F.logger.error(f"Exception:{str(e)}")
|
||||
F.logger.error(traceback.format_exc())
|
||||
|
||||
if not F.config['run_flask']:
|
||||
return
|
||||
|
||||
for key, entity in cls.plugin_list.items():
|
||||
try:
|
||||
mod_plugin_load = None
|
||||
if entity['version'] == '3':
|
||||
mod_plugin_load = getattr(entity['module'], 'plugin_load')
|
||||
elif entity['version'] == '4':
|
||||
mod_plugin_load = getattr(entity['P'], 'plugin_load')
|
||||
mod_plugin_load = getattr(entity['P'], 'plugin_load')
|
||||
if mod_plugin_load:
|
||||
def func(mod_plugin_load, key):
|
||||
try:
|
||||
F.logger.debug(f'[!] plugin_load threading start : [{key}]')
|
||||
#mod.plugin_load()
|
||||
F.logger.info(f'[!] plugin_load threading start : [{key}]')
|
||||
mod_plugin_load()
|
||||
F.logger.debug(f'[!] plugin_load threading end : [{key}]')
|
||||
except Exception as exception:
|
||||
except Exception as e:
|
||||
F.logger.error('### plugin_load exception : %s', key)
|
||||
F.logger.error('Exception:%s', exception)
|
||||
F.logger.error(f"Exception:{str(e)}")
|
||||
F.logger.error(traceback.format_exc())
|
||||
cls.all_package_list[key]['loading'] = False
|
||||
cls.all_package_list[key]['status'] = 'plugin_load error'
|
||||
@@ -199,42 +195,29 @@ class PluginManager:
|
||||
MenuManager.init_menu()
|
||||
F.logger.info(f"플러그인 로딩 실패로 메뉴 삭제2 : {key}")
|
||||
|
||||
t = threading.Thread(target=func, args=(mod_plugin_load, key))
|
||||
t.setDaemon(True)
|
||||
t.start()
|
||||
|
||||
# mod는 위에서 로딩
|
||||
if key != 'mod':
|
||||
t = threading.Thread(target=func, args=(mod_plugin_load, key))
|
||||
t.setDaemon(True)
|
||||
t.start()
|
||||
#if key == 'mod':
|
||||
# t.join()
|
||||
except Exception as exception:
|
||||
except Exception as e:
|
||||
F.logger.debug(f'[!] PLUGIN_LOAD function not exist : [{key}]')
|
||||
#logger.error('Exception:%s', exception)
|
||||
#logger.error(traceback.format_exc())
|
||||
#logger.debug('no init_scheduler')
|
||||
|
||||
try:
|
||||
mod_menu = None
|
||||
if entity['version'] == '3':
|
||||
mod_menu = getattr(entity['module'], 'menu')
|
||||
elif entity['version'] == '4':
|
||||
mod_menu = getattr(entity['P'], 'menu')
|
||||
|
||||
mod_menu = getattr(entity['P'], 'menu')
|
||||
if mod_menu and cls.all_package_list[key]['loading'] != False:
|
||||
cls.plugin_menus[key]= {'menu':mod_menu, 'match':False}
|
||||
if entity['version'] == '4':
|
||||
setting_menu = getattr(entity['P'], 'setting_menu')
|
||||
if setting_menu != None and cls.all_package_list[key]['loading'] != False:
|
||||
F.logger.info(f"메뉴 포함 : {key}")
|
||||
cls.setting_menus.append(setting_menu)
|
||||
|
||||
|
||||
setting_menu = getattr(entity['P'], 'setting_menu')
|
||||
setting_menu['plugin'] = entity['P'].package_name
|
||||
if setting_menu != None and cls.all_package_list[key]['loading'] != False:
|
||||
F.logger.info(f"확장 설정 : {key}")
|
||||
cls.setting_menus.append(setting_menu)
|
||||
except Exception as exception:
|
||||
F.logger.debug('no menu')
|
||||
F.logger.debug('### plugin_load threading all start.. : %s ', len(cls.plugin_list))
|
||||
# 모든 모듈을 로드한 이후에 app 등록, table 생성, start
|
||||
|
||||
except Exception as exception:
|
||||
F.logger.error('Exception:%s', exception)
|
||||
except Exception as e:
|
||||
F.logger.error(f"Exception:{str(e)}")
|
||||
F.logger.error(traceback.format_exc())
|
||||
|
||||
|
||||
@@ -243,17 +226,9 @@ class PluginManager:
|
||||
def plugin_unload(cls):
|
||||
for key, entity in cls.plugin_list.items():
|
||||
try:
|
||||
if entity['version'] == '3':
|
||||
mod_plugin_unload = getattr(entity['module'], 'plugin_unload')
|
||||
elif entity['version'] == '4':
|
||||
mod_plugin_unload = getattr(entity['P'], 'plugin_unload')
|
||||
|
||||
#if plugin_name == 'rss':
|
||||
# continue
|
||||
#mod_plugin_unload = getattr(mod, 'plugin_unload')
|
||||
mod_plugin_unload = getattr(entity['P'], 'plugin_unload')
|
||||
if mod_plugin_unload:
|
||||
mod_plugin_unload()
|
||||
#mod.plugin_unload()
|
||||
except Exception as e:
|
||||
F.logger.error('module:%s', key)
|
||||
F.logger.error(f'Exception:{str(e)}')
|
||||
@@ -267,6 +242,7 @@ class PluginManager:
|
||||
|
||||
@classmethod
|
||||
def plugin_install(cls, plugin_git, zip_url=None, zip_filename=None):
|
||||
plugin_git = plugin_git.strip()
|
||||
is_git = True if plugin_git != None and plugin_git != '' else False
|
||||
ret = {}
|
||||
try:
|
||||
@@ -381,7 +357,7 @@ class PluginManager:
|
||||
tmps = os.listdir(plugins_path)
|
||||
for t in tmps:
|
||||
plugin_path = os.path.join(plugins_path, t)
|
||||
if t.startswith('_'):
|
||||
if t.startswith('_') or t.startswith('.'):
|
||||
continue
|
||||
if os.path.exists(os.path.join(plugin_path, '.git')):
|
||||
command = ['git', '-C', plugin_path, 'reset', '--hard', 'HEAD']
|
||||
@@ -392,14 +368,15 @@ class PluginManager:
|
||||
F.logger.debug(ret)
|
||||
else:
|
||||
F.logger.debug(f"{plugin_path} not git repo")
|
||||
except Exception as exception:
|
||||
F.logger.error('Exception:%s', exception)
|
||||
except Exception as e:
|
||||
F.logger.error(f"Exception:{str(e)}")
|
||||
F.logger.error(traceback.format_exc())
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_plugin_instance(cls, package_name):
|
||||
try:
|
||||
return cls.all_package_list[package_name]['P']
|
||||
if cls.all_package_list[package_name]['loading']:
|
||||
return cls.all_package_list[package_name]['P']
|
||||
except:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user