From: rnv Date: Thu, 22 Jun 2017 14:28:12 +0000 (+0300) Subject: Merge Python 3 porting. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8aabfc9256249b3d60820832ac3450978a5a0f19;p=modules%2Fyacs.git Merge Python 3 porting. --- 8aabfc9256249b3d60820832ac3450978a5a0f19 diff --cc bin/appliskel/tests/concurrentSession/TestMinimalExample.py index 4498d6934,713f3ad96..9771f9a27 --- a/bin/appliskel/tests/concurrentSession/TestMinimalExample.py +++ b/bin/appliskel/tests/concurrentSession/TestMinimalExample.py @@@ -73,8 -73,8 +73,8 @@@ class TestMinimalExample(unittest.TestC p.join() # Release port - print "release port 2899" - print("release port 2812") - p = multiprocessing.Process(target=releasePort, args=(2812,)) ++ print ("release port 2899") + p = multiprocessing.Process(target=releasePort, args=(2899,)) p.start() p.join() diff --cc bin/nameserver.py index 37061547d,37cbdbf6b..19fde8e96 --- a/bin/nameserver.py +++ b/bin/nameserver.py @@@ -46,8 -46,13 +46,8 @@@ class NamingServer(Server) except: pass - if verbose(): print "Name Service... " - if verbose(): print("Name Service... ", end=' ') - #hname=os.environ["HOST"] #commands.getoutput("hostname") - if sys.platform == "win32": - hname = getShortHostName(); - else: - hname = socket.gethostname(); - # print("hname=",hname) ++ if verbose(): print("Name Service... ", end =' ') + hname = getHostName() with open(os.environ["OMNIORB_CONFIG"]) as f: ss = re.findall("NameService=corbaname::" + hname + ":\d+", f.read()) diff --cc bin/salomeContext.py index 69116a8c8,4f31c584f..8a78e1442 --- a/bin/salomeContext.py +++ b/bin/salomeContext.py @@@ -260,19 -262,19 +262,19 @@@ class SalomeContext try: res = getattr(self, command)(options) # run appropriate method - return res or (None, None) + return res or 0 - except SystemExit, returncode: + except SystemExit as returncode: if returncode != 0: - self.getLogger().warning("SystemExit %s in method %s.", returncode, command) + self.getLogger().error("SystemExit %s in method %s.", returncode, command) return returncode - except StandardError: - except SalomeContextException as e: - self.getLogger().error(e) - return 1 + except Exception: self.getLogger().error("Unexpected error:") import traceback traceback.print_exc() return 1 - except SalomeContextException, e: ++ except SalomeContextException as e: + self.getLogger().error(e) + return 1 # def __setContextFromConfigFile(self, filename, reserved=None): @@@ -613,11 -615,10 +615,11 @@@ Available options are if __name__ == "__main__": if len(sys.argv) == 3: - context = pickle.loads(sys.argv[1]) - args = pickle.loads(sys.argv[2]) + context = pickle.loads(sys.argv[1].encode()) + args = pickle.loads(sys.argv[2].encode()) - context._startSalome(args) + status = context._startSalome(args) + sys.exit(status) else: usage() # diff --cc doc/salome/examples/example1 index 709216610,a7d937fdb..9300f476e --- a/doc/salome/examples/example1 +++ b/doc/salome/examples/example1 @@@ -19,10 -19,10 +19,10 @@@ file = str+"/test.hdf #file = "/tmp/ggg.hdf" - print " ------- We will save to", file, "-----------" + print(" ------- We will save to", file, "-----------") -batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy) -openedStudy=batchmode_geompy.myStudyManager.Open(file) +batchmode_geompy.myStudy.SaveAs(file) +openedStudy=batchmode_geompy.myStudy.Open(file) if openedStudy == None: raise RuntimeError, "Can't open saved study!" diff --cc doc/salome/examples/example16 index 724fb89fd,d05c9a83c..b5694d661 --- a/doc/salome/examples/example16 +++ b/doc/salome/examples/example16 @@@ -100,11 -100,11 +100,11 @@@ if res == 0 or A == None A = A._narrow(SALOMEDS.AttributeSequenceOfInteger) if A.Length() != 4: - print "Wrong length of SequenceOfInteger" + print("Wrong length of SequenceOfInteger") if A.Value(1) != 100 or A.Value(2) != 300 or A.Value(3) != 400 or A.Value(4) != 500: - print "Wrong value of AttributeSequenceOfInteger" + print("Wrong value of AttributeSequenceOfInteger") #---------------------------------------------------------------------- -openedStudy=batchmode_geompy.myStudyManager.Open(file2); +openedStudy=batchmode_geompy.myStudy.Open(file2); if openedStudy == None: raise RuntimeError, "Can't open saved study!" diff --cc doc/salome/examples/example19 index dbbd80e52,71efad361..1a60f7df8 --- a/doc/salome/examples/example19 +++ b/doc/salome/examples/example19 @@@ -70,53 -70,53 +70,53 @@@ batchmode_smesh.SetShape(idbox, idmesh) # ---- create Hypothesis - print "-------------------------- create Hypothesis ----------------------" - print "-------------------------- LocalLength" + print("-------------------------- create Hypothesis ----------------------") + print("-------------------------- LocalLength") -hyp1 = smesh.CreateHypothesis("LocalLength", batchmode_geompy.myStudyId ) +hyp1 = smesh.CreateHypothesis("LocalLength") hypLen1 = hyp1._narrow(SMESH.SMESH_LocalLength) hypLen1.SetLength(100) - print hypLen1.GetName() - print hypLen1.GetId() - print hypLen1.GetLength() + print(hypLen1.GetName()) + print(hypLen1.GetId()) + print(hypLen1.GetLength()) idlength = batchmode_smesh.AddNewHypothesis( orb.object_to_string(hypLen1) ); batchmode_smesh.SetName(idlength, "Local_Length_100"); - print "-------------------------- NumberOfSegments" + print("-------------------------- NumberOfSegments") -hyp2 = smesh.CreateHypothesis("NumberOfSegments", batchmode_geompy.myStudyId ) +hyp2 = smesh.CreateHypothesis("NumberOfSegments") hypNbSeg1=hyp2._narrow(SMESH.SMESH_NumberOfSegments) hypNbSeg1.SetNumberOfSegments(7) - print hypNbSeg1.GetName() - print hypNbSeg1.GetId() - print hypNbSeg1.GetNumberOfSegments() + print(hypNbSeg1.GetName()) + print(hypNbSeg1.GetId()) + print(hypNbSeg1.GetNumberOfSegments()) idseg = batchmode_smesh.AddNewHypothesis( orb.object_to_string(hypNbSeg1) ); batchmode_smesh.SetName(idseg, "NumberOfSegments_7"); - print "-------------------------- MaxElementArea" + print("-------------------------- MaxElementArea") -hyp3 = smesh.CreateHypothesis("MaxElementArea", batchmode_geompy.myStudyId) +hyp3 = smesh.CreateHypothesis("MaxElementArea") hypArea1=hyp3._narrow(SMESH.SMESH_MaxElementArea) hypArea1.SetMaxElementArea(2500) - print hypArea1.GetName() - print hypArea1.GetId() - print hypArea1.GetMaxElementArea() + print(hypArea1.GetName()) + print(hypArea1.GetId()) + print(hypArea1.GetMaxElementArea()) idarea1 = batchmode_smesh.AddNewHypothesis( orb.object_to_string(hypArea1) ); batchmode_smesh.SetName(idarea1, "MaxElementArea_2500"); - print "-------------------------- MaxElementArea" + print("-------------------------- MaxElementArea") -hyp3 = smesh.CreateHypothesis("MaxElementArea", batchmode_geompy.myStudyId) +hyp3 = smesh.CreateHypothesis("MaxElementArea") hypArea2 = hyp3._narrow(SMESH.SMESH_MaxElementArea) hypArea2.SetMaxElementArea(500) - print hypArea2.GetName() - print hypArea2.GetId() - print hypArea2.GetMaxElementArea() + print(hypArea2.GetName()) + print(hypArea2.GetId()) + print(hypArea2.GetMaxElementArea()) idarea2 = batchmode_smesh.AddNewHypothesis( orb.object_to_string(hypArea2) ); batchmode_smesh.SetName(idarea2, "MaxElementArea_500"); - print "-------------------------- Regular_1D" + print("-------------------------- Regular_1D") -alg1 = smesh.CreateHypothesis("Regular_1D", batchmode_geompy.myStudyId) +alg1 = smesh.CreateHypothesis("Regular_1D") algo1 = alg1._narrow(SMESH.SMESH_Algo) listHyp = algo1.GetCompatibleHypothesis() for hyp in listHyp: @@@ -128,8 -128,8 +128,8 @@@ print(algoReg.GetId() idreg = batchmode_smesh.AddNewAlgorithms( orb.object_to_string(algoReg) ); batchmode_smesh.SetName(idreg, "Regular_1D"); - print "-------------------------- MEFISTO_2D" + print("-------------------------- MEFISTO_2D") -alg2 = smesh.CreateHypothesis("MEFISTO_2D", batchmode_geompy.myStudyId) +alg2 = smesh.CreateHypothesis("MEFISTO_2D") algo2 = alg2._narrow(SMESH.SMESH_Algo) listHyp=algo2.GetCompatibleHypothesis() for hyp in listHyp: @@@ -326,10 -326,10 +326,10 @@@ file = str+"/test.hdf #================================================== #1. SaveAs #================================================== - print " ------- We will save to", file, "-----------" + print(" ------- We will save to", file, "-----------") -batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy) -batchmode_geompy.myStudyManager.Close(batchmode_geompy.myStudy) +batchmode_geompy.myStudy.SaveAs(file) +batchmode_geompy.myStudy.Clear() #rename the file and try to reread it again @@@ -342,10 -342,10 +342,10 @@@ os.rename(file, str+"/test_dir/test_new #================================================== #3. Open #================================================== - print " ------- We try to open " + str + "/test_dir/test_new.hdf" + print(" ------- We try to open " + str + "/test_dir/test_new.hdf") try: - openedStudy=batchmode_geompy.myStudyManager.Open(str+"/test_dir/test_new.hdf") + openedStudy=batchmode_geompy.myStudy.Open(str+"/test_dir/test_new.hdf") except Exception: raise RuntimeError, "Can't open saved study!" diff --cc doc/salome/examples/example20 index 20affe6dc,64ff48f36..6b7731d99 --- a/doc/salome/examples/example20 +++ b/doc/salome/examples/example20 @@@ -63,9 -63,9 +63,9 @@@ if str == None str = "/tmp" file = str+"/test.hdf" - print " ------- We will save to", file, "-----------" + print(" ------- We will save to", file, "-----------") -batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy) +batchmode_geompy.myStudy.SaveAs(file) #--------------------------------------------------------------------------# diff --cc doc/salome/examples/example21 index 9d456d04b,6c9dd9783..7ff5b0ec2 --- a/doc/salome/examples/example21 +++ b/doc/salome/examples/example21 @@@ -77,9 -77,9 +77,9 @@@ if str == None str = "/tmp" file = str+"/test.hdf" - print " ------- We will save to", file, "-----------" + print(" ------- We will save to", file, "-----------") -batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy) +batchmode_geompy.myStudy.SaveAs(file) #--------------------------------------------------------------------------# #---------------------------- Open file -----------------------------------# diff --cc doc/salome/examples/example22 index 6f9eee0a9,84befc2d1..157bd3631 --- a/doc/salome/examples/example22 +++ b/doc/salome/examples/example22 @@@ -78,9 -78,9 +78,9 @@@ if str == None str = "/tmp" file = str+"/test.hdf" - print " ------- We will save to", file, "-----------" + print(" ------- We will save to", file, "-----------") -batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy) +batchmode_geompy.myStudy.SaveAs(file) #--------------------------------------------------------------------------# #---------------------------- Open file -----------------------------------# diff --cc src/Container/Container_i.cxx index 05ca69454,4537accaa..49f3f67e9 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@@ -1620,57 -1673,57 +1620,57 @@@ void Engines_Container_i::copyFile(Engi //============================================================================= Engines::PyNode_ptr Engines_Container_i::createPyNode(const char* nodeName, const char* code) { - Engines::PyNode_var node= Engines::PyNode::_nil(); + Engines::PyNode_var node= Engines::PyNode::_nil(); - PyGILState_STATE gstate = PyGILState_Ensure(); - PyObject *res = PyObject_CallMethod(_pyCont, - (char*)"create_pynode", - (char*)"ss", - nodeName, - code); - if(res==NULL) - { - //internal error - PyErr_Print(); - PyGILState_Release(gstate); - SALOME::ExceptionStruct es; - es.type = SALOME::INTERNAL_ERROR; - es.text = "can not create a python node"; - throw SALOME::SALOME_Exception(es); - } - long ierr=PyLong_AsLong(PyTuple_GetItem(res,0)); - PyObject* result=PyTuple_GetItem(res,1); - std::string astr=PyUnicode_AsUTF8(result); - Py_DECREF(res); + PyGILState_STATE gstate = PyGILState_Ensure(); + PyObject *res = PyObject_CallMethod(_pyCont, + (char*)"create_pynode", + (char*)"ss", + nodeName, + code); + if(res==NULL) + { + //internal error + PyErr_Print(); PyGILState_Release(gstate); - if(ierr==0) - { - Utils_Locker lck(&_mutexForDftPy); - CORBA::Object_var obj=_orb->string_to_object(astr.c_str()); - node=Engines::PyNode::_narrow(obj); - std::map::iterator it(_dftPyNode.find(nodeName)); - if(it==_dftPyNode.end()) - { - _dftPyNode[nodeName]=node; - } - else - { - Engines::PyNode_var oldNode((*it).second); - if(!CORBA::is_nil(oldNode)) - oldNode->UnRegister(); - (*it).second=node; - } - if(!CORBA::is_nil(node)) - node->Register(); - return node._retn(); - } + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "can not create a python node"; + throw SALOME::SALOME_Exception(es); + } - long ierr=PyInt_AsLong(PyTuple_GetItem(res,0)); ++ long ierr=PyLong_AsLong(PyTuple_GetItem(res,0)); + PyObject* result=PyTuple_GetItem(res,1); - std::string astr=PyString_AsString(result); ++ std::string astr=PyUnicode_AsUTF8(result); + Py_DECREF(res); + PyGILState_Release(gstate); + if(ierr==0) + { + Utils_Locker lck(&_mutexForDftPy); + CORBA::Object_var obj=_orb->string_to_object(astr.c_str()); + node=Engines::PyNode::_narrow(obj); + std::map::iterator it(_dftPyNode.find(nodeName)); + if(it==_dftPyNode.end()) + { + _dftPyNode[nodeName]=node; + } else - { - SALOME::ExceptionStruct es; - es.type = SALOME::INTERNAL_ERROR; - es.text = astr.c_str(); - throw SALOME::SALOME_Exception(es); - } + { + Engines::PyNode_var oldNode((*it).second); + if(!CORBA::is_nil(oldNode)) + oldNode->UnRegister(); + (*it).second=node; + } + if(!CORBA::is_nil(node)) + node->Register(); + return node._retn(); + } + else + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = astr.c_str(); + throw SALOME::SALOME_Exception(es); + } } //============================================================================= @@@ -1703,58 -1756,58 +1703,58 @@@ Engines::PyNode_ptr Engines_Container_ //============================================================================= Engines::PyScriptNode_ptr Engines_Container_i::createPyScriptNode(const char* nodeName, const char* code) { - Engines::PyScriptNode_var node= Engines::PyScriptNode::_nil(); + Engines::PyScriptNode_var node= Engines::PyScriptNode::_nil(); - PyGILState_STATE gstate = PyGILState_Ensure(); - PyObject *res = PyObject_CallMethod(_pyCont, - (char*)"create_pyscriptnode", - (char*)"ss", - nodeName, - code); - if(res==NULL) - { - //internal error - PyErr_Print(); - PyGILState_Release(gstate); - SALOME::ExceptionStruct es; - es.type = SALOME::INTERNAL_ERROR; - es.text = "can not create a python node"; - throw SALOME::SALOME_Exception(es); - } - long ierr=PyLong_AsLong(PyTuple_GetItem(res,0)); - PyObject* result=PyTuple_GetItem(res,1); - std::string astr=PyUnicode_AsUTF8(result); - Py_DECREF(res); + PyGILState_STATE gstate = PyGILState_Ensure(); + PyObject *res = PyObject_CallMethod(_pyCont, + (char*)"create_pyscriptnode", + (char*)"ss", + nodeName, + code); + if(res==NULL) + { + //internal error + PyErr_Print(); PyGILState_Release(gstate); + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "can not create a python node"; + throw SALOME::SALOME_Exception(es); + } - long ierr=PyInt_AsLong(PyTuple_GetItem(res,0)); ++ long ierr=PyLong_AsLong(PyTuple_GetItem(res,0)); + PyObject* result=PyTuple_GetItem(res,1); - std::string astr=PyString_AsString(result); ++ std::string astr=PyUnicode_AsUTF8(result); + Py_DECREF(res); + PyGILState_Release(gstate); - if(ierr==0) - { - Utils_Locker lck(&_mutexForDftPy); - CORBA::Object_var obj=_orb->string_to_object(astr.c_str()); - node=Engines::PyScriptNode::_narrow(obj); - std::map::iterator it(_dftPyScriptNode.find(nodeName)); - if(it==_dftPyScriptNode.end()) - { - _dftPyScriptNode[nodeName]=node; - } - else - { - Engines::PyScriptNode_var oldNode((*it).second); - if(!CORBA::is_nil(oldNode)) - oldNode->UnRegister(); - (*it).second=node; - } - if(!CORBA::is_nil(node)) - node->Register(); - return node._retn(); - } + if(ierr==0) + { + Utils_Locker lck(&_mutexForDftPy); + CORBA::Object_var obj=_orb->string_to_object(astr.c_str()); + node=Engines::PyScriptNode::_narrow(obj); + std::map::iterator it(_dftPyScriptNode.find(nodeName)); + if(it==_dftPyScriptNode.end()) + { + _dftPyScriptNode[nodeName]=node; + } else - { - SALOME::ExceptionStruct es; - es.type = SALOME::INTERNAL_ERROR; - es.text = astr.c_str(); - throw SALOME::SALOME_Exception(es); - } + { + Engines::PyScriptNode_var oldNode((*it).second); + if(!CORBA::is_nil(oldNode)) + oldNode->UnRegister(); + (*it).second=node; + } + if(!CORBA::is_nil(node)) + node->Register(); + return node._retn(); + } + else + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = astr.c_str(); + throw SALOME::SALOME_Exception(es); + } } //============================================================================= diff --cc src/Container/SALOME_ContainerPy.py index 69316736f,a9cce39d0..1e24534dc --- a/src/Container/SALOME_ContainerPy.py +++ b/src/Container/SALOME_ContainerPy.py @@@ -199,38 -199,42 +199,38 @@@ class SALOME_ContainerPy_i (Engines__PO #------------------------------------------------------------------------- - def create_component_instance_env(self, componentName, studyId, env): - return self.create_component_instance(componentName, studyId), "" + def create_component_instance_env(self, componentName, env): + return self.create_component_instance(componentName), "" - def create_component_instance(self, componentName, studyId): - MESSAGE( "SALOME_ContainerPy_i::create_component_instance ==> " + str(componentName) + ' ' + str(studyId) ) - if studyId < 0: - MESSAGE( "Study ID is lower than 0!" ) - return None - else: - self._numInstance = self._numInstance +1 - instanceName = componentName + "_inst_" + repr(self._numInstance) - comp_iors="" - try: - component=__import__(componentName) - factory=getattr(component,componentName) - comp_i=factory(self._orb, - self._poa, - self._this(), - self._containerName, - instanceName, - componentName) - - MESSAGE( "SALOME_Container_i::create_component_instance : OK") - comp_o = comp_i._this() - self._listInstances_map[instanceName] = comp_i - except: - import traceback - traceback.print_exc() - MESSAGE( "SALOME_Container_i::create_component_instance : NOT OK") - return comp_o + def create_component_instance(self, componentName): + MESSAGE( "SALOME_ContainerPy_i::create_component_instance ==> " + str(componentName) ) + self._numInstance = self._numInstance +1 - instanceName = componentName + "_inst_" + `self._numInstance` ++ instanceName = componentName + "_inst_" + repr(self._numInstance) + comp_iors="" + try: + component=__import__(componentName) + factory=getattr(component,componentName) + comp_i=factory(self._orb, + self._poa, + self._this(), + self._containerName, + instanceName, + componentName) + + MESSAGE( "SALOME_Container_i::create_component_instance : OK") + comp_o = comp_i._this() + self._listInstances_map[instanceName] = comp_i + except: + import traceback + traceback.print_exc() + MESSAGE( "SALOME_Container_i::create_component_instance : NOT OK") + return comp_o #------------------------------------------------------------------------- - def find_component_instance(self, registeredName, studyId): + def find_component_instance(self, registeredName): anEngine = None - keysList = self._listInstances_map.keys() + keysList = list(self._listInstances_map.keys()) i = 0 while i < len(keysList): instance = keysList[i] diff --cc src/KERNEL_PY/Help.py index 4fd4a5e56,9100c5694..fc03d773f --- a/src/KERNEL_PY/Help.py +++ b/src/KERNEL_PY/Help.py @@@ -75,10 -77,10 +75,10 @@@ variables methods : defined in SALOMEDS.idl methods: - salome.DumpStudy(study) : Dump a study, given the ior + salome.DumpStudy() : Dump a study, given the ior --- ''' - print doc_salome + print(doc_salome) def geompy(self): doc_geompy = ''' diff --cc src/KERNEL_PY/PyInterp.py index c14efb152,79cec890e..e33625b6a --- a/src/KERNEL_PY/PyInterp.py +++ b/src/KERNEL_PY/PyInterp.py @@@ -60,8 -59,8 +60,8 @@@ def DumpComponent(SO, offset) while ofs <= offset: a = a + " " ofs = ofs +1 - print a + ">" + RefSO.GetID() + print(a + ">" + RefSO.GetID()) - DumpComponent(Study, CSO, offset+2) + DumpComponent(CSO, offset+2) #-------------------------------------------------------------------------- @@@ -72,8 -70,8 +72,8 @@@ def DumpStudy() SC = itcomp.Value() itcomp.Next() name = SC.ComponentDataType() - print "-> ComponentDataType is " + name + print("-> ComponentDataType is " + name) - DumpComponent(Study, SC, 1) + DumpComponent(SC, 1) #-------------------------------------------------------------------------- @@@ -90,10 -88,16 +90,10 @@@ sg = SALOMEGUI_Swig( #create an naming service instance naming_service = SALOME_NamingServicePy_i(orb) -# get active study name and id -myStudyName = sg.getActiveStudyName() +# get active study name +myStudyName = sg.getStudyName() - print myStudyName + print(myStudyName) -myStudyId = sg.getActiveStudyId() -print(myStudyId) - -# get Study Manager reference -obj = naming_service.Resolve('myStudyManager') -myStudyManager = obj._narrow(SALOMEDS.StudyManager) - -# get active study -myStudy = myStudyManager.GetStudyByName(myStudyName) +# get Study reference +obj = naming_service.Resolve('/Study') +myStudy = obj._narrow(SALOMEDS.Study) diff --cc src/KERNEL_PY/__init__.py index 514f741c1,16104045a..79fb951df --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@@ -187,10 -221,10 +187,10 @@@ def salome_init(embedded=0) salome_initial=0 sg = salome_iapp_init(embedded) orb, lcc, naming_service, cm = salome_kernel_init() - myStudyManager, myStudyId, myStudy, myStudyName = salome_study_init(theStudyId) + myStudy, myStudyName = salome_study_init() pass pass - except RuntimeError, inst: + except RuntimeError as inst: # wait a little to avoid trace mix import time time.sleep(0.2) diff --cc src/KERNEL_PY/batchmode_salome.py index 4e52b1fe4,6cf554390..59a0bfc85 --- a/src/KERNEL_PY/batchmode_salome.py +++ b/src/KERNEL_PY/batchmode_salome.py @@@ -178,28 -178,28 +178,30 @@@ def CheckCopyPaste(theSO, theInfo ,theC while aRoot.GetID() != "0:": aRoot = aRoot.GetFather() aTree = GetTree(aRoot) + aStudyPersist = PersistentPresentation(aRoot, 1) + + aStudyPersist = PersistentPresentation(myStudy, aRoot, 1) + - if not myStudyManager.CanCopy(theSO): + if not myStudy.CanCopy(theSO): - raise RuntimeError, " for "+theInfo+" returns false" + raise RuntimeError(" for "+theInfo+" returns false") - if not myStudyManager.Copy(theSO): + if not myStudy.Copy(theSO): - raise RuntimeError, " for "+theInfo+" returns false" + raise RuntimeError(" for "+theInfo+" returns false") - if not myStudyManager.CanPaste(theSO): + if not myStudy.CanPaste(theSO): - raise RuntimeError, " for "+theInfo+" returns false" + raise RuntimeError(" for "+theInfo+" returns false") # check: before paste study is not changed check - if aStudyPersist != PersistentPresentation(myStudy, aRoot, 1): + if aStudyPersist != PersistentPresentation(aRoot, 1): - raise RuntimeError, "Study is changed before Paste calling for "+theInfo + raise RuntimeError("Study is changed before Paste calling for "+theInfo) aSObj = theSO if theComponentPaste: aSObj = theSO.GetFatherComponent() theInfo = theInfo + "(paste for component)" - if myStudyManager.Paste(aSObj) == None: + if myStudy.Paste(aSObj) == None: - raise RuntimeError, " for "+theInfo+" returns None object" + raise RuntimeError(" for "+theInfo+" returns None object") aNewTree = GetTree(aRoot) aLen = len(aTree) for a in range(0,aLen): @@@ -283,10 -283,23 +285,11 @@@ while 1 time.sleep(sleeping_time) sleeping_time = max(sleeping_time_max, 2*sleeping_time) pass -- -myStudyManager = obj._narrow(SALOMEDS.StudyManager) - -if myStudyManager is None: - print("Warning: SALOMEDS.StudyManager has not been created !!!") - -# create new study -aListOfOpenStudies = myStudyManager.GetOpenStudies(); -myStudy = None; -if len(aListOfOpenStudies) == 0 : - myStudy = myStudyManager.NewStudy("Study1") -else: - myStudyName = aListOfOpenStudies[0] - myStudy = myStudyManager.GetStudyByName(myStudyName) + -myStudyName = myStudy._get_Name() +myStudy = obj._narrow(SALOMEDS.Study) -myStudyId = myStudy._get_StudyId() -# print(myStudyId) + +if myStudy is None: - print "Warning: SALOMEDS.Study has not been created !!!" ++ print("Warning: SALOMEDS.Study has not been created !!!") + +myStudyName = myStudy._get_Name() diff --cc src/KERNEL_PY/kernel/services.py index c8ab30236,5e6c8db0f..e14023b7e --- a/src/KERNEL_PY/kernel/services.py +++ b/src/KERNEL_PY/kernel/services.py @@@ -120,18 -120,24 +120,18 @@@ def getComponentList() obj = salome.naming_service.Resolve('Kernel/ModulCatalog') catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog) if not catalog: - raise RuntimeError, "Can't accesss module catalog" + raise RuntimeError("Can't accesss module catalog") return catalog.GetComponentList() -## Get a study manager to create and manage %SALOME studies -# \ingroup service -def getStudyManager(): - """Get a study manager to create and manage SALOME studies""" - return salome.myStudyManager - import SALOMEDS -## Get a study manager to create and manage SALOME studies. -# \warning you should use instead the variable salome.myStudyManager. +## Get a study to create SALOME study. +# \warning you should use instead the variable salome.myStudy. # This function is given for illustration of usage of the naming service # \ingroup service -def __getStudyManager_demo(): +def __getStudy_demo(): """ - Get a study manager to create and manage SALOME studies. WARN: you - should use instead the variable salome.myStudyManager. This + Get a study to create SALOME study. WARN: you + should use instead the variable salome.myStudy. This function is given for illustration of usage of the naming service """ naming_service = SALOME_NamingServicePy_i( orb ) diff --cc src/KERNEL_PY/kernel/studyedit.py index 98aad6282,ccc2e0680..c047b046f --- a/src/KERNEL_PY/kernel/studyedit.py +++ b/src/KERNEL_PY/kernel/studyedit.py @@@ -31,27 -31,61 +31,27 @@@ This module provides a new class :class import re - import salome - from salome.kernel.logger import Logger from salome.kernel import termcolor - logger = Logger("salome.kernel.studyedit", color = termcolor.PURPLE) + from salome.kernel.logger import Logger + import salome + + + logger = Logger("salome.kernel.studyedit", color=termcolor.PURPLE) -_editors = {} +_editor = None _DEFAULT_CONTAINER = "FactoryServer" - # The codec to use for strings that are displayed in Salome study tree is Latin-1 - ENCODING_FOR_SALOME_STUDY = "iso-8859-1" -## Return the ID of the active study. In GUI mode, this function is equivalent -# to salome.sg.getActiveStudyId(). Outside GUI, it returns salome.myStudyId -# variable. -# \ingroup studyedit -def getActiveStudyId(): - """ - Return the ID of the active study. In GUI mode, this function is equivalent - to ``salome.sg.getActiveStudyId()``. Outside GUI, it returns - ``salome.myStudyId`` variable. - """ - salome.salome_init() - # Warning: we don't use salome.getActiveStudy() here because it doesn't - # work properly when called from Salome modules (multi-study interpreter - # issue) - if salome.hasDesktop(): - return salome.sg.getActiveStudyId() - else: - return salome.myStudyId - -def getActiveStudy(): - return getStudyFromStudyId(getActiveStudyId()) - -def getStudyFromStudyId(studyId): - salome.salome_init() - study = salome.myStudyManager.GetStudyByID(studyId) - return study -def getStudyIdFromStudy(study): - studyId = study._get_StudyId() - return studyId - -## Return a \b StudyEditor instance to edit the study with ID studyId. -# If \b studyId is \b None, return an editor for the current study. +## Return a \b StudyEditor instance to edit the study. # \ingroup studyedit -def getStudyEditor(studyId = None): +def getStudyEditor(): """ - Return a :class:`StudyEditor` instance to edit the study with ID - `studyId`. If `studyId` is :const:`None`, return an editor for the current - study. + Return a :class:`StudyEditor` instance to edit the study. """ - if studyId is None: - studyId = getActiveStudyId() - if studyId not in _editors: - _editors[studyId] = StudyEditor(studyId) - return _editors[studyId] + global _editor + if _editor is None: + _editor = StudyEditor() + return _editor ## This class provides utility methods to complement \b Study and # \b StudyBuilder classes. Those methods may be moved in those classes diff --cc src/KERNEL_PY/salome_iapp.py index cdd942bd1,b7aa1557d..c3aa0cbf8 --- a/src/KERNEL_PY/salome_iapp.py +++ b/src/KERNEL_PY/salome_iapp.py @@@ -77,14 -77,19 +77,14 @@@ class SalomeOutsideGUI(object) """Indicate if GUI is running""" return False - def updateObjBrowser(self, bid): + def updateObjBrowser(self): """update the GUI object browser""" - print "SalomeOutsideGUI: no objectBrowser update outside GUI" + print("SalomeOutsideGUI: no objectBrowser update outside GUI") pass - def getActiveStudyId(self): - """Get the active study id""" - print("SalomeOutsideGUI.getActiveStudyId: avoid use outside GUI") - return myStudyId - - def getActiveStudyName(self): - """Get the active study name""" - print("SalomeOutsideGUI.getActiveStudyName: avoid use outside GUI") + def getStudyName(self): + """Get the study name""" - print "SalomeOutsideGUI.getStudyName: avoid use outside GUI" ++ print("SalomeOutsideGUI.getStudyName: avoid use outside GUI") return myStudyName def SelectedCount(self): diff --cc src/KERNEL_PY/salome_study.py index efd41940b,b31fad899..be6d72f29 --- a/src/KERNEL_PY/salome_study.py +++ b/src/KERNEL_PY/salome_study.py @@@ -51,8 -52,8 +51,8 @@@ def DumpComponent(SO, Builder,offset) find,RefSO = CSO.ReferencedObject() if find: a=a+":"+RefSO.GetID() - print a + print(a) - DumpComponent(Study, CSO, Builder,offset+2) + DumpComponent(CSO, Builder,offset+2) it.Next() #-------------------------------------------------------------------------- @@@ -67,10 -67,21 +67,10 @@@ def DumpStudy() while itcomp.More(): SC = itcomp.Value() name = SC.ComponentDataType() - print "-> ComponentDataType is " + name + print("-> ComponentDataType is " + name) - DumpComponent(Study, SC,Builder, 1) + DumpComponent(SC,Builder, 1) itcomp.Next() -def DumpStudies(): - """ - Dump all studies in a StudyManager - """ - global myStudyManager - for name in myStudyManager.GetOpenStudies(): - s = myStudyManager.GetStudyByName(name) - print("study:",name, s._get_StudyId()) - DumpStudy(s) - - #-------------------------------------------------------------------------- def IDToObject(id): @@@ -194,28 -203,28 +194,28 @@@ def CheckCopyPaste(theSO, theInfo ,theC while aRoot.GetID() != "0:": aRoot = aRoot.GetFather() aTree = GetTree(aRoot) - aStudyPersist = PersistentPresentation(myStudy, aRoot, 1) + aStudyPersist = PersistentPresentation(aRoot, 1) - if not myStudyManager.CanCopy(theSO): + if not myStudy.CanCopy(theSO): - raise RuntimeError, " for "+theInfo+" returns false" + raise RuntimeError(" for "+theInfo+" returns false") - if not myStudyManager.Copy(theSO): + if not myStudy.Copy(theSO): - raise RuntimeError, " for "+theInfo+" returns false" + raise RuntimeError(" for "+theInfo+" returns false") - if not myStudyManager.CanPaste(theSO): + if not myStudy.CanPaste(theSO): - raise RuntimeError, " for "+theInfo+" returns false" + raise RuntimeError(" for "+theInfo+" returns false") # check: before paste study is not changed check - if aStudyPersist != PersistentPresentation(myStudy, aRoot, 1): + if aStudyPersist != PersistentPresentation(aRoot, 1): - raise RuntimeError, "Study is changed before Paste calling for "+theInfo + raise RuntimeError("Study is changed before Paste calling for "+theInfo) aSObj = theSO if theComponentPaste: aSObj = theSO.GetFatherComponent() theInfo = theInfo + "(paste for component)" - if myStudyManager.Paste(aSObj) == None: + if myStudy.Paste(aSObj) == None: - raise RuntimeError, " for "+theInfo+" returns None object" + raise RuntimeError(" for "+theInfo+" returns None object") aNewTree = GetTree(aRoot) aLen = len(aTree) for a in range(0,aLen): @@@ -270,12 -279,97 +270,12 @@@ def FindFileInDataDir(filename) #-------------------------------------------------------------------------- -salome_study_ID = -1 - -# *args are used here to support backward compatibility -# previously it was possible to pass theStudyId parameter to this function -# which is no more supported. -def getActiveStudy(*args): - global myStudyManager - global salome_study_ID - - if not myStudyManager: - print("No active study") - return None - pass - - if verbose(): print("getActiveStudy") - if salome_study_ID == -1: - listOpenStudies = myStudyManager.GetOpenStudies() - if len(listOpenStudies) == 0: - return None - else: - s = myStudyManager.GetStudyByName(listOpenStudies[0]) - salome_study_ID = s._get_StudyId() - if verbose(): print("--- Study Id ", salome_study_ID) - return salome_study_ID - - #-------------------------------------------------------------------------- - -def setCurrentStudy(theStudy): - """ - Change current study : an existing one given by a study object. - - :param theStudy: the study CORBA object to set as current study - - Obsolete: only one study can be opened at the moment. - This function works properly if specified theStudy parameter - corresponds to the currently opened study. - Kept for backward compatibility only. - """ - global myStudyId, myStudy, myStudyName - global salome_study_ID - myStudy = theStudy - myStudyId = theStudy._get_StudyId() - myStudyName = theStudy._get_Name() - return myStudyId, myStudy, myStudyName - - #-------------------------------------------------------------------------- - -# *args are used here to support backward compatibility -# previously it was possible to pass theStudyId parameter to this function -# which is no more supported. -def setCurrentStudyId(*args): - """ - Change current study : an existing or new one. - - This function connects to the single opened study if there is any; otherwise - new empty study is created. - - Obsolete: only one study can be opened at the moment. - Kept for backward compatibility only. - """ - global myStudyManager, myStudyId, myStudy, myStudyName - global salome_study_ID - salome_study_ID = -1 - myStudyId = getActiveStudy() - if not myStudyId: - myStudyId = createNewStudy() - if verbose(): print("myStudyId",myStudyId) - myStudy = myStudyManager.GetStudyByID(myStudyId) - myStudyName = myStudy._get_Name() - return myStudyId, myStudy, myStudyName - - #-------------------------------------------------------------------------- - -def createNewStudy(): - global myStudyManager - print("createNewStudy") - aStudyName = "extStudy" - theStudy = myStudyManager.NewStudy(aStudyName) - theStudyId = theStudy._get_StudyId() - print(aStudyName, theStudyId) - return theStudyId - - #-------------------------------------------------------------------------- - def openStudy(theStudyPath): - print "openStudy" - global myStudyManager + print("openStudy") - theStudy = myStudyManager.Open(theStudyPath) - theStudyId = theStudy._get_StudyId() - print(theStudyPath, theStudyId) - return theStudyId + global myStudy, myStudyName + myStudy.Open(theStudyPath) + myStudyName = myStudy._get_Name() - print theStudyPath, myStudy._get_Name() ++ print(theStudyPath, myStudy._get_Name()) #-------------------------------------------------------------------------- @@@ -287,24 -381,40 +287,24 @@@ def salome_study_init(theStudyPath=None create new empty study if there is active study (str) : open study with the given file name """ - global myStudyManager, myStudyId, myStudy, myStudyName + global myStudy, myStudyName global orb, lcc, naming_service, cm - if verbose(): print "theStudyPath:", theStudyPath + if verbose(): print("theStudyPath:", theStudyPath) - if not myStudyManager: + if not myStudy: orb, lcc, naming_service, cm = salome_kernel.salome_kernel_init() - # get Study Manager reference - if verbose(): print("looking for studyManager ...") - obj = naming_service.Resolve('myStudyManager') - myStudyManager = obj._narrow(SALOMEDS.StudyManager) - if verbose(): print("studyManager found") + # get Study reference - if verbose(): print "looking for study..." ++ if verbose(): print("looking for study...") + obj = naming_service.Resolve('/Study') + myStudy = obj._narrow(SALOMEDS.Study) - if verbose(): print "Study found" ++ if verbose(): print("Study found") pass - # get active study Id, ref and name - myStudy = None - myStudyId = getActiveStudy() - if myStudyId == None : - import types - if theStudyPath and (type(theStudyPath) == bytes or type(theStudyPath) == str): - myStudyId = openStudy(theStudyPath) - else: - myStudyId = createNewStudy() - if verbose(): print("myStudyId", myStudyId) - - if myStudy == None: - myStudy = myStudyManager.GetStudyByID(myStudyId) - myStudyName = myStudy._get_Name() + import types + if theStudyPath and type(theStudyPath) == types.StringType: + openStudy(theStudyPath) - return myStudyManager, myStudyId, myStudy, myStudyName + myStudyName = myStudy._get_Name() -def salome_study_close(): - global salome_study_ID - global myStudyId, myStudy, myStudyName - salome_study_ID = -1 - myStudyId, myStudy, myStudyName = None, None, None - pass + return myStudy, myStudyName diff --cc src/KERNEL_PY/salome_test.py index 4713d3626,08070cb21..60efd54fc --- a/src/KERNEL_PY/salome_test.py +++ b/src/KERNEL_PY/salome_test.py @@@ -54,65 -54,65 +54,65 @@@ print("================================ obj = salome.naming_service.Resolve('Kernel/ModulCatalog') catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog) if not catalog: - raise RuntimeError, "Can't accesss module catalog" - print "OK" + raise RuntimeError("Can't accesss module catalog") + print("OK") - print + print() - print "======================================================================" - print " %d. Check modules availability in the module catalog " % step; step+=1 - print "======================================================================" + print("======================================================================") + print(" %d. Check modules availability in the module catalog " % step); step+=1 + print("======================================================================") for module in [ "GEOM", "SMESH", "MEDFactory", "PVSERVER"]: - print - print "--- Check %s ..." % module + print() + print("--- Check %s ..." % module) comp = catalog.GetComponent(module) if not comp: - raise RuntimeError, "Component %s is not found in Module Catalog." % module - print "OK" + raise RuntimeError("Component %s is not found in Module Catalog." % module) + print("OK") pass - print + print() - print "======================================================================" - print " %d. Test Data Server " % step; step+=1 - print "======================================================================" + print("======================================================================") + print(" %d. Test Data Server " % step); step+=1 + print("======================================================================") - print - print "--- Create new component ..." + print() + print("--- Create new component ...") comp = builder.NewComponent("TEST") if not comp: - raise RuntimeError, "Can't create new component" - print "OK" + raise RuntimeError("Can't create new component") + print("OK") - print - print "--- Create AttributeName ..." + print() + print("--- Create AttributeName ...") A = builder.FindOrCreateAttribute(comp, "AttributeName") if not A: - raise RuntimeError, "Can't create AttributeName attribute" + raise RuntimeError("Can't create AttributeName attribute") A.SetValue("TEST") if A.Value() != "TEST": - raise RuntimeError, "Error : wrong value of AttributeName" - print "OK" + raise RuntimeError("Error : wrong value of AttributeName") + print("OK") - print - print "--- Create AttributeReal ..." + print() + print("--- Create AttributeReal ...") A = builder.FindOrCreateAttribute(comp, "AttributeReal") if not A: - raise RuntimeError, "Can't create AttributeReal attribute" + raise RuntimeError("Can't create AttributeReal attribute") A.SetValue(0.0001) if A.Value() != 0.0001: - raise RuntimeError, "Error : wrong value of AttributeReal" - print "OK" + raise RuntimeError("Error : wrong value of AttributeReal") + print("OK") - print + print() - print "======================================================================" - print " %d. Test Geometry " % step; step+=1 - print "======================================================================" + print("======================================================================") + print(" %d. Test Geometry " % step); step+=1 + print("======================================================================") from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) +geompy = geomBuilder.New() ShapeTypeCompSolid = 1 ShapeTypeSolid = 2 @@@ -163,13 -163,13 +163,13 @@@ print("OK" # ---- update object browser if salome.hasDesktop(): - salome.sg.updateObjBrowser(True); + salome.sg.updateObjBrowser(); - print + print() - print "======================================================================" - print " %d. Test Mesh " % step; step+=1 - print "======================================================================" + print("======================================================================") + print(" %d. Test Mesh " % step); step+=1 + print("======================================================================") from salome.StdMeshers import StdMeshersBuilder import SMESH @@@ -300,13 -300,13 +300,13 @@@ print("OK" # ---- update object browser if salome.hasDesktop(): - salome.sg.updateObjBrowser(True); + salome.sg.updateObjBrowser(); - print + print() - print "======================================================================" - print " %d. Test Med " % step; step+=1 - print "======================================================================" + print("======================================================================") + print(" %d. Test Med " % step); step+=1 + print("======================================================================") import medcalc #from medcalc import properties diff --cc src/Launcher/Test/test_launcher.py index c9f02549f,2b9ee1583..920c9034b --- a/src/Launcher/Test/test_launcher.py +++ b/src/Launcher/Test/test_launcher.py @@@ -103,11 -91,11 +103,11 @@@ f.close( job_params.out_files = ["result.txt", "subdir"] job_params.resource_required = salome.ResourceParameters() job_params.resource_required.nb_proc = 1 - + launcher = salome.naming_service.Resolve('/SalomeLauncher') - + for resource in self.ressources: - print "Testing python_salome job on ", resource + print("Testing python_salome job on ", resource) job_params.result_directory = local_result_dir + resource job_params.job_name = "PyJob" + resource job_params.resource_required.name = resource @@@ -312,9 -301,9 +312,9 @@@ f.close( launcher = salome.naming_service.Resolve('/SalomeLauncher') resManager= salome.lcc.getResourcesManager() - + for resource in self.ressources: - print "Testing yacs job on ", resource + print("Testing yacs job on ", resource) job_params.result_directory = local_result_dir + resource job_params.job_name = "YacsJob_" + resource job_params.resource_required.name = resource @@@ -426,9 -416,9 +426,9 @@@ f.close( launcher = salome.naming_service.Resolve('/SalomeLauncher') resManager= salome.lcc.getResourcesManager() - + for resource in self.ressources: - print "Testing yacs job with options on ", resource + print("Testing yacs job with options on ", resource) job_params.result_directory = local_result_dir + resource job_params.job_name = "YacsJobOpt_" + resource job_params.resource_required.name = resource diff --cc src/ModuleGenerator/IDLparser.py index 0d6d9a060,bc10283c5..b2107353a --- a/src/ModuleGenerator/IDLparser.py +++ b/src/ModuleGenerator/IDLparser.py @@@ -831,9 -831,10 +829,9 @@@ def run(tree, args) common_data["COMP_NAME"] = getParamValue("name", "", args) common_data["COMP_UNAME"] = getParamValue("username", "", args) common_data["COMP_TYPE"] = getParamValue("type", "OTHER", args) - common_data["COMP_MULT"] = getParamValue("multistudy", "1", args) common_data["COMP_IMPL"] = getParamValue("impltype", "1", args) - print common_data + print(common_data) remove_comp = getParamValue("remove", "", args) @@@ -878,6 -879,6 +876,6 @@@ if __name__ == "__main__": - print - print "Usage : omniidl -bIDLparser [-I]* -Wbcatalog=[,icon=][,version=][,author=][,name=][,username=][,impltype=] " - print + print() - print("Usage : omniidl -bIDLparser [-I]* -Wbcatalog=[,icon=][,version=][,author=][,name=][,username=][,multistudy=][,impltype=] ") ++ print("Usage : omniidl -bIDLparser [-I]* -Wbcatalog=[,icon=][,version=][,author=][,name=][,username=][,impltype=] ") + print() diff --cc src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index 25b63dc5a,c04961aa2..c76daf908 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@@ -2097,14 -1290,18 +2097,14 @@@ bool SALOMEDSImpl_Study::DumpStudy(cons sfp << "import sys" << std::endl; sfp << "import " << aBatchModeScript << std::endl << std::endl; - std::string aStudyVar = "salome.myStudy"; // initialization function sfp << aBatchModeScript << ".salome_init()" << std::endl; - if ( !isMultiFile ) { - sfp << "theStudy = " << aStudyVar << std::endl << std::endl; - aStudyVar = "theStudy"; - } + // notebook initialization - sfp << _GetNoteBookAccess(aStudyVar) << std::endl; + sfp << _GetNoteBookAccess() << std::endl; // extend sys.path with the directory where the script is being dumped to - sfp << "sys.path.insert( 0, r\'" << thePath << "\')" << std::endl << std::endl; + sfp << "sys.path.insert(0, r\'" << thePath << "\')" << std::endl << std::endl; // dump NoteBook variables sfp << _GetStudyVariablesScript();