day87.2

import os
import sys
import importlib  # 下文的 v 为字符串类型无法导入,需借助importlib模块
import requests

BASEDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASEDIR)    #将根目录auto_client添加到环境变量
from conf import settings

server_info = {}
for k,v in settings.PLUGIN_ITEMS.items():
    print(k,v,type(v))

    module_path,cls_name =v.rsplit(".",maxsplit=1)  #从右侧的.分割v
    module = importlib.import_module(module_path)   
    cls = getattr(module,cls_name)      #通过字符串cls_name取到cls
    obj = cls()
    ret = obj.process() #执行类下process的函数
    server_info[k]= ret

requests.post(
    url=settings.API,
    data = server_info,
)





posted @ 2017-09-25 15:04  hsddon  阅读(109)  评论(0编辑  收藏  举报