def get_start_params(): frame = 50 firstLaunchTimes = 0 notFirstLaunchTimes = 0 enterLiveTimes = 1 apkName = u"yy.apk" package = u"com.duowan.mobile" try: MLog.info(u"sys_config get_start_params: 读取配置文件参数...") conf = Config("default.ini") frame = conf.getconf("default").frame firstLaunchTimes = conf.getconf("default").first_start notFirstLaunchTimes = conf.getconf("default").normal_start enterLiveTimes = conf.getconf("default").enter_liveroom apkName = conf.getconf("default").apk_name package = conf.getconf("default").package except Exception: MLog.error(u"获取参数错误,使用默认值") frame = 50 firstLaunchTimes = 1 notFirstLaunchTimes = 1 enterLiveTimes = 1 apkName = u"yy.apk" package = u"com.duowan.mobile" finally: # start_python 需要运行在init_ffmpeg后面,否则拿不到帧数的值 MLog.info("apkName = " + str(apkName) + " ,first_start = " \ + str(firstLaunchTimes) + " ,normal_start = " + str(notFirstLaunchTimes) + " ,frame = " + str(frame)) return int(firstLaunchTimes), int(notFirstLaunchTimes), int( enterLiveTimes), str(apkName), str(package)
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
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))
def checkSrcVialdAndAutoCreate(file_path): try: if not os.path.exists(file_path): MLog.debug(u"fileUtil checkSrcVialdAndAutoCreate: 文件路径不存在,现在创建一个...") os.makedirs(file_path) MLog.debug(u"fileUtil checkSrcVialdAndAutoCreate: 路径为:" + file_path) except IOError, e: MLog.error(u"fileUtil checkSrcVialdAndAutoCreate: 创建文件失败!,异常如下:") MLog.error(u"fileUtil checkSrcVialdAndAutoCreate:: e = " + repr(e))
def installAPK(self, name): feature_path = self.getFeaturePath() path = os.path.dirname(__file__) + "\\" os.chdir(path) print path apk_path = feature_path + os.sep + "apk" + os.sep + name if not fileExist(apk_path): MLog.error(u"installAPK:" + u"请检查下你的apk安装包 " + name + u" 是否放置在:" + feature_path + u"中的apk分类的路径下!") sysExit(u"应用退出,原因:安装失败!") MLog.debug(u"installAPK: 执行安装操作,包路径apk_path = " + apk_path) os.system("adb -s " + self.serNum + " install " + apk_path) MLog.info(u"app_operation installAPK: 安装成功! sermun = " + self.serNum)
def json_file_to_charts(type, device, apks): MLog.info(u"json_file_to_charts: type = " + type + u", device = " + device + u", apks =" + str(apks)) # MLog.debug(u"json_file_to_charts: 开始生成折线图...") lines = [] for apk in apks: file = get_json_file(type, device, apk) try: MLog.debug(u"尝试打开文件生成折线图,file = " + file) if not fileExist(file): continue lines.append(read_json(file)) except Exception, e: MLog.error(u"打开文件失败" + file) MLog.error(u"e = " + repr(e)) print lines
def start_calculate(device_name): conf_default = Config("default.ini") app_key = conf_default.getconf("default").app first_launch_result = [] normal_launch_result = [] if app_key == "huya" or app_key == "momo": first_launch_result = multi_huya_calculate(device_name) else: first_launch_result = multi_normal_calculate(device_name, "first") # 以后想适配虎牙陌陌的话,必须uiautomator那边要手动处理下登录/跳过 normal_launch_result = multi_normal_calculate(device_name, "notfirst") # TODO 如果进直播间测试次数设置为0,会崩溃,杨帆后续改 try: enter_ent_result = enter_ent_calculate_new(device_name) except Exception, e: MLog.error(u"测试进直播间计算的时候出现崩溃了 + error = ") MLog.error(traceback.format_exc(e)) enter_ent_result = []
def json_file_to_type(types, devices, apks): MLog.info(u"data_transform :传入的参数如下:") MLog.info(u"data_transform json_file_to_type:" u"apks = " + list2str(apks) + u" devices = " + list2str(devices) + u" types = " + list2str(types)) result_name = u"chart" lines = [] for type in types: src = json_file_path + type if fileExist(src): for device in devices: new_src = src + os.sep + device if fileExist(new_src): if count_file(new_src, u".json") > 0: lines.append(json_file_to_charts(type, device, apks)) if len(lines) == 0: MLog.error(u"收集到的折线为0,直接返回!") return create_charts(result_name, lines)
def create_detail_sheet_by_json(sheet_name, file_name, title, json_data): if json_data is None or json_data is [] or len(json_data) == 0: MLog.error(u"json == None or json_data == [], return !") raise Exception(u"创建Excel时,传入的json数据是空的,所以抛出这个错误!") # 创建一个工作簿 w = Workbook() # 创建一个工作表 ws = w.add_sheet(sheet_name) style = init_normal_style() # 调整单元格宽度,先调20个够用 content_size = 6000 for i in range(0, 20): ws.col(i).width = content_size # 表格偏移量 x_offset = 0 y_offset = 0 ws.write_merge(y_offset, y_offset, x_offset, x_offset + len(json_data[0]) - 1, unicode(str(title), 'utf-8'), style) for index in range(0, len(json_data)): cur = 0 for key, value in json_data[index].items(): if index == 0: # 写标题 ws.write(y_offset + 1, x_offset + cur, key, style) # 写内容 ws.write(index + y_offset + 2, x_offset + cur, value, style) cur += 1 file_name = file_path + file_name checkSrcVialdAndAutoCreate(file_path) w.save(file_name + '.xls') MLog.debug(u"handledata create_detail_sheet_by_json: Excel文件生成路径:" + os.path.abspath(file_name) + ".xls")
def fileExist(file): if not os.path.exists(file): MLog.error(u"fileUtil fileExist: file or src not exist! file = " + file) return False return True
def sendEmail(authInfo, fromAdd, toAdd, subject, content, contentType='plain', patchFileList=None): def _format_addr(s): name, addr = parseaddr( s ) # 将email地址根据'< '符合分为两部分,如jack <[email protected],>会变成(jack,[email protected] return formataddr(( \ Header(name, 'utf-8').encode(), \ addr.encode('utf-8') if isinstance(addr, unicode) else addr)) strFrom = fromAdd strTo = toAdd # 多个邮箱地址分割成list toAddList = toAdd.split(",") server = authInfo.get('server') smtpPort = 25 sslPort = 465 user = authInfo.get('user') passwd = authInfo.get('password') if not (server and user and passwd): MLog.debug(u"sendmail sendEmail: incomplete login info, exit now!") return # 设定root信息 msgRoot = MIMEMultipart('alternative') msgRoot['Subject'] = Header(subject, 'utf-8').encode() msgRoot['From'] = _format_addr(u'%s<%s>' % (strFrom.split('@')[0], strFrom)) msgRoot['To'] = strTo # 邮件正文内容 if contentType == 'html': msgHtml = MIMEText(content, 'html', 'utf-8') msgRoot.attach(msgHtml) else: msgText = MIMEText(content, 'plain', 'utf-8') msgRoot.attach(msgText) # 设定附件信息 if not patchFileList is None: MLog.debug(u"sendmail sendEmail: 打包附件:") for patchFile in patchFileList: # print patchFile with codecs.open(patchFile, 'rb') as f: patchFileName = patchFile.split("/")[-1] # 设置附件的MIME和文件名,这里是txt类型: msgPatch = MIMEBase('text', 'txt', filename=patchFileName) # 加上必要的头信息: msgPatch.add_header('Content-Disposition', 'attachment', filename=patchFileName) msgPatch.add_header('Content-ID', '<0>') msgPatch.add_header('X-Attachment-Id', '0') # 把附件的内容读进来: msgPatch.set_payload(f.read()) # 用Base64编码: encoders.encode_base64(msgPatch) # 添加到MIMEMultipart: msgRoot.attach(msgPatch) try: # 发送邮件 smtp = smtplib.SMTP() # smtp.connect(server, smtpPort) # ssl加密方式,通信过程加密,邮件数据安全 smtp = smtplib.SMTP_SSL() smtp.connect(server, sslPort) # 设定调试级别,依情况而定 # smtp.set_debuglevel(1) smtp.login(user, passwd) smtp.sendmail(strFrom, toAddList, msgRoot.as_string()) smtp.quit() MLog.debug(u"sendmail sendEmail: 邮件发送成功!") except Exception, e: MLog.error(u"sendmail sendEmail: 邮件发送失败! e = " + repr(e))
def sysExit(reason): MLog.error(u"baseUtil exitWith: exit Application , reason is " + reason) sys.exit(reason)