# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2016 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
# print error message
#--------------------------------------------------
def error (message):
- print "ERROR : ", message
+ print("ERROR : ", message)
#--------------------------------------------------
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 != '':
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):
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)
## 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())
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)
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):
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':
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):
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():
common_data["COMP_TYPE"] = getParamValue("type", "OTHER", 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)
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')
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>][,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()