def updateUI(self, data):
size = len(data) / 3
if size != self._count:
log.warning("Bytecount mismatch")
return
for i in range(size):
r = data[i * 3 + 0]
g = data[i * 3 + 1]
b = data[i * 3 + 2]
self._values[i] = self.toHexColor(r, g, b)
try:
for i in range(self._count):
self._canvas.itemconfig(self._leds[i], fill=self._values[i])
except TclError:
# Looks like the UI closed!
pass
python类warning()的实例源码
def update(self, data):
try:
s = self._connect()
count = self.bufByteCount
packet = self._generateHeader(CMDTYPE.PIXEL_DATA, count)
packet.extend(data)
s.sendall(packet)
resp = ord(s.recv(1))
if not self.persist:
s.close()
if resp != RETURN_CODES.SUCCESS:
log.warning("Bytecount mismatch! %s", resp)
except Exception as e:
log.exception(e)
error = "Problem communicating with network receiver!"
log.error(error)
raise IOError(error)
def sch_text(self, data):
if(not self.__flag):
return None
__msp_search = self.__libmsc.MSPSearch
__msp_search.restype = c_char_p
_data = create_string_buffer(data)
_data_len = sizeof(_data)
_len_point = pointer(c_uint(_data_len))
_ret_p = pointer(c_int(0))
rec_txt = __msp_search("nlp_version=2.0", _data, _len_point, _ret_p)
if _ret_p.contents:
#print ("MSPLogin failed , Error code %s"%(_ret_p.contents))
log.warning("MSPLogin failed , Error code %s"%(_ret_p.contents))
return None
#print ("iflytek search api result: %s"%(rec_txt))
log.debug("iflytek search api result: %s"%(rec_txt))
return self.__deal_data(rec_txt)
def click_handler(channel, click_type, was_queued, time_diff):
log.info(channel.bd_addr + " " + str(click_type))
if str(click_type) == 'ClickType.ButtonSingleClick':
try:
log.info("Switching on lights associated with button " + channel.bd_addr)
for light in groups[channel.bd_addr]['group']:
bridge.get(light).on()
except KeyError:
log.warning("Light not found for button " + str(channel.bd_addr))
elif str(click_type) == 'ClickType.ButtonHold':
# turn off all lights
log.info("Turning off all lights...")
for light in bridge:
light.off()
return
def jsonify_(data):
keycase = settings.JSON_KEYCASE
if keycase:
try:
casefunc = getattr(stringcase, keycase)
data = keycase_convert(data, casefunc)
except AttributeError:
log.warning(u'%s keycase is not supported, response default json. '
u'Supported keycase: %s'
% (keycase, get_support_keycase()))
if settings.DEBUG:
js = json.dumps(data, ensure_ascii=False, indent=4)
else:
js = json.dumps(data, ensure_ascii=False, separators=[',', ':'])
return Response(js, mimetype='application/json')
def keyerror_response(func):
@wraps(func)
def wrap(*args, **kwargs):
try:
return func(*args, **kwargs)
except KeyError as e:
data = u'Need params:{0}'.format(e)
log.warning(data)
return response(code=ResponseCode.BAD_REQUEST, data=data)
return wrap
def on_kick(self, event, irc):
nick = event.raw.split(" ")[3]
if nick == self.config['nickname']:
log.warning("Kicked from %s, trying to re-join", event.target)
irc.join(event.target)
else:
self.userdb.remove_entry(event, nick)
def on_part(self, event, irc):
requested = "".join(event.arguments).startswith("requested")
nick = event.source.nick
if nick == self.config['nickname']:
if requested:
log.warning(
"Removed from %s, trying to re-join", event.target)
irc.join(event.target)
else:
del self.userdb[event.target]
else:
self.userdb.remove_entry(event, nick)
def on_bannedfromchan(event, irc):
s = event.raw.split(" ")
channel = s[3]
irc.notice("wolfy1339", "Banned from {0}".format(channel))
log.warning("Banned from %s", channel)
def update_product(fournisseur_product_infos, incwo_product_infos):
update_infos = {}
try:
PRODUCT_ID = incwo_product_infos["id"]
PRODUCT_REF = fournisseur_product_infos["reference"]
except KeyError:
log.error("Incwo product with no ID or ref associated")
raise ValueError()
try:
# Si produit considere comme vitrine : on annule la comparaison prix et category en mettant les champs aux memes valeurs
if not compareValues(incwo_product_infos["product_category_id"],VITRINE_CATEGORY_ID):
log.warning("Pas de mise a jour du prix du produit {} (Produit categorisé comme en vitrine)".format(PRODUCT_REF))
incwo_product_infos["product_category_id"] = fournisseur_product_infos["product_category_id"]
fournisseur_product_infos["price"] = incwo_product_infos["price"]
except KeyError:
log.error("Incwo product with no category_ID associated")
raise ValueError()
for key in INCWO_PARAMS:
if not key in fournisseur_product_infos:
log.error("Product "+fournisseur_product_infos["name"]+" : fournisseur info incomplete! Missing "+key)
raise ValueError()
elif not key in incwo_product_infos:
if key != 'barcode':
log.debug("incwo info incomplete, updating "+key)
update_infos[key]=fournisseur_product_infos[key]
elif (compareValues(fournisseur_product_infos[key],incwo_product_infos[key])):
log.debug("incwo info outdated, updating {}".format(key))
log.debug("Picata {} ; incwo_product_infos {}".format(fournisseur_product_infos[key], incwo_product_infos[key]))
update_infos[key]=fournisseur_product_infos[key]
if len(update_infos) > 0 :
log.debug("Update needed for product "+str(PRODUCT_ID))
xml = prepare_xml_product(update_infos)
url = "https://www.incwo.com/"+str(ID_USER)+"/customer_products/"+str(PRODUCT_ID)+".xml";
send_request('put', url, xml)
# else :
# log.debug("Product {} (id {}) infos up to date".format(fournisseur_product_infos["name"],PRODUCT_ID))
manage_stock_movement(fournisseur_product_infos, PRODUCT_ID, incwo_product_infos["product_category_id"])