コード例 #1
0
ファイル: pp_udpworker.py プロジェクト: riverzhou/hp_pp
    def update_status(self):
        global global_info
        udp_recv = self.recv_udp()
        if udp_recv == None:
            return

        udp_recv = self.proto.parse_decode(udp_recv)
        info_val = self.proto.parse_ack(udp_recv)
        if info_val == None:
            return

        code = info_val['code']

        if code == 'F':
            printer.debug(udp_recv)
            return

        if code == 'C':
            printer.info(udp_recv)
            return

        if code == 'A' or code == 'B':
            printer.warning(udp_recv)
            printer.error(udp_recv)
            return

        printer.error(udp_recv)
        return
コード例 #2
0
ファイル: fd_channel.py プロジェクト: riverzhou/hp_pp
        def pyget(self, handle, req, headers = {}):
                time_req = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S.%f')

                printer.info(time_req + ' :: ' + str(headers) + ' :: ' + req)

                ack = None

                try:
                        handle.request('GET', req, headers = headers)
                except  KeyboardInterrupt:
                        self.close_handle(handle)
                        return False
                except:
                        printer.critical(format_exc())
                        self.close_handle(handle)
                        return False
                try:
                        ack  = handle.getresponse()
                except  KeyboardInterrupt:
                        self.close_handle(handle)
                        return False
                except:
                        printer.critical(format_exc())
                        self.close_handle(handle)
                        return False

                self.close_handle(handle)

                try:
                        body = ack.read()
                except  KeyboardInterrupt:
                        del(ack)
                        return None
                except:
                        printer.critical(format_exc())
                        del(ack)
                        return None

                key_val = {}
                key_val['head']    = str(ack.msg)
                key_val['status']  = ack.status
                try:
                        key_val['body'] = body.decode('gb18030')
                except:
                        printer.error(body)
                        key_val['body'] = ''

                time_ack = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S.%f')

                printer.info(time_ack + ' :: ' + str(key_val['head']) + ' :: ' + str(key_val['body']))

                printer.time(time_req + ' --- ' + time_ack + ' :: ' + str(headers) + ' :: ' + req + ' :: ' + str(key_val['head']) + ' :: ' + str(key_val['body']))

                del(ack)
                return key_val
コード例 #3
0
def get_channel_init():
    global get_channel

    get_channel[0].start()
    get_channel[1].start()

    printer.info(str(pp_server_dict))
    printer.info(str(pp_server_dict_2))

    get_channel[0].wait_for_start()
    get_channel[1].wait_for_start()
コード例 #4
0
    def do_image(self):
        global channel_center
        channel = 'tb0'

        while True:
            group, handle = channel_center.get_channel(
                channel, self.timeout_find_channel, self.group)
            if handle == None:
                return
            channel_center.close_handle(handle)
            printer.info(str(self.group) + ' : ' + str(handle) + ' closed')
コード例 #5
0
    def do_proc(self, arg):
        key_val, callback = arg

        price = key_val['image_price']

        proto = proto_ssl_image(key_val)
        req = proto.make_image_req(price)
        head = proto.make_ssl_head(self.host_name)
        info_val = self.pyget(req, head)
        #logger.debug(sorted(info_val.items()))

        if info_val == None:
            return

        printer.info(sorted(info_val.items()))

        if info_val['status'] != 200:
            logger.error('ack status error : %s' % info_val['status'])
            printer.error('ack status error : %s' % info_val['status'])
            try:
                logger.error(info_val['body'].decode('gb18030'))
                printer.error(info_val['body'].decode('gb18030'))
            except:
                pass
            else:
                return
            try:
                logger.error(info_val['body'].decode())
                printer.error(info_val['body'].decode())
            except:
                pass
            else:
                return
            logger.error('unknow body coding')
            printer.error(info_val['body'])
            return

        ack_sid = proto.get_sid_from_head(info_val['head'])
        ack_val = proto.parse_image_ack(info_val['body'])
        ack_val['sid'] = ack_sid
        ack_val['price'] = price
        #printer.debug(sorted(ack_val.items()))
        #logger.debug(sorted(ack_val.items()))
        logger.debug(ack_sid)

        if self.flag_stop == True:
            logger.error(
                'image ack recived but thread be stoped. Do not proc callback.'
            )
            return

        if callback != None: callback(ack_val)
コード例 #6
0
        def pyget(self, handler, req, headers = {}):
                printer.info(str(headers))
                printer.info(req)

                try:
                        handler.request('GET', req, headers = headers)
                except  KeyboardInterrupt:
                        return None
                except:
                        printer.critical(format_exc())
                        return None
                try:
                        ack  = handler.getresponse()
                        body = ack.read()
                except  KeyboardInterrupt:
                        return None
                except:
                        printer.critical(format_exc())
                        return None

                key_val = {}
                key_val['body']    = body
                key_val['head']    = str(ack.msg)
                key_val['status']  = ack.status

                printer.info(key_val['head'])
                printer.info(key_val['body'])
                return key_val
コード例 #7
0
 def do_decode(self):
     global decode_worker
     decode_worker.put_request(self.sid, self.type_decode,
                               self.timeout_decode, self.picture)
     printer.info(
         '%s,%s,%s,%s' %
         (self.sid, self.type_decode, self.timeout_decode, self.picture))
     number = decode_worker.get_result(self.sid)
     printer.info('%s,%s' % (self.sid, number))
     #self.lock_timeout.acquire()
     #if self.flag_timeout == False:
     #        self.client.number_bid[self.count] = number
     #self.lock_timeout.release()
     self.event_finish.set()
     return
コード例 #8
0
    def do_proc(self, arg):
        key_val, callback = arg

        proto = proto_ssl_login(key_val)
        req = proto.make_login_req()
        head = proto.make_ssl_head(self.host_name)
        info_val = self.pyget(req, head)
        logger.debug(sorted(info_val.items()))

        if info_val == None:
            return

        printer.info(sorted(info_val.items()))

        if info_val['status'] != 200:
            logger.error('ack status error : %s' % info_val['status'])
            printer.error('ack status error : %s' % info_val['status'])
            try:
                logger.error(info_val['body'].decode('gb18030'))
                printer.error(info_val['body'].decode('gb18030'))
            except:
                pass
            else:
                return
            try:
                logger.error(info_val['body'].decode())
                printer.error(info_val['body'].decode())
            except:
                pass
            else:
                return
            logger.error('unknow body coding')
            printer.error(info_val['body'])
            return

        ack_sid = proto.get_sid_from_head(info_val['head'])
        ack_val = proto.parse_login_ack(info_val['body'])
        #ack_val['sid'] = ack_sid
        #printer.debug(sorted(ack_val.items()))
        #logger.debug(sorted(ack_val.items()))

        if callback != None: callback(ack_val)
コード例 #9
0
        def do_proc(self, arg):
                key_val, callback = arg

                price     = key_val['shot_price']
                image     = key_val['image_decode']
                sid       = key_val['sid']
                event     = key_val['event']
                delay     = key_val['delay']
                worker_in = key_val['worker_in']
                worker_out= key_val['worker_out']
                group     = self.group

                worker_in(group)

                proto     = proto_ssl_price(key_val)
                req       = proto.make_price_req(price, image)
                head      = proto.make_ssl_head(self.host_name, sid)

                int_price = int(price)
                event.wait()
                if delay != 0 : sleep(delay)
                global current_price
                cur_price = current_price.get()
                logger.debug('shot_price %d , cur_price %d ' % (int_price, cur_price))
                if int_price > cur_price + 300 or int_price < cur_price - 300:
                        worker_out(group)
                        return

                info_val  = self.pyget(req, head)
                #logger.debug(sorted(info_val.items()))

                if info_val == None:
                        worker_out(group)
                        return

                printer.info(sorted(info_val.items()))

                if info_val['status'] != 200 :
                        logger.error('ack status error : %s' % info_val['status'])
                        printer.error('ack status error : %s' % info_val['status'])
                        try:
                                logger.error(info_val['body'].decode('gb18030'))
                                printer.error(info_val['body'].decode('gb18030'))
                        except: pass
                        else:
                                worker_out(group)
                                return
                        try:
                                logger.error(info_val['body'].decode())
                                printer.error(info_val['body'].decode())
                        except: pass
                        else:
                                worker_out(group)
                                return
                        logger.error('unknow body coding')
                        printer.error(info_val['body'])
                        worker_out(group)
                        return

                ack_sid   = proto.get_sid_from_head(info_val['head'])
                ack_val   = proto.parse_price_ack(info_val['body'])
                #ack_val['sid'] = ack_sid
                #printer.debug(sorted(ack_val.items()))
                #logger.debug(sorted(ack_val.items()))

                worker_out(group)
                if callback != None : callback(ack_val)