X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=bin%2FPortManager.py;h=e0584ac81529000f029ad5267f0b1b6a66dbd8b9;hb=8e13e88d05d970cc47659054136f16aa0361b2fc;hp=b135ab3b4a44e3faf03750513997e3bad8973c1f;hpb=3f048e2513c4a1053a84a98ebd708921c831fa23;p=modules%2Fkernel.git diff --git a/bin/PortManager.py b/bin/PortManager.py index b135ab3b4..e0584ac81 100644 --- a/bin/PortManager.py +++ b/bin/PortManager.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: iso-8859-1 -*- -# Copyright (C) 2007-2017 CEA/DEN, EDF R&D, OPEN CASCADE +# Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE # # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -35,11 +35,11 @@ __PORT_MAX_NUMBER = 2910 import logging def createLogger(): logger = logging.getLogger(__name__) -# logger.setLevel(logging.DEBUG) + #logger.setLevel(logging.DEBUG) logger.setLevel(logging.INFO) ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) - formatter = logging.Formatter("%(levelname)s:%(threadName)s:%(message)s") + formatter = logging.Formatter("%(levelname)s:%(threadName)s:%(pathname)s[%(lineno)s]%(message)s") ch.setFormatter(formatter) logger.addHandler(ch) return logger @@ -83,6 +83,11 @@ def _getConfigurationFilename(): import tempfile temp = tempfile.NamedTemporaryFile() lock_file = os.path.join(os.path.dirname(temp.name), ".salome_PortManager.lock") + try: + with open(lock_file, 'wb'): + pass + except IOError: + pass temp.close() return (portmanager_config, lock_file) @@ -100,7 +105,7 @@ def __isNetworkConnectionActiveOnPort(port): # netstat options -l and -t are unavailable # grep command is unavailable if sys.platform == "win32": - cmd = ['netstat','-a','-n','-p tcp'] + cmd = ['netstat','-a','-n','-p','tcp'] else: cmd = ['netstat','-ant'] pass @@ -118,7 +123,7 @@ def __isNetworkConnectionActiveOnPort(port): return False from io import StringIO - buf = StringIO(out.decode()) + buf = StringIO(out.decode('utf-8', 'ignore')) ports = buf.readlines() # search for TCP - LISTEN connections import re @@ -132,12 +137,12 @@ def __isNetworkConnectionActiveOnPort(port): return False # -def getPort(preferedPort=None): +def getPort(preferredPort=None): logger.debug("GET PORT") config_file, lock_file = _getConfigurationFilename() oldmask = os.umask(0) - with open(lock_file, 'wb') as lock: + with open(lock_file, 'rb') as lock: # acquire lock __acquire_lock(lock) @@ -159,7 +164,7 @@ def getPort(preferedPort=None): config[appli_path] = [] # append port - port = preferedPort + port = preferredPort if not port or __isPortUsed(port, config): port = __PORT_MIN_NUMBER while __isPortUsed(port, config): @@ -177,7 +182,7 @@ def getPort(preferedPort=None): logger.debug("write config: %s"%str(config)) try: with open(config_file, 'wb') as f: - pickle.dump(config, f) + pickle.dump(config, f, protocol=0) except IOError: pass @@ -196,7 +201,7 @@ def releasePort(port): config_file, lock_file = _getConfigurationFilename() oldmask = os.umask(0) - with open(lock_file, 'wb') as lock: + with open(lock_file, 'rb') as lock: # acquire lock __acquire_lock(lock) @@ -224,7 +229,7 @@ def releasePort(port): logger.debug("write config: %s"%str(config)) try: with open(config_file, 'wb') as f: - pickle.dump(config, f) + pickle.dump(config, f, protocol=0) except IOError: pass