Salome HOME
Updated copyright comment
[modules/kernel.git] / src / ModuleGenerator / IDLparser.py
index d27e083d6f7bef35b8529e68be9f51513f8ae2de..d0ed9d72d721293fdf664762976bbaddfee9d780 100644 (file)
@@ -1,5 +1,5 @@
 #  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-#  File   : IDLparser.py
-#  Module : SALOME
-
-import string, sys, fpformat, re, os
+import os
+import os.path as osp
+import re
 import xml.sax
-import pdb
 
 from xml.sax.handler import *
 from omniidl import idlast, idltype, idlvisitor, idlutil, output
+from salome_utils import getUserName
 
 # parameters not found in IDL file, user's specified in optional parameters
 common_data={"AUTHOR"     : "",
@@ -38,7 +37,6 @@ common_data={"AUTHOR"     : "",
              "COMP_TYPE"  : "",
              "COMP_NAME"  : "",
              "COMP_UNAME" : "",
-             "COMP_MULT"  : "",
              "COMP_IMPL"  : ""
              }
 
@@ -67,7 +65,7 @@ def getParamValue( param_name, default_value, args ):
 # print error message
 #--------------------------------------------------
 def error (message):
-    print "ERROR : ", message
+    print("ERROR : ", message)
 
 
 #--------------------------------------------------
@@ -116,9 +114,9 @@ class Tree:
     def output_xml(self, f, depth=0):
         d = depth
         if self.name != '':
-            s = string.ljust('', 4*depth)
+            s = ''.ljust(4*depth)
             s += '<' + self.name
-            for k,v in self.attrs.items():
+            for k,v in list(self.attrs.items()):
               s += ' ' + k + '="' + v + '"'
             s += '>'
             if self.content != '':
@@ -135,7 +133,7 @@ class Tree:
         if self.name != '':
             s = '</' + self.name + '>\n'
             if len(self.childs) > 0 :
-                s = string.ljust('', 4*depth) + s
+                s = ''.ljust(4*depth) + s
             f.write(s)
 
     def Dump(self, levels=-1, depth=0):
@@ -143,8 +141,8 @@ class Tree:
 
         if levels == 0: return
 
-        s = string.ljust('', 4*depth)
-        print s, self, self.content
+        s = ''.ljust(4*depth)
+        print(s, self, self.content)
         for i in self.childs:
             i.Dump(levels-1, depth+1)
 
@@ -295,8 +293,7 @@ def parseComment(comment):
             ## the remaining part of input string
             m = re.match(pattern, sPorts)
             if m is None:
-                raise LookupError, \
-                      'format error in DataStreamPort definition : '+sPorts
+                raise LookupError('format error in DataStreamPort definition : '+sPorts)
             sPorts = sPorts[m.end():]
             result.append(m.groups())
 
@@ -401,9 +398,8 @@ class Interface(Tree):
             if type == 'DataStreamPorts':
                 Service = self.findService(key)
                 if Service is None:
-                    raise LookupError, \
-                          'service ' + key + \
-                          ' not found in interface : ' + self.key
+                    raise LookupError('service ' + key + \
+                          ' not found in interface : ' + self.key)
                 for p in result:
                 ## process next DataStreamPort
                     Service.createDataStreamParameter(p)
@@ -436,7 +432,6 @@ class Component(Tree):
         self.addNamedChild('component-author',     common_data["AUTHOR"])
         self.addNamedChild('component-version',    common_data["VERSION"])
         self.addNamedChild('component-comment',    'unknown')
-        self.addNamedChild('component-multistudy', common_data["COMP_MULT"])
         self.addNamedChild('component-impltype',   common_data["COMP_IMPL"])
         self.addNamedChild('component-icone',      common_data["ICON"])
         self.addNamedChild('constraint')
@@ -455,7 +450,7 @@ class Component(Tree):
 
         for i in ['component-username', 'component-author',
                   'component-type', 'component-icone', 'component-version',
-                  'component-multistudy', 'component-impltype', 'constraint']:
+                  'component-impltype', 'constraint']:
             ext = C.getChild(i)
             int = self.getChild(i)
             if int is None:
@@ -502,14 +497,14 @@ class Catalog(ContentHandler, Tree):
         complist = self.getNode('component-list')
         idx = 0
         if complist is None:
-            print "Catalog.removeComponent() : 'component-list' is not found"
+            print("Catalog.removeComponent() : 'component-list' is not found")
             return
         for comp in complist.childs:
             cname = comp.getChild('component-name')
             if cname is not None:
                 if cname.content == name:
                     complist.childs.pop(idx)
-                    print "Component " + name + " is removed"
+                    print("Component " + name + " is removed")
             idx += 1
 
     def startDocument(self):
@@ -543,7 +538,7 @@ class Catalog(ContentHandler, Tree):
         self.buffer = ''
 
     def endElement(self, name):
-        self.buffer = string.join(string.split(self.buffer), ' ')
+        self.buffer = ' '.join(self.buffer.split())
         p = self.list[len(self.list)-1]
         p.content = self.buffer
         if name == 'component':
@@ -570,10 +565,10 @@ class Catalog(ContentHandler, Tree):
                 break;
 
         if present == 0:
-            print '   add component', i_ext.getChild('component-name').content
+            print('   add component', i_ext.getChild('component-name').content)
             L_int.addChild(i_ext)
         else:
-            print '   replace component', i_ext.getChild('component-name').content
+            print('   replace component', i_ext.getChild('component-name').content)
             i_int.merge(i_ext)
 
     def mergeType(self, type):
@@ -755,6 +750,9 @@ class ModuleCatalogVisitor (idlvisitor.AstVisitor):
     def visitStringType(self, type):
         self.currentType = "string"
 
+    def visitWStringType(self, type):
+        self.currentType = "wstring"
+
     def visitParameter(self, node):
         node.paramType().accept(self)
         if node.is_in():
@@ -827,28 +825,27 @@ def run(tree, args):
 
     #=========  Read parameters  ======================
     common_data["ICON"]       = getParamValue("icon",       "",                args)
-    common_data["AUTHOR"]     = getParamValue("author",     os.getenv("USER"), args)
+    common_data["AUTHOR"]     = getParamValue("author",     getUserName(),     args)
     common_data["VERSION"]    = getParamValue("version",    "1",               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)
 
     #==================================================
 
-    if (os.path.exists(CatalogFileName)):
-        print "Importing", CatalogFileName
+    if (osp.exists(CatalogFileName)):
+        print("Importing", CatalogFileName)
         C = Catalog(CatalogFileName)
     else:
-        print "Creating ",CatalogFileName
+        print("Creating ",CatalogFileName)
         C = Catalog()
 
-    print "Reading idl file"
+    print("Reading idl file")
 
     visitor = ModuleCatalogVisitor(C)
     tree.accept(visitor)
@@ -858,13 +855,13 @@ def run(tree, args):
     if remove_comp :
         C.removeComponent(remove_comp)
 
-    if (os.path.exists(CatalogFileName)):
-        print "Updating", CatalogFileName
+    if (osp.exists(CatalogFileName)):
+        print("Updating", CatalogFileName)
         CatalogFileName_old = CatalogFileName + '_old'
         os.rename(CatalogFileName, CatalogFileName_old)
     else:
         CatalogFileName_old = ""
-        print "Writing", CatalogFileName
+        print("Writing", CatalogFileName)
 
     CatalogFileName_new = CatalogFileName + '_new'
     f=open(CatalogFileName_new, 'w')
@@ -873,13 +870,13 @@ def run(tree, args):
     f.close()
 
     os.rename(CatalogFileName_new, CatalogFileName)
-    if ((CatalogFileName_old != "") & os.path.exists(CatalogFileName_old)):
+    if ((CatalogFileName_old != "") & osp.exists(CatalogFileName_old)):
         os.unlink(CatalogFileName_old)
 
-    print
+    print()
 
 
 if __name__ == "__main__":
-    print
-    print "Usage : omniidl -bIDLparser [-I<catalog files directory>]* -Wbcatalog=<my_catalog.xml>[,icon=<pngfile>][,version=<num>][,author=<name>][,name=<component_name>][,username=<component_username>][,multistudy=<component_multistudy>][,impltype=<implementation type : 0 (python), 1 (C++)>] <file.idl>"
-    print
+    print()
+    print("Usage : omniidl -bIDLparser [-I<catalog files directory>]* -Wbcatalog=<my_catalog.xml>[,icon=<pngfile>][,version=<num>][,author=<name>][,name=<component_name>][,username=<component_username>][,impltype=<implementation type : 0 (python), 1 (C++)>] <file.idl>")
+    print()