Ejemplo n.º 1
0
    def copy_open(self, srcfile, dstfile):
        """
        复制并打开excel,用于防止原用例文件被错误修改
        :param srcfile: 要打开的源文件名
        :param dstfile: 复制后的目标文件名
        """

        # 判断要复制的文件是否存在
        if not os.path.isfile(srcfile):
            logger.error(f'{srcfile}不存在!!')
            return

        # 判断要新建的文档是否存在,存在则提示
        if os.path.isfile(dstfile):
            logger.warn(dstfile + " 文件已存在!")

        # 记录要保存的文件
        self.df = dstfile
        # 读取excel到缓存
        # formatting_info带格式的复制
        self.workbook = openpyxl.load_workbook(filename=srcfile)
        # 拷贝,也在内存里面
        copyfile(srcfile, dstfile)
        # 打开复制后的excel文件
        self.wb = openpyxl.load_workbook(filename=dstfile)
        return
Ejemplo n.º 2
0
async def upload_group(request: web.Request):
    """
    文件上传,批量上传到所在gourd组的手机
    :param request:
    :return:
    """
    path: str = request.match_info.get("path", "")
    logger.debug(path)
    reader = await request.multipart()
    field = await reader.next()
    name = field.filename
    # 上传文件到所在group组的手机
    # group = request.headers["Access-Control-Allow-Origin"]
    # /!\ Don't forget to validate your inputs /!\
    # reader.next() will `yield` the fields of your form

    _list = await phone_service.query_device_list_by_present()
    exception_ip = []
    async with aiohttp.ClientSession() as _session:
        for device in _list:
            # 转到其他手机端
            data = aiohttp.FormData()
            data.add_field('file',
                           field,
                           filename=name,
                           content_type='application/octet-stream')
            url = f"http://{device['ip']}:{device['port']}/upload/{path.replace('_', '/')}/"
            logger.debug("upload url>>>>>> " + url)
            try:
                # proxy="http://localhost:8888"
                async with _session.post(url=url, data=data, timeout=5) as resp:
                    content = await resp.read()
                    text = content.decode(encoding="utf-8")
                    logger.debug(text)
                # apk安装
                if name.endswith(".apk"):
                    url = f"http://localhost:{conf.server['port']}/shell"
                    headers = {
                        "Access-Control-Allow-Origin": device['udid']
                    }
                    data = {
                        "command": f"pm install /{path.replace('_', '/')}/{name}"
                    }
                    async with _session.post(url=url, data=data, headers=headers) as resp:
                        logger.debug(await resp.read())
            except Exception as e:
                logger.warn("Exception:" + str(e) + "   >>>>>> ip:" + device['ip'])
                exception_ip.append("Exception:" + str(e) + "   >>>>>> ip:" + device['ip'])

    current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
    file = {"group": 0, "filename": name, "filesize": 0, "upload_time": current_time, "who": "admin"}
    await file_service.save_install_file(file)
    result = {}
    if len(exception_ip) != 0:
        result["exception"] = "true"
        result["exception_data"] = exception_ip
    return web.json_response(text=json.dumps(result))
Ejemplo n.º 3
0
 def remove_analyzer(self, a):
     """
     :type a: audio_identify.collector.Analyzer
     """
     if isinstance(a, Analyzer):
         a.remove()
         self.analyzers.remove(a)
     else:
         logger.warn('invalid analyzer..., Analyzer::{0}'.format(a))
Ejemplo n.º 4
0
 def register_collector(self, c):
     """
     :type c: audio_identify.collector.Collector
     """
     if isinstance(c, Collector):
         # c.start()  # 播放与采集同线程时,不启动
         self.collectors.append(c)
     else:
         logger.warn('invalid collector..., c:{0}'.format(c))
Ejemplo n.º 5
0
 def remove_collector(self, c):
     """
     :type c: audio_identify.collector.Collector
     """
     if isinstance(c, Collector):
         c.remove()
         observer.remove(c)
         self.collectors.remove(c)
     else:
         logger.warn('invalid collector..., c:{0}'.format(c))
Ejemplo n.º 6
0
 def filter_wav_mapping(self, wav_count_one_cmd):
     for k, v in self.wav_mapping.items():
         count = wav_count_one_cmd
         if wav_count_one_cmd > len(v):
             logger.warn(
                 'wav num is not enough, use all wavs, cmd:{0}, len:{1}'.
                 format(k, len(v)))
             count = len(v)
         index_l = random.sample(range(0, len(v)), count)
         tmp = []
         for i in index_l:
             tmp.append(v[i])
         self.wav_mapping[k] = tmp
Ejemplo n.º 7
0
 def deal_voice(self, filename):
     dst_f = os.path.join(corpus_conf.temp_path,
                          os.path.basename(filename))
     try:
         v_adjustment = float(
             self.transformer.stat(filename).get(
                 'Volume adjustment')) or 1.0
         logger.info('voice increment:{0}, wav_path:{1}'.format(
             v_adjustment, filename))
         self.transformer.vol(v_adjustment)
         self.transformer.build(filename, dst_f)
         self.transformer.clear_effects()
         return dst_f
     except Exception as e:
         logger.warn(
             'Failed to adjust volume, use origin wav. err: {0}, {1}'.
             format(e, traceback.format_exc()))
         if os.path.exists(dst_f):
             os.remove(dst_f)
         return shutil.copy(filename, corpus_conf.temp_path)
Ejemplo n.º 8
0
 def listen(self):
     ave_t = []
     while self.__start:
         try:
             start = int(round(time.time() * 1000))
             line = self.serial_com.readline().decode(
                 encoding='utf-8').strip('\r\n\t')
             if line is None or line == '':
                 continue
             ave_t.append(int(round(time.time() * 1000)) - start)
             logger.info('com:{0} receive info: {1}, cost:{2}'.format(
                 self.com_device, line, int(sum(ave_t) / len(ave_t))))
             if not corpus_conf.log_filter.need_filter(line):
                 with self.lock:
                     self.tmp_data.append(line)
         except Exception as e:
             logger.warn('com: {0} may may not read log, e:{1}'.format(
                 self.com_device, e))
         finally:
             sleep(.001)  # 取消线程占用
     else:
         logger.info('com:{0} collector thread finish....'.format(
             self.com_device))
Ejemplo n.º 9
0
def running(crt_type):
    t_start = datetime.now()  # 起x始时间
    logger.info('%s Start running for %s %s' % ('-' * 10, crt_type, '-' * 10))
    if crt_type is 'FL' or crt_type is 'TL':
        loadnames = get_asir_loadnames(crt_type)
    else:
        loadnames = get_loadnames(crt_type)

    # object = ['FLF18A_ENB_9999_180921_001290']
    for loadname in loadnames:
        if loadname is None:
            logger.warn("Invalid load name ('load_name' is None).")
            continue
        loadstatus = LoadStatus(loadname)
        logger.debug("loadname is %s" % loadname)

        load_start_time = str(loadstatus.get_load_name_time())
        logger.debug('load_start_time: %s', type(load_start_time))
        logger.debug('load_start_time: %s', load_start_time)

        passed_count = loadstatus.get_passed_count()
        logger.debug('passed_count: %s', type(passed_count))
        logger.debug('passed_count: %s', passed_count)

        passed_first_count = loadstatus.get_passed_first_count()
        logger.debug('passed_first_count: %s', type(passed_first_count))
        logger.debug('passed_first_count: %s', passed_first_count)

        failed_count = str(loadstatus.get_failed_count())
        logger.debug('failed_count: %s', type(failed_count))
        logger.debug('failed_count: %s', failed_count)

        unexecuted_count = str(loadstatus.get_unexecuted_count())
        logger.debug('unexecuted_count: %s', type(unexecuted_count))
        logger.debug('unexecuted_count: %s', unexecuted_count)

        totle_count = str(loadstatus.get_testcase_total())
        logger.debug('totle_count: %s', type(totle_count))
        logger.debug('totle_count: %s', totle_count)

        pass_rate = str(loadstatus.get_pass_rate(passed_count))
        logger.debug('pass_rate: %s', pass_rate)

        first_pass_rate = str(
            loadstatus.get_first_pass_rate(passed_first_count))
        logger.debug('first_pass_rate: %s', first_pass_rate)

        if crt_type is 'FL' or crt_type is 'TL':
            # debug = loadstatus.get_debug_asir_result()
            debug = ''
        else:
            debug = loadstatus.get_debug_result()

        logger.debug('debug status is : %s' % (debug, ))

        item = '"' + load_start_time + '","' + str(loadname) + '","' + str(passed_count) + '","' + str(
            failed_count) + '","' + unexecuted_count + '","' + totle_count + '","' + \
               first_pass_rate + '","' + pass_rate + '","' + debug + '"'
        logger.debug('item: %s', item)
        sql_str = '''
            REPLACE INTO crt_loadstatus_page(start_time,
                                             loadname,
                                             passed_num,
                                             failed_num,
                                             norun_num,
                                             total_num,
                                             first_passrate,
                                             passrate,
                                             debug) VALUES(''' + item + ''');
        '''
        logger.debug('sql_str: %s', sql_str)
        try:
            mysqldb.update_DB(sql_str)
        except Exception as e:
            logger.error('update data failed is  %s:', e)

    t_end = datetime.now()  # 关闭时间
    time = (t_end - t_start).total_seconds()
    logger.info('The script run time is: %s sec' % (time, ))