Commit 8c9e3e63 authored by payno's avatar payno
Browse files

[web client] small fix + move "_knows_hostname" to be a static_method

parent cff5e43e
# coding: utf-8
#/*##########################################################################
# /*##########################################################################
# Copyright (C) 2016 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
......@@ -30,7 +30,6 @@ __authors__ = ["H.Payno"]
__license__ = "MIT"
__date__ = "28/04/2017"
import graypy
from .config import grayport_port, grayport_host
import os
......@@ -39,9 +38,11 @@ import logging
_logger = logging.getLogger(__file__)
global _INFO_UNKNOWN_HOST_NAME
_INFO_UNKNOWN_HOST_NAME = False
"""Cache variable to avoid several log about this information"""
class OWClient(object):
"""Orange widget Client can emit information about his advancement
"""
......@@ -51,19 +52,22 @@ class OWClient(object):
def __init__(self, loggers):
assert loggers is not None
if self._knows_hostname(hostname=grayport_host) is False:
if OWClient._knows_hostname(hostname=grayport_host) is False:
global _INFO_UNKNOWN_HOST_NAME
if _INFO_UNKNOWN_HOST_NAME is False:
_logger.warning('unknow host %s' % grayport_host)
_INFO_UNKNOWN_HOST_NAME = True
return
if type(loggers) not in (list, tuple):
loggers = (loggers, )
loggers = (loggers,)
for logger in loggers:
if os.environ.get('ORANGE_WEB_LOG', 'True') is 'True':
try:
self.graylogHandler = graypy.GELFHandler(grayport_host, grayport_port)
self.graylogHandler = graypy.GELFHandler(grayport_host,
grayport_port)
except:
logger.error('Fail to create GELFHandler. Won\'t report log message')
logger.error(
'Fail to create GELFHandler. Won\'t report log message')
else:
logger.addHandler(self.graylogHandler)
logger.debug('- add graypy handler')
......@@ -72,7 +76,8 @@ class OWClient(object):
info += 'ORANGE_WEB_LOG variable is setted to False'
logger.info(info)
def _knows_hostname(self, hostname):
@staticmethod
def _knows_hostname(hostname):
try:
socket.gethostbyname(hostname)
return True
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment