From ad36c8493054eabd441060a5604d329d8c6b73b1 Mon Sep 17 00:00:00 2001 From: flaskfarm Date: Mon, 10 Oct 2022 11:40:10 +0900 Subject: [PATCH] update --- lib/framework/init_plugin.py | 61 +++--- lib/framework/static/js/ff_ui1.js | 13 +- lib/framework/templates/macro.html | 4 + lib/support/__init__.py | 5 +- lib/system/mod_plugin.py | 37 +++- lib/system/setup.py | 7 +- lib/system/templates/system_plugin_list.html | 194 ++++++++----------- 7 files changed, 173 insertions(+), 148 deletions(-) diff --git a/lib/framework/init_plugin.py b/lib/framework/init_plugin.py index 8c0b596..72d8d84 100644 --- a/lib/framework/init_plugin.py +++ b/lib/framework/init_plugin.py @@ -16,6 +16,7 @@ class PluginManager: plugin_list = {} plugin_menus = {} setting_menus = [] + all_package_list = {} @classmethod @@ -29,25 +30,28 @@ class PluginManager: plugins = os.listdir(plugin_path) """ plugins = [] - pass_include = [] - except_plugin_list = [] + #2019-07-17 - if F.config.get('plugin_loading_only_devpath', None) != True: - try: - plugin_path = os.path.join(F.config['path_data'], 'plugins') - if os.path.exists(plugin_path) == True and os.path.isdir(plugin_path) == True: - sys.path.insert(1, plugin_path) - 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)): - add_plugin_list.append(t) - plugins = plugins + add_plugin_list - pass_include = pass_include + add_plugin_list - except Exception as exception: - F.logger.error('Exception:%s', exception) - F.logger.error(traceback.format_exc()) + + try: + plugin_path = os.path.join(F.config['path_data'], 'plugins') + if os.path.exists(plugin_path) == True and os.path.isdir(plugin_path) == True: + sys.path.insert(1, plugin_path) + 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)): + add_plugin_list.append(t) + cls.all_package_list[t] = {'pos':'normal', 'path':os.path.join(plugin_path, t)} + + plugins = plugins + add_plugin_list + except Exception as exception: + F.logger.error('Exception:%s', exception) + F.logger.error(traceback.format_exc()) + + if F.config.get('plugin_loading_only_devpath', None) == True: + plugins = [] # 2018-09-04 try: @@ -60,8 +64,8 @@ class PluginManager: for t in tmps: if not t.startswith('_') and os.path.isdir(os.path.join(plugin_path, t)): add_plugin_list.append(t) + cls.all_package_list[t] = {'pos':'dev', 'path':os.path.join(plugin_path, t)} plugins = plugins + add_plugin_list - pass_include = pass_include + add_plugin_list except Exception as exception: F.logger.error('Exception:%s', exception) F.logger.error(traceback.format_exc()) @@ -74,6 +78,9 @@ class PluginManager: for _ in plugins: if _ in plugin_loading_list: new_plugins.append(_) + else: + cls.all_package_list[t]['loading'] = False + cls.all_package_list[t]['status'] = 'not_include_loading_list' plugins = new_plugins except Exception as exception: F.logger.error('Exception:%s', exception) @@ -87,12 +94,17 @@ class PluginManager: for _ in plugins: if _ not in plugin_except_list: new_plugins.append(_) + else: + cls.all_package_list[t]['loading'] = False + cls.all_package_list[t]['status'] = 'include_except_list' plugins = new_plugins except Exception as exception: F.logger.error('Exception:%s', exception) F.logger.error(traceback.format_exc()) return plugins + + # menu, blueprint, plugin_info, plugin_load, plugin_unload @classmethod def plugin_init(cls): @@ -112,7 +124,8 @@ class PluginManager: # F.logger.debug('Except plugin : %s' % frame.plugin_menu) # continue F.logger.debug(f'[+] PLUGIN LOADING Start.. [{plugin_name}]') - entity = {'version':'3'} + entity = cls.all_package_list[plugin_name] + entity['version'] = '3' try: mod = __import__('%s' % (plugin_name), fromlist=[]) mod_plugin_info = None @@ -166,7 +179,6 @@ class PluginManager: entity['P'] = getattr(mod, 'P') mod_blue_print = getattr(entity['P'], 'blueprint') if mod_blue_print: - #if plugin_name in pass_include or is_include_menu(plugin_name): F.app.register_blueprint(mod_blue_print) except Exception as exception: #logger.error('Exception:%s', exception) @@ -179,6 +191,9 @@ class PluginManager: F.logger.error('Exception:%s', exception) F.logger.error(traceback.format_exc()) F.logger.debug('no blueprint') + cls.all_package_list[plugin_name]['loading'] = False + cls.all_package_list[plugin_name]['status'] = 'import fail' + cls.all_package_list[plugin_name]['log'] = traceback.format_exc() #from tool_base import d #logger.error(d(system.LogicPlugin.current_loading_plugin_list)) @@ -227,7 +242,6 @@ class PluginManager: mod_plugin_load = getattr(entity['module'], 'plugin_load') elif entity['version'] == '4': mod_plugin_load = getattr(entity['P'], 'plugin_load') - #if mod_plugin_load and (key in pass_include or is_include_menu(key)): if mod_plugin_load: def func(mod_plugin_load, key): try: @@ -239,6 +253,9 @@ class PluginManager: F.logger.error('### plugin_load exception : %s', key) F.logger.error('Exception:%s', exception) F.logger.error(traceback.format_exc()) + cls.all_package_list[key]['loading'] = False + cls.all_package_list[key]['status'] = 'plugin_load error' + cls.all_package_list[key]['log'] = traceback.format_exc() # mod는 위에서 로딩 if key != 'mod': t = threading.Thread(target=func, args=(mod_plugin_load, key)) @@ -258,7 +275,7 @@ class PluginManager: elif entity['version'] == '4': mod_menu = getattr(entity['P'], 'menu') - if mod_menu:# and (key in pass_include or is_include_menu(key)): + if mod_menu: cls.plugin_menus[key]= {'menu':mod_menu, 'match':False} if entity['version'] == '4': setting_menu = getattr(entity['P'], 'setting_menu') diff --git a/lib/framework/static/js/ff_ui1.js b/lib/framework/static/js/ff_ui1.js index 43c681f..32867af 100644 --- a/lib/framework/static/js/ff_ui1.js +++ b/lib/framework/static/js/ff_ui1.js @@ -81,8 +81,8 @@ function m_col(w, h, align='left') { return str } -function m_col2(w, h, align='left') { - var str = '
'; +function m_col_wide(w, h, align='left') { + var str = '
'; str += h str += '
'; return str @@ -105,6 +105,15 @@ function m_button(id, text, data) { return str; } +function m_button_small(id, text, data, color='danger') { + var str = '
{% endmacro %} +{% macro m_col_wide(width, html, align='left') %} +
{{html}}
+{% endmacro %} + {% macro m_strong(html) %} {{html}} {% endmacro %} diff --git a/lib/support/__init__.py b/lib/support/__init__.py index 611efa9..8d0b56e 100644 --- a/lib/support/__init__.py +++ b/lib/support/__init__.py @@ -1,7 +1,10 @@ def d(data): if type(data) in [type({}), type([])]: import json - return '\n' + json.dumps(data, indent=4, ensure_ascii=False) + try: + return '\n' + json.dumps(data, indent=4, ensure_ascii=False) + except: + return data else: return str(data) diff --git a/lib/system/mod_plugin.py b/lib/system/mod_plugin.py index 42a331e..1185d48 100644 --- a/lib/system/mod_plugin.py +++ b/lib/system/mod_plugin.py @@ -1,3 +1,5 @@ +import shutil + from support import SupportFile from .setup import * @@ -27,7 +29,40 @@ class ModulePlugin(PluginModuleBase): ret = {'ret':'success'} if command == 'plugin_install': ret = F.PluginManager.plugin_install(arg1) - + elif command == 'get_plugin_list': + data = [] + """ + for name, entity in F.PluginManager.plugin_list.items(): + if entity['version'] == '3': + data.append({'package_name':name}) + else: + data.append(entity['P'].plugin_info) + """ + for name, entity in F.PluginManager.all_package_list.items(): + if entity['version'] == '3': + #data.append(entity) + data.append({'package_name':name}) + else: + data.append(entity['P'].plugin_info) + data[-1]['loading'] = entity.get('loading') + data[-1]['status'] = entity.get('status') + data[-1]['log'] = entity.get('log') + ret['data'] = data + #P.logger.debug(data) + elif command == 'uninstall': + info = F.PluginManager.all_package_list[arg1] + if os.path.exists(info['path']): + try: + shutil.rmtree(info['path']) + ret['msg'] = '삭제하였습니다.
재시작시 적용됩니다.' + except Exception as e: + P.logger.error(f'Exception:{str(e)}') + P.logger.error(traceback.format_exc()) + ret['msg'] = info['path'] + "
삭제에 실패하였습니다.
" + str(e) + ret['ret'] = 'danger' + else: + ret['msg'] = info['path'] + "
폴더가 없습니다." + ret['ret'] = 'danger' return jsonify(ret) diff --git a/lib/system/setup.py b/lib/system/setup.py index 9646915..8001362 100644 --- a/lib/system/setup.py +++ b/lib/system/setup.py @@ -20,11 +20,10 @@ __menu = { 'uri': 'plugin', 'name': '플러그인', 'list': [ - {'uri': 'setting', 'name': '개발 설정'}, - {'uri': 'list', 'name': '플러그인 목록'}, + {'uri': 'setting', 'name': '설정'}, + {'uri': 'list', 'name': '로딩 플러그인'}, ], }, - { 'uri': 'tool', 'name': '시스템 툴', @@ -73,9 +72,9 @@ try: SystemModelSetting = P.ModelSetting from .mod_home import ModuleHome + from .mod_plugin import ModulePlugin from .mod_route import ModuleRoute from .mod_setting import ModuleSetting - from .mod_plugin import ModulePlugin from .mod_tool import ModuleTool P.set_module_list([ModuleHome, ModuleRoute, ModuleSetting, ModulePlugin, ModuleTool]) diff --git a/lib/system/templates/system_plugin_list.html b/lib/system/templates/system_plugin_list.html index c61f78d..56c1d8c 100644 --- a/lib/system/templates/system_plugin_list.html +++ b/lib/system/templates/system_plugin_list.html @@ -8,151 +8,109 @@
- - - -
+