Ejemplo n.º 1
0
class JsonParser(object):
    def __init__(self):
        self.json_obj = None
        self.fc = FileChecKController()
        if self.fc.is_has_file("android_devices_info.json"):
            self.json_file_path = self.fc.get_fileabspath()
        self.log4py = LoggingController()

    def load_json(self, json_file_path):
        fin = open(json_file_path, "r")
        try:
            json_obj = json.load(fin)
            self.log4py.info("加载了%s文件" % json_file_path)
        except ValueError, e:
            json_obj = {}
        fin.close()
        return json_obj
Ejemplo n.º 2
0
class DeviceController():
    def __init__(self):
        self.android = AdbCmder()
        self.log4py = LoggingController()

    '''
        获取连接上电脑的手机设备,返回一个设备名的list
    '''

    def get_devices(self):
        sno_list = self.android.get_device_list()
        return sno_list

    '''
    根据不同的需求,设计了返回dict和list格式的两个function。
    '''

    def get_infos_as_dict(self):
        try:
            info = {}
            lists = self.get_devices()
            if not lists or len(lists) <= 0:
                self.log4py.info("NO Device connected")
                return None
            for sno in lists:
                sno, phone_brand, phone_model, os_version, ram, dpi, image_resolution, ip = self.get_info(
                    sno)
                info[sno] = {
                    "phone_brand": phone_brand,
                    "phone_model": phone_model,
                    "ram": ram,
                    "os_version": os_version,
                    "dpi": dpi,
                    "image_resolution": image_resolution,
                    "ip": ip
                }
            return info
        except TypeError, e:
            self.log4py.error(e)
            return None
Ejemplo n.º 3
0
class FileChecKController():
    def __init__(self):
        self.__fileabspath = None  #不可访问的
        self.__logger = LoggingController()

    '''
    是否存在指定的文件,路径默认为当前项目的目录
    '''

    def is_has_file(self, filename):
        propath = self.get_project_path()
        boolean = self.is_path_has_file(propath, filename)
        return boolean

    '''
    指定目录下是否存在指定的文件
    '''

    def is_path_has_file(self, path, filename):
        boolean = self.check_has_file(path, filename)
        return boolean

    '''
   扫描指定目录下的所有文件,找到所要找的文件,return True or False
     '''

    def check_has_file(self, path, filename):
        try:
            for filep, dirs, filelist in os.walk(path):
                for fl in filelist:
                    if cmp(fl, filename) == 0:  #这个字符串的比较存在风险,python3不支持,待修改
                        self.__fileabspath = os.path.join(filep, fl)
                        self.__logger.info("查找的%s文件存在" % filename)
                        return True
            return False
        except Exception, e:
            self.__logger.error("check_has_file()方法出现异常" + str(e))
Ejemplo n.º 4
0
class ServicePort(object):
    def __init__(self):
        self.log4py = LoggingController()
        path_obj = GetAllPathController()
        self.appium_log_path = path_obj.get_appium_logs_path()
        self.appium_port_list = []
        self.bootstrap_port_list = []
        self.device_list = []
        self.cfg = CreateConfigFile()
        self.tmp = {}

    def is_port_used(self, port_num):
        """
        检查端口是否被占用
        netstat -aon | findstr port 能够获得到内容证明端口被占用
        """
        flag = False
        try:
            port_res = subprocess.Popen(
                'netstat -ano | findstr %s | findstr LISTENING' % port_num,
                shell=True,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE).stdout.readlines()
            reg = re.compile(str(port_num))
            for i in range(len(port_res)):
                ip_port = port_res[i].strip().split("   ")
                if re.search(reg, ip_port[1]):
                    flag = True
                    self.log4py.info(
                        str(port_num) + " 端口已经在使用,对应的进程是:" + str(ip_port[-1]))
                    self.tmp[port_num] = ip_port[-1]
            if not flag:
                self.log4py.info(str(port_num) + " 端口没有被占用.")
        except Exception, e:
            self.log4py.error(
                str(port_num) + " port get occupied status failure: " + str(e))
        return flag
Ejemplo n.º 5
0
class WindowCmder(object):

    def __init__(self):
        self.log4py = LoggingController()

    def is_port_used(self, port_num):
        """
        检查端口是否被占用
        netstat -aon | findstr port 能够获得到内容证明端口被占用
        :param port_num: 
        :return: 
        """
        flog = True
        try:
            port_res = subprocess.Popen('netstat -ano | findstr %s' % port_num, shell=True, stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE).stdout.readlines()
            if len(port_res) <= 0:
                self.log4py.info(str(port_num) + " port unoccupied.")
                flog = False
            else:
                self.log4py.error(str(port_num) + " port has been occupied.")
        except Exception, e:
            self.log4py.error(str(port_num) + " port get occupied status failure: " + str(e))
        return flog
Ejemplo n.º 6
0
class GetAllPathController(object):
    def __init__(self):
        self.fkctl = FileChecKController()
        if self.fkctl.is_has_file("allpath.ini"):
            fp = self.fkctl.get_fileabspath()
        self.cfgctl = ConfigController(fp)
        self.log4py = LoggingController()
        self.pro_path = self.fkctl.get_project_path()

    def get_dumpxml_path(self):
        self.log4py.info("executive -get_dumpxml_path- function ")
        path = os.path.join(self.pro_path, self.cfgctl.get("dumpxmlPath", "dumpxmlPath"))
        if PATH(path):
            self.log4py.info("获取 %s"%path)
            return path
        return None

    def get_htmlreport_path(self):
        self.log4py.info("executive -get_htmlreport_path- function ")
        path = os.path.join(self.pro_path, self.cfgctl.get("htmlreportPath", "htmlreportPath"))
        if PATH(path):
            self.log4py.info("获取 %s" % path)
            return path
        return None

    def get_logs_path(self):
        self.log4py.info("executive -get_logs_path- function ")
        path = os.path.join(self.pro_path, self.cfgctl.get("logsPath", "logsPath"))
        if PATH(path):
            if not os.path.exists(path):
                os.makedirs(path)
            self.log4py.info("获取 %s" % path)
            return path
        return None

    def get_capture_path(self):
        self.log4py.info("executive get_logs_path function ")
        path = os.path.join(self.pro_path, self.cfgctl.get("capturePath", "capturePath"))
        if PATH(path):
            self.log4py.info("获取 %s" % path)
            return path
        return None

    def get_appium_logs_path(self):
        self.log4py.info("executive  get_logs_path  function ")
        path = os.path.join(self.pro_path, self.cfgctl.get("appiumlogPath", "appiumlogPath"))
        if PATH(path):
            if not os.path.exists(path):
                os.makedirs(path)
            self.log4py.info("获取到appium服务的日志路径 %s" % path)
            return path.replace("\\", "/")
        return None