From 8c9e3e63e07e2d90821fb69fe489fc80579db6ae Mon Sep 17 00:00:00 2001 From: payno <henri.payno@esrf.fr> Date: Tue, 6 Nov 2018 15:26:37 +0100 Subject: [PATCH] [web client] small fix + move "_knows_hostname" to be a static_method --- tomwer/web/client.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tomwer/web/client.py b/tomwer/web/client.py index 04fb856b44..a9f1ec56b9 100644 --- a/tomwer/web/client.py +++ b/tomwer/web/client.py @@ -1,5 +1,5 @@ # 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 -- GitLab