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.

94 lines
3.6 KiB

3 years ago
  1. #coding: utf-8
  2. import public,os,sys,json
  3. #获取插件列表(0/1)
  4. def get_plugin_list(force = 0):
  5. api_root_url = 'https://api.bt.cn'
  6. api_url = api_root_url+ '/panel/get_plugin_list'
  7. cache_file = 'data/plugin_list.json'
  8. if force==0 and os.path.exists(cache_file):
  9. jsonData = public.readFile(cache_file)
  10. softList = json.loads(jsonData)
  11. else:
  12. try:
  13. jsonData = public.HttpGet(api_url)
  14. except Exception as ex:
  15. raise public.error_conn_cloud(str(ex))
  16. softList = json.loads(jsonData)
  17. if type(softList)!=dict or 'list' not in softList: raise Exception('云端插件列表获取失败')
  18. public.writeFile(cache_file, jsonData)
  19. return softList
  20. #获取授权状态() 返回:0.免费版 1.专业版 2.企业版 -1.获取失败
  21. def get_auth_state():
  22. try:
  23. softList = get_plugin_list()
  24. if softList['ltd'] > -1:
  25. return 2
  26. elif softList['pro'] > -1:
  27. return 1
  28. else:
  29. return 0
  30. except:
  31. return -1
  32. #执行插件方法(插件名,方法名,参数)
  33. def plugin_run(plugin_name, def_name, args):
  34. if not plugin_name or not def_name: return public.returnMsg(False,'插件名称和插件方法名称不能为空!')
  35. p_path = public.get_plugin_path(plugin_name)
  36. if not os.path.exists(p_path + '/index.php') and not os.path.exists(p_path + '/%s_main.py' % plugin_name): return public.returnMsg(False,'插件不存在!')
  37. is_php = os.path.exists(p_path + '/index.php')
  38. if not is_php:
  39. public.package_path_append(p_path)
  40. plugin_main = __import__(plugin_name + '_main')
  41. try:
  42. if sys.version_info[0] == 2:
  43. reload(plugin_main)
  44. else:
  45. from imp import reload
  46. reload(plugin_main)
  47. except:
  48. pass
  49. plu = eval('plugin_main.' + plugin_name + '_main()')
  50. if not hasattr(plu, def_name):
  51. return public.returnMsg(False,'在[%s]插件中找不到[%s]方法' % (plugin_name,def_name))
  52. if 'plugin_get_object' in args and args.plugin_get_object == 1:
  53. if not is_php:
  54. return getattr(plu, def_name)
  55. else:
  56. return None
  57. else:
  58. if not is_php:
  59. data = eval('plu.' + def_name + '(args)')
  60. else:
  61. import panelPHP
  62. args.s = def_name
  63. args.name = plugin_name
  64. data = panelPHP.panelPHP(plugin_name).exec_php_script(args)
  65. return data
  66. #执行模块方法(模块名,方法名,参数)
  67. def module_run(mod_name, def_name, args):
  68. if not mod_name or not def_name: return public.returnMsg(False,'模块名称和模块方法名称不能为空!')
  69. mod_file = "{}/projectModel/{}Model.py".format(public.get_class_path(),mod_name)
  70. if not os.path.exists(mod_file):
  71. mod_file = "{}/databaseModel/{}Model.py".format(public.get_class_path(),mod_name)
  72. if not os.path.exists(mod_file):
  73. return public.returnMsg(False,'模块[%s]不存在' % mod_name)
  74. def_object = public.get_script_object(mod_file)
  75. if not def_object: return public.returnMsg(False,'模块[%s]不存在!' % mod_name)
  76. try:
  77. run_object = getattr(def_object.main(),def_name,None)
  78. except:
  79. return public.returnMsg(False,'模块入口实例化失败' % mod_name)
  80. if not run_object: return public.returnMsg(False,'在[%s]模块中找不到[%s]方法' % (mod_name,def_name))
  81. if 'module_get_object' in args and args.module_get_object == 1:
  82. return run_object
  83. result = run_object(args)
  84. return result