#!/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
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
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)
# 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
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
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)
config[appli_path] = []
# append port
- port = preferedPort
+ port = preferredPort
if not port or __isPortUsed(port, config):
port = __PORT_MIN_NUMBER
while __isPortUsed(port, config):
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
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)
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