Salome HOME
projects
/
modules
/
kernel.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge remote branch 'origin/V7_dev'
[modules/kernel.git]
/
bin
/
PortManager.py
diff --git
a/bin/PortManager.py
b/bin/PortManager.py
index 16345298c60071e73d064ac7d0b8fd05dd8be627..d324bdebc4735bc13a51c005f599dc942b3f649f 100644
(file)
--- a/
bin/PortManager.py
+++ b/
bin/PortManager.py
@@
-1,6
+1,6
@@
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-201
5
CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-201
6
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
#
# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@
-33,6
+33,7
@@
import logging
def createLogger():
logger = logging.getLogger(__name__)
# logger.setLevel(logging.DEBUG)
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")
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(levelname)s:%(threadName)s:%(message)s")
@@
-43,7
+44,7
@@
def createLogger():
logger = createLogger()
#------------------------------------
logger = createLogger()
#------------------------------------
-# A file locker
(Linux only)
+# A file locker
def __acquire_lock(lock):
if sys.platform == "win32":
import msvcrt
def __acquire_lock(lock):
if sys.platform == "win32":
import msvcrt
@@
-61,6
+62,7
@@
def __release_lock(lock):
import fcntl
fcntl.flock(lock, fcntl.LOCK_UN)
#
import fcntl
fcntl.flock(lock, fcntl.LOCK_UN)
#
+#------------------------------------
def _getConfigurationFilename():
omniorbUserPath = os.getenv("OMNIORB_USER_PATH")
def _getConfigurationFilename():
omniorbUserPath = os.getenv("OMNIORB_USER_PATH")
@@
-88,7
+90,10
@@
def __isNetworkConnectionActiveOnPort(port):
# netstat options -l and -t are unavailable
# grep command is unavailable
from subprocess import Popen, PIPE
# 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()
import StringIO
buf = StringIO.StringIO(stdout)
ports = buf.readlines()
@@
-101,6
+106,7
@@
def __isNetworkConnectionActiveOnPort(port):
if p == port: return True
except:
pass
if p == port: return True
except:
pass
+ return False
#
def getPort(preferedPort=None):
#
def getPort(preferedPort=None):
@@
-119,7
+125,7
@@
def getPort(preferedPort=None):
with open(config_file, 'r') as f:
config = pickle.load(f)
except:
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"]))
# In this case config dictionary is reset
logger.debug("load busy_ports: %s"%str(config["busy_ports"]))
@@
-135,6
+141,9
@@
def getPort(preferedPort=None):
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
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)
port = port + 1
logger.debug("found free port: %s"%str(port))
config["busy_ports"].append(port)
@@
-161,6
+170,7
@@
def releasePort(port):
logger.debug("RELEASE PORT (%s)"%port)
config_file, lock_file = _getConfigurationFilename()
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)
with open(lock_file, 'w') as lock:
# acquire lock
__acquire_lock(lock)
@@
-195,10
+205,14
@@
def releasePort(port):
__release_lock(lock)
logger.debug("released port port: %s"%str(port))
__release_lock(lock)
logger.debug("released port port: %s"%str(port))
+
+ os.umask(oldmask)
#
def getBusyPorts():
#
def getBusyPorts():
+ busy_ports = []
config_file, lock_file = _getConfigurationFilename()
config_file, lock_file = _getConfigurationFilename()
+ oldmask = os.umask(0)
with open(lock_file, 'w') as lock:
# acquire lock
__acquire_lock(lock)
with open(lock_file, 'w') as lock:
# acquire lock
__acquire_lock(lock)
@@
-218,5
+232,6
@@
def getBusyPorts():
# release lock
__release_lock(lock)
# release lock
__release_lock(lock)
- return busy_ports
+ os.umask(oldmask)
+ return busy_ports
#
#