#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2016 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
def createLogger():
logger = logging.getLogger(__name__)
# logger.setLevel(logging.DEBUG)
+ logger.setLevel(logging.INFO)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(levelname)s:%(threadName)s:%(message)s")
logger = createLogger()
#------------------------------------
-# A file locker (Linux only)
+# A file locker
def __acquire_lock(lock):
if sys.platform == "win32":
import msvcrt
import fcntl
fcntl.flock(lock, fcntl.LOCK_UN)
#
+#------------------------------------
def _getConfigurationFilename():
omniorbUserPath = os.getenv("OMNIORB_USER_PATH")
# netstat options -l and -t are unavailable
# grep command is unavailable
from subprocess import Popen, PIPE
- stdout, _ = Popen(['netstat','-an'], stdout=PIPE).communicate()
+ if sys.platform == "win32":
+ stdout, _ = Popen(['netstat','-a','-n','-p tcp'], stdout=PIPE).communicate()
+ else:
+ stdout, _ = Popen(['netstat','-ant'], stdout=PIPE).communicate()
import StringIO
buf = StringIO.StringIO(stdout)
ports = buf.readlines()
if p == port: return True
except:
pass
+ return False
#
def getPort(preferedPort=None):
with open(config_file, 'r') as f:
config = pickle.load(f)
except:
- print "Problem loading PortManager file: %s"%config_file
+ logger.info("Problem loading PortManager file: %s"%config_file)
# In this case config dictionary is reset
logger.debug("load busy_ports: %s"%str(config["busy_ports"]))
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
+ logger.debug("Port %s seems to be busy"%str(port))
+ if not port in config["busy_ports"]:
+ config["busy_ports"].append(port)
port = port + 1
logger.debug("found free port: %s"%str(port))
config["busy_ports"].append(port)
logger.debug("RELEASE PORT (%s)"%port)
config_file, lock_file = _getConfigurationFilename()
+ oldmask = os.umask(0)
with open(lock_file, 'w') as lock:
# acquire lock
__acquire_lock(lock)
__release_lock(lock)
logger.debug("released port port: %s"%str(port))
+
+ os.umask(oldmask)
#
def getBusyPorts():
+ busy_ports = []
config_file, lock_file = _getConfigurationFilename()
+ oldmask = os.umask(0)
with open(lock_file, 'w') as lock:
# acquire lock
__acquire_lock(lock)
# release lock
__release_lock(lock)
- return busy_ports
+ os.umask(oldmask)
+ return busy_ports
#