Esempio n. 1
0
def startAppWithConfig(params):
    MLog.debug(u"程序启动...")
    os.system("python -m uiautomator2 init")
    time.sleep(10)
    # 取序列号
    start_time = datetime.datetime.now()
    serial = getDevices()
    MLog.info(u"读取到的序列号 = " + str(serial))
    devices = []
    pool = Pool(len(serial) + 1)  # 取电脑核数
    for index in range(len(serial)):
        serial_number = serial[index]
        MLog.info(u"启动一个新进程 : index = " + str(index) + u" serial_number = " +
                  serial_number)
        deviceInfo = DeviceInfo(serial_number)
        devices.append(deviceInfo.getDeviceInfo())
        # pool.apply_async(test_main, args=(serial_number,))
        # 下面方法注释开会导致进程阻塞,debug时可以打开,运行时注释掉!!!
        result = pool.apply_async(test_main, args=(
            serial_number,
            1,
            params,
        ))
        result.get()
    pool.close()
    pool.join()
    # 生成图表
    create_lines(devices, getApkName())

    # sendEmailWithDefaultConfig()  # 发邮件
    end_time = datetime.datetime.now()
    MLog.info("all time = {}".format(end_time - start_time))
    MLog.info(u"end main...")
Esempio n. 2
0
def sendEmailWithDefaultConfig():
    user = u"*****@*****.**"
    password = u"lcqctgdcbvklghde"
    to_users = u"[email protected], [email protected],[email protected]"
    conf = Config("default.ini")
    apk_name = conf.getconf("default").apk_name
    conf = Config("default.ini")
    event = conf.getconf("serial").serial_number
    serial = event.split(',')
    deviceInfo = DeviceInfo(serial[0])
    subject = deviceInfo.getDeviceInfo() + apk_name + u"启动时间数据分析"
    content = u"数据分析详见附件:"
    contentType = u"application/octet-stream"
    try:

        log_file = make_log_patch()

        patchFile = []
        MLog.debug(u"sendmail sendEmailWithDefaultConfig: 收集邮件附件:")
        for files in os.walk(chart_data_path):
            for f in files[2]:
                new_file_path = files[0] + f
                patchFile.append(new_file_path)

        patchFile.append(log_file)

        MLog.debug(u"sendmail sendEmailWithDefaultConfig: " + str(patchFile))

    except Exception, e:
        MLog.error(u"sendmail sendEmailWithDefaultConfig: 收集附件失败! e = " +
                   repr(e))
        patchFile = None
Esempio n. 3
0
def get_device_params():
    conf = Config("default.ini")
    event = conf.getconf("serial").serial_number
    serial = event.split(',')
    deviceInfo = DeviceInfo(serial[0])
    device_name = deviceInfo.getDeviceInfo(
    )  # device name 看看韦总到时候怎么处理,把这一个干掉,我这边的操作其实很多余
    device_name = re.sub('\s', '', device_name)
    return device_name
Esempio n. 4
0
def test_main(serial_num, method, params):
    deviceInfo = DeviceInfo(serial_num)
    settings._init()
    firstLaunchTimes, notFirstLaunchTimes, enterLiveTimes, apkName, package = get_start_params(
    )
    MLog.info("current Device = {}".format(serial_num))
    start_time = datetime.datetime.now()
    if params.install_method == Constants.autoInstall:  # 自动安装
        MLog.info(u"main test_main: 自动安装!")
        start_python(serial_num, params)
    else:  # 手动安装,判断有么有安装,没有安装提示,return,安装之后走
        if apkIsInstall(package):
            start_python(serial_num, params)
        else:
            print u"应用没有安装,请先安装应用"
            sys.exit()

    end_video_2_frame_time = datetime.datetime.now()
    MLog.info(u"录屏及切帧时间 time = {}".format(end_video_2_frame_time - start_time))

    path = os.path.dirname(__file__) + "\\"
    os.chdir(path)
    print path
    device_name = deviceInfo.getDeviceInfo()
    first_launch_result, normal_launch_result, enter_ent = start_calculate(
        device_name)
    MLog.debug("first_launch_result ==========")
    MLog.debug(first_launch_result)
    MLog.debug("normal_launch_result ==========")
    MLog.debug(normal_launch_result)
    MLog.debug("enter ent ==========")
    MLog.debug(enter_ent)

    first_launch_all_datas, normal_launch_all_datas, detail_data, avg_detail_data, first_lunch_splash_datas, normal_launch_splash_datas, enter_liveroom_datas = format_data(
        first_launch_result, normal_launch_result, enter_ent, apkName)
    end_calculate_time = datetime.datetime.now()
    MLog.info(u"计算时间 time ={}".format(end_calculate_time -
                                      end_video_2_frame_time))

    # ---------------------------- UI Part ------------------------------#
    # 创建表格
    create_sheet(detail_data, avg_detail_data, device_name)
    # 写入json数据到本地
    write_data_local(device_name, enter_liveroom_datas, first_launch_all_datas,
                     first_lunch_splash_datas, normal_launch_all_datas,
                     normal_launch_splash_datas)

    end_time = datetime.datetime.now()
    MLog.info(
        "all time = {}, video_frame time = {}, calculate time = {}, datacharts time = {}"
        .format(end_time - start_time, end_video_2_frame_time - start_time,
                end_calculate_time - end_video_2_frame_time,
                end_time - end_calculate_time))
Esempio n. 5
0
 def __init__(self, sernum, params):
     super(BusinessEntrance, self).__init__()
     self.param = params
     self.serNum = sernum
     self.method = params.install_method
     self.device = DeviceInfo(sernum)
     self.tempDir = self.device.getDeviceInfo()
     self.serial = []
     self.d = u2.connect(sernum)
     self.registerEvent = RegisterEvent(sernum)
     self.appOperation = AppOperation(sernum, params)
     self.fileOperation = FileOperation(sernum)
     self.videoOperation = VideoOperation(sernum)
     self.machineName = self.tempDir
     self.startApp = StartApp(sernum)
Esempio n. 6
0
class BusinessEntrance(BaseConfig):

    def __init__(self, sernum, params):
        super(BusinessEntrance, self).__init__()
        self.param = params
        self.serNum = sernum
        self.method = params.install_method
        self.device = DeviceInfo(sernum)
        self.tempDir = self.device.getDeviceInfo()
        self.serial = []
        self.d = u2.connect(sernum)
        self.registerEvent = RegisterEvent(sernum)
        self.appOperation = AppOperation(sernum, params)
        self.fileOperation = FileOperation(sernum)
        self.videoOperation = VideoOperation(sernum)
        self.machineName = self.tempDir
        self.startApp = StartApp(sernum)

    def start_python(self):
        MLog.info(u"screen_record_main start_python: serial_num = " + str(self.serNum))
        self.screenmain()

    # main函数,线程sleep时间有待商榷
    def screenmain(self):

        MLog.info(u"screen_record_main screenmain: sernum = " + str(self.serNum))
        MLog.info(u"screen_record_main screenmain: "
                  + " firstLaunchTimes = " + str(self.getFirstStartTime())
                  + " notFirstLaunchTimes = " + str(self.getNormalStartTime())
                  + " apkName = " + self.getApkName())
        settings._init()
        try:
            d = u2.connect(self.serNum)
            doInThread(self.registerEvent.runwatch, d, 0)
            time.sleep(10)
            doInThread(self.registerEvent.inputListener, d, 0, self.serNum)
            time.sleep(20)

            if self.getFirstStartTime() > 0:
                if self.method == Constants.autoInstall:  # 自动安装
                    self.firstLaunch()
                elif self.method == Constants.manuelInstall:  # 手动安装
                    self.firstLaunch2()

            self.notFirstLaunch()
            self.enterLiveRoom()
        except BaseException, e:
            MLog.error("BaseException = " + repr(e))
Esempio n. 7
0
class StartApp(BaseConfig):
    def __init__(self, sernum):
        super(StartApp, self).__init__()
        self.serNum = sernum
        self.device = DeviceInfo(sernum)
        self.machineName = self.device.getDeviceInfo()
        self.videoOperation = VideoOperation(sernum)

    # 启动应用
    def startAPP(self, d, times, name):
        try:
            MLog.debug(u"尝试启动app")
            self.startAppBySwipe(d, times, name)
        except Exception, e:
            MLog.debug(u"startAPP:" + u"启动app失败! e = " + repr(e) + "  " +
                       self.machineName)
            sysExit(u"程序退出,原因:启动app失败!")
Esempio n. 8
0
    MLog.debug(u"程序启动...")
    config = BaseConfig()
    params = configToParams(config)
    os.system("python -m uiautomator2 init")
    time.sleep(10)
    # 取序列号
    start_time = datetime.datetime.now()
    serial = getDevices()
    MLog.info(u"读取到的序列号 = " + str(serial))
    devices = []
    pool = Pool(len(serial) + 1)  # 取电脑核数
    for index in range(len(serial)):
        serial_number = serial[index]
        MLog.info(u"启动一个新进程 : index = " + str(index) + u" serial_number = " +
                  serial_number)
        deviceInfo = DeviceInfo(serial_number)
        devices.append(deviceInfo.getDeviceInfo())
        # pool.apply_async(test_main, args=(serial_number,))
        # 下面方法注释开会导致进程阻塞,debug时可以打开,运行时注释掉!!!
        result = pool.apply_async(test_main, args=(
            serial_number,
            1,
            params,
        ))
        result.get()
        # test_main(serial_number, 1)
    pool.close()
    pool.join()
    # 生成图表
    create_lines(devices, getApkName())
Esempio n. 9
0
 def __init__(self, sernum):
     super(VideoOperation, self).__init__()
     self.saveDir = '/sdcard/screenrecord/'
     self.serNum = sernum
     self.device = DeviceInfo(sernum)
     self.machineName = self.device.getDeviceInfo()
Esempio n. 10
0
class VideoOperation(BaseConfig):
    def __init__(self, sernum):
        super(VideoOperation, self).__init__()
        self.saveDir = '/sdcard/screenrecord/'
        self.serNum = sernum
        self.device = DeviceInfo(sernum)
        self.machineName = self.device.getDeviceInfo()

    # 录屏
    def screenRecord(self, d, times, name):
        if self.machineName == "PACM00":
            os.system('adb -s ' + self.serNum +
                      ' shell service call statusbar 1')
            d(text="开始录屏").click()
            print "start"
            time.sleep(5)
        else:
            print(
                name +
                "         ----------------------------------                ---------------------------"
            )
            subprocess.Popen(
                "adb -s " + self.serNum +
                " shell screenrecord --bit-rate 10000000 --time-limit " +
                str(times) + " " + self.saveDir + name)
            time.sleep(2)
        MLog.info(u"video_operation screenRecord: 录屏开始")

    # 数据上传
    def pullRecord(self, name):
        curPath = os.getcwd()
        if self.machineName == "PACM00":
            os.system("adb -s " + self.serNum + "  pull " + name)
        else:
            os.system("adb -s " + self.serNum + "  pull " + self.saveDir +
                      name)
            MLog.info(u"video_operation pullRecord: 数据上传成功")
            path = os.path.dirname(__file__) + "\\"
            srcPath = os.path.join(os.path.dirname(path), name)
            print srcPath + "pull record----"
            os.chdir(srcPath)
            for root, dirs, files in os.walk(srcPath):  # 遍历统计
                for file in files:
                    if file.__contains__('_'):
                        os.rename(file, file.split('_')[0] + ".mp4")
            os.chdir(curPath)

    # 视频转换成帧
    # ffmpeg没有视频切成帧输出到指定目录的命令,只能反复调工作目录
    def videoToPhoto(self, dirname, index):
        curPath = os.getcwd()

        if self.machineName == "PACM00":
            print str(curPath) + "-------------"

            srcPath = os.path.join(os.path.dirname(curPath), "Screenshots")
            print srcPath + "1111111111"
            count = 0
            # for filename in os.listdir(srcPath):
            os.chdir(srcPath)

            for root, dirs, files in os.walk(srcPath):  # 遍历统计
                for file in files:
                    print os.path.abspath(file)
                    shutil.copyfile(file, curPath + "/" + str(count) + ".mp4")
                    count += 1
            os.chdir(curPath)

        MLog.info(u"video_operation videoToPhoto:" + '+++++++++++++' + curPath)
        if os.path.isdir(dirname):
            shutil.rmtree(dirname)
        os.makedirs(dirname)
        chagePath = curPath + '/' + dirname
        print '+++++++++++++' + chagePath
        os.chdir(chagePath)
        strcmd = 'ffmpeg -i ' + curPath + '/' + index + '.mp4' + ' -r ' + str(
            50) + ' -f ' + 'image2 %05d.jpg'
        subprocess.call(strcmd, shell=True)
        os.chdir(curPath)
Esempio n. 11
0
 def __init__(self, sernum):
     super(StartApp, self).__init__()
     self.serNum = sernum
     self.device = DeviceInfo(sernum)
     self.machineName = self.device.getDeviceInfo()
     self.videoOperation = VideoOperation(sernum)