-#!/usr/bin/env python
+#!/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
p = Popen(cmd, stdout=PIPE, stderr=STDOUT)
out, err = p.communicate()
except:
- print "Error when trying to access active network connections."
- if err: print err
+ print("Error when trying to access active network connections.")
+ if err: print(err)
import traceback
traceback.print_exc()
return False
- import StringIO
- buf = StringIO.StringIO(out)
+ from io import StringIO
+ 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, 'w') as lock:
+ with open(lock_file, 'rb') as lock:
# acquire lock
__acquire_lock(lock)
config = {}
logger.debug("read configuration file")
try:
- with open(config_file, 'r') as f:
+ with open(config_file, 'rb') as f:
config = pickle.load(f)
except:
logger.info("Problem loading PortManager file: %s"%config_file)
config[appli_path] = []
# append port
- port = preferedPort
+ port = preferredPort
if not port or __isPortUsed(port, config):
port = __PORT_MIN_NUMBER
while __isPortUsed(port, config):
msg = "\n"
msg += "Can't find a free port to launch omniNames\n"
msg += "Try to kill the running servers and then launch SALOME again.\n"
- raise RuntimeError, msg
+ raise RuntimeError(msg)
logger.debug("Port %s seems to be busy"%str(port))
port = port + 1
logger.debug("found free port: %s"%str(port))
# write config
logger.debug("write config: %s"%str(config))
try:
- with open(config_file, 'w') as f:
- pickle.dump(config, f)
+ with open(config_file, 'wb') as f:
+ pickle.dump(config, f, protocol=0)
except IOError:
pass
config_file, lock_file = _getConfigurationFilename()
oldmask = os.umask(0)
- with open(lock_file, 'w') as lock:
+ with open(lock_file, 'rb') as lock:
# acquire lock
__acquire_lock(lock)
config = {}
logger.debug("read configuration file")
try:
- with open(config_file, 'r') as f:
+ with open(config_file, 'rb') as f:
config = pickle.load(f)
except IOError: # empty file
pass
# write config
logger.debug("write config: %s"%str(config))
try:
- with open(config_file, 'w') as f:
- pickle.dump(config, f)
+ with open(config_file, 'wb') as f:
+ pickle.dump(config, f, protocol=0)
except IOError:
pass
def getBusyPorts():
config_file, lock_file = _getConfigurationFilename()
oldmask = os.umask(0)
- with open(lock_file, 'w') as lock:
+ with open(lock_file, 'wb') as lock:
# acquire lock
__acquire_lock(lock)
config = {}
logger.debug("read configuration file")
try:
- with open(config_file, 'r') as f:
+ with open(config_file, 'rb') as f:
config = pickle.load(f)
except IOError: # empty file
pass