Beispiel #1
0
 def move_screenshot(cls, tarpath="Fail||Pass"):
     """
     移动截图到指定dirname目录中
     :return:tarpath = Fail||Pass
     """
     try:
         dirname = datetime.datetime.now().strftime("%Y%m%d.%H%M%S.%f")[:-3]
         old_path = Misc.ABSpath() + "/Output/Screenshot/" + tarpath + "/"
         path = Misc.ABSpath() + "/Output/Screenshot/"
         new_path_screen = path + dirname
         for root, dirs, files in os.walk(old_path):
             if len(files) != 0:
                 Misc.mkdir(old_path, new_path_screen)
                 log.debug(u'创建新路径')
             else:
                 log.debug(u'当前目录无文件,不创建新目录')
             if len(dirs) == 0:
                 for i in range(len(files)):
                     log.debug(u'查找file')
                     if files[i][-3:] == 'png':
                         log.debug(u'查找.png图片')
                         old_path_file = old_path + "/" + files[i]
                         new_path_screen_file = new_path_screen + "/" + files[
                             i]
                         shutil.move(old_path_file, new_path_screen_file)
                         log.debug(u'执行移动')
                     else:
                         log.debug(u'当前路径无.png图片')
         log.debug(u'移动截图成功')
     except Exception as msg:
         log.error(u'移动截图失败')
         print msg
         raise
Beispiel #2
0
    def del_file_the_earliest(cls, dir, maxFileNum):
        """
        当删除指定目录dir中文件总数>500,删除最早的一个文件
        :param dir:
        :param filename:
        :return:
        """
        log.debug(dir)

        cls.dir = str(dir)
        if not os.listdir(dir):
            log.debug(u'目录中没有文件')

        while len(os.listdir(dir)) > int(maxFileNum):
            try:
                lists = os.listdir(dir)
                lists.sort(key=lambda fn: os.path.getmtime(dir + '/' + fn))
                file_old0 = os.path.join(lists[0])
                file_old1 = os.path.join(lists[1])
                # 返回最早生成的文件名称
                log.debug('remove report file:%s' % file_old0)
                log.debug('remove report file:%s' % file_old1)
                os.remove(cls.dir + file_old0)
                os.remove(cls.dir + file_old1)
            except Exception as msg:
                log.error(msg)
                raise msg
Beispiel #3
0
 def _conn(self):
     try:
         self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
         self.address = (self.addr, self.port)
         self.client_socket.settimeout(30)
         log.debug('_conn succ:{}'.format(self.address))
     except:
         log.error('_conn fail')
Beispiel #4
0
 def send(self,send_data):
     send_data = Misc.jsonToStr(send_data)
     try:
         log.debug("send data:{}".format(send_data))
         # 发送成功响应值是发送数据的长度
         send_len = self.client_socket.sendto(send_data, self.address)
         # res = self.client_socket.sendto('sdfasfd', ('172.16.16.1',2048))
         log.debug('send succ [len:{}]'.format(send_len))
         return send_len
     except:
         log.error('send error')
         return 0
Beispiel #5
0
 def del_file(cls, dir, filename):
     """
     删除指定目录dir中与filename不同的文件
     :param dir:
     :param filename:
     :return:
     """
     cls.dir = str(dir)
     try:
         if os.listdir(dir):
             for file in os.listdir(cls.dir):
                 if file != filename:
                     os.remove(cls.dir + file)
             log.debug('del_file => ok')
     except Exception as msg:
         log.error('del_file => error')
         raise msg
Beispiel #6
0
    def compareTime(cls, first, second):
        """
        比较时间大小,
        :param second:入参格式为:'2017-08-22 20:30:23'
        :return:
        """

        try:
            result = time.mktime(time.strptime(
                first, '%Y-%m-%d %H:%M:%S')) - time.mktime(
                    time.strptime(second, '%Y-%m-%d %H:%M:%S'))
            if float(result) > 0:
                result = True
            else:
                result = False
            return result
        except BaseException:
            msg = '入参错误'
            log.error(msg)
Beispiel #7
0
 def replace_value(self, dict, objkey, value):
     self.path = []
     try:
         self.dict_get(dict, objkey)
         num = len(self.path)
         if num == 0:
             dict[objkey] = value
         elif num == 1:
             dict[self.path[0]][objkey] = value
         elif num == 2:
             dict[self.path[0]][self.path[1]][objkey] = value
         elif num == 3:
             dict[self.path[0]][self.path[1]][self.path[2]][objkey] = value
         elif num == 4:
             dict[self.path[0]][self.path[1]][self.path[2]][
                 self.path[3]][objkey] = value
         else:
             msg = '{}>4'.format(num)
             log.error('{},{}'.format(msg, self.path))
             raise msg
         return dict
     except:
         log.error(msg)
         raise msg
Beispiel #8
0
 def recv(self):
     self.receive_data, self.sender_address = self.client_socket.recvfrom(2048)
     try:
         res = Misc.strtojson(self.receive_data)
         log.debug("recv data: {}".format(res))
         if not isinstance(res,dict):
             log.error('res is not dict:500')
         return res
     except BaseException as msg:
         log.error('recv data:{}'.format(self.receive_data))
         raise msg
     except:
         msg = 'recv timeout'
         log.error(msg)