AC_MSG_RESULT($swig_ok)
fi
-numpydir=`$PYTHON -c "import numpy;print numpy.get_include()" 2>/dev/null`
+numpydir=`$PYTHON -c "import numpy;print(numpy.get_include())" 2>/dev/null`
if test -d "$numpydir"; then
numpy_ok=yes
PYTHON_INCLUDES="-I$numpydir $PYTHON_INCLUDES"
changequote(,)dnl
py_makefile="`$PYTHON -c '
import sys
-print \"%s/lib/python%s/config/Makefile\"%(sys.exec_prefix, sys.version[:3])'`"
+print(\"%s/lib/python%s/config/Makefile\"%(sys.exec_prefix, sys.version[:3]))'`"
changequote([,])dnl
if test ! -f "$py_makefile"; then
AC_MSG_ERROR([*** Couldn't find the python config makefile. Maybe you are
import sys
ver = sys.version[:3]
pre = sys.exec_prefix
-print \"-L%s/lib/python%s/config\" % (pre, ver),
+print(\"-L%s/lib/python%s/config\" % (pre, ver)),
if ver == \"1.4\":
- print \"-lPython -lObjects -lParser\"
+ print(\"-lPython -lObjects -lParser\")
else:
- print \"-lpython\" + ver
+ print(\"-lpython\" + ver)
changequote([,])dnl
changequote(,)dnl
py_config_in="`$PYTHON -c '
import sys
-print \"%s/lib/python%s/config/config.c.in\"%(sys.exec_prefix, sys.version[:3])'`"
+print(\"%s/lib/python%s/config/config.c.in\"%(sys.exec_prefix, sys.version[:3]))'`"
changequote([,])dnl
if test ! -f "$py_config_in"; then
AC_MSG_ERROR([*** Couldn't find the config.c.in file. Maybe you are
AC_SUBST(PYTHONHOME)
changequote(<<, >>)dnl
- PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[:3]"`
+ PYTHON_VERSION=`$PYTHON -c "import sys; print(sys.version[:3])"`
changequote([, ])dnl
AC_SUBST(PYTHON_VERSION)
dnl to know which OS Python thinks this is.
AC_SUBST(PYTHON_PLATFORM)
- PYTHON_PLATFORM=`$PYTHON -c "import sys; print sys.platform"`
+ PYTHON_PLATFORM=`$PYTHON -c "import sys; print(sys.platform)"`
AC_SUBST(PYTHON_SITE)
AC_ARG_WITH(python-site,
def debug(*args):
if verbose():
- print "[DEBUG]",
- for a in args: print a,
- print
+ print("[DEBUG]", end=' ')
+ for a in args: print(a, end=' ')
+ print()
pass
##
##
def error_exit(msg):
- print "%s: %s" % (get_tool_name(), msg)
+ print("%s: %s" % (get_tool_name(), msg))
sys.exit(1)
pass
def format_commands():
commands = get_commands()
# filter out tool itself
- commands = filter(lambda a: a != "", commands)
+ commands = sorted([a for a in commands if a != ""])
# sort commands alphabetically
- commands.sort()
# get max command's length
max_length = max([ len(i) for i in commands])
# generate formatting string
def format_list_options(cmd):
opts = get_opts(cmd)
- return "".join([" [%s]" % i for i in opts.keys()])
+ return "".join([" [%s]" % i for i in opts])
##
# function: format_options
def format_options(cmd):
opts = get_opts(cmd)
- opts_names = opts.keys()
+ opts_names = list(opts.keys())
if not opts: return ""
# get max command's length
max_length = max([ len(i) for i in opts_names])
fmt[ "opt_list" ] = format_options(cmd)
help_string = get_help(cmd)
help_string = help_string.replace("\t", " ")
- print help_string.format(**fmt)
+ print(help_string.format(**fmt))
sys.exit(0)
pass
# empty option
error_exit("empty option is not allowed")
if a.startswith("-"):
- allowed_opts = get_opts(cmd).keys()
+ allowed_opts = list(get_opts(cmd).keys())
allowed_opts = dict([(i[1], len(i)>2) for i in allowed_opts])
processed_opts = tool_opts if cmd is None else cmd_opts
cmd_descr = "" if cmd is None else " for command '%s'" % cmd
if o == "-":
# "--" format is not supported
error_exit("invalid format of option")
- elif o in allowed_opts.keys():
+ elif o in allowed_opts:
if allowed_opts[o]:
# supported option; requires parameter
if opts:
try:
# check if custom source file is specified
- src_file = opts["s"] if opts.has_key("s") else None
+ src_file = opts["s"] if "s" in opts else None
debug("source file:", src_file)
# create config tool
error_exit("%s: can't read more than one parameter at once!" % cmd)
def _toString(v):
if v is None: return ""
- elif type(v) is list: return " ".join(v)
+ elif isinstance(v, list): return " ".join(v)
else: return v
- print _toString(cfg_tool.get(tgt, params[0]))
+ print(_toString(cfg_tool.get(tgt, params[0])))
pass
elif cmd == "set":
if not tgt:
errors = []
if cfg_tool.verify(tgt, errors):
msg = " (no products found)" if not cfg_tool.get("cfg", "products") else ""
- print "Configuration is valid%s." % msg
+ print("Configuration is valid%s." % msg)
else:
raise Exception("Configuration is invalid:\n"+ "\n".join(errors))
pass
error_exit("unknown command: %s" % cmd)
pass
pass
- except Exception, e:
+ except Exception as e:
error_exit(e)
pass
return os.path.basename(sys.argv[0])
def error_exit(msg):
- print "%s: %s" % (get_tool_name(), msg)
- print "Try '%s --help' for more information." % get_tool_name()
+ print("%s: %s" % (get_tool_name(), msg))
+ print("Try '%s --help' for more information." % get_tool_name())
sys.exit(2)
pass
def usage():
- print "Command line tool to compare two SALOME configurations."
- print
- print "Usage: %s [options] CFGFILE1 [CFGFILE2]" % get_tool_name()
- print
- print " CFGFILE1 First configuration file to compare."
- print " CFGFILE2 Second configuration file to compare; if not specified,"
- print " default one is used: %s." % defaultConfFile()
- print
- print "Options:"
- print " --help (-h) Prints this help information."
- print " --force (-f) Perform full comparation, including optional parameters."
- print " --verbose (-v) Print results of comparison to the screen."
- print
+ print("Command line tool to compare two SALOME configurations.")
+ print()
+ print("Usage: %s [options] CFGFILE1 [CFGFILE2]" % get_tool_name())
+ print()
+ print(" CFGFILE1 First configuration file to compare.")
+ print(" CFGFILE2 Second configuration file to compare; if not specified,")
+ print(" default one is used: %s." % defaultConfFile())
+ print()
+ print("Options:")
+ print(" --help (-h) Prints this help information.")
+ print(" --force (-f) Perform full comparation, including optional parameters.")
+ print(" --verbose (-v) Print results of comparison to the screen.")
+ print()
def main():
# parse command line
try:
tool1 = CfgTool(cfgfile1)
tool2 = CfgTool(cfgfile2)
- except Exception, e:
+ except Exception as e:
error_exit(str(e))
pass
if errors:
if isverbose:
- print "Files %s and %s differ:" % (tool1.cfgFile, tool2.cfgFile)
- print "\n".join([" " + i for i in errors])
+ print("Files %s and %s differ:" % (tool1.cfgFile, tool2.cfgFile))
+ print("\n".join([" " + i for i in errors]))
pass
return 1
self.tree = ET.parse(self.cfgFile).getroot()
self._checkConfig()
pass
- except IOError, e:
+ except IOError as e:
self.tree = self._new()
pass
- except exceptionClass, e:
+ except exceptionClass as e:
if e.code == 3: # no element found, it's OK
self.tree = self._new()
else:
raise Exception("bad XML file %s: %s" % (self.cfgFile, str(e)))
pass
- except Exception, e:
+ except Exception as e:
raise Exception("unkwnown error: %s" % str(e))
pass
tag = path[-1][0]
params = {}
# process keyword arguments
- for param, value in kwargs.items():
+ for param, value in list(kwargs.items()):
if param not in tagAttributes(tag):
raise Exception("unsupported parameter %s for target %s" % (param, target))
params[param] = value
pass
# create / modify target
elem = self._findPath(path, True)
- for param, value in params.items():
+ for param, value in list(params.items()):
elem.set(param, value)
pass
self._write()
elem = self.tree
for tag, name in path[1:]:
if name:
- children = filter(lambda i: i.tag == tag and i.get(nameAttr()) == name, elem.getchildren())
+ children = [i for i in elem.getchildren() if i.tag == tag and i.get(nameAttr()) == name]
if len(children) > 1:
raise Exception("error parsing target path: more than one child element found")
elif len(children) == 1:
return None
pass
else:
- children = filter(lambda i: i.tag == tag, elem.getchildren())
+ children = [i for i in elem.getchildren() if i.tag == tag]
if len(children) > 1:
raise Exception("error parsing target path: more than one child element found")
elif len(children) == 1:
_name = _obj.tag
attrs = tagAttributes(_obj.tag, True)
if nameAttr() in attrs and attrs[nameAttr()]:
- if nameAttr() not in _obj.keys(): _name += " [unnamed]"
+ if nameAttr() not in list(_obj.keys()): _name += " [unnamed]"
else: _name += " [%s]" % _obj.get(nameAttr())
pass
return _name
"""
result = []
result += [i.get(nameAttr()) for i in \
- filter(lambda i: i.tag == param and i.get(nameAttr()), elem.getchildren())]
+ [i for i in elem.getchildren() if i.tag == param and i.get(nameAttr())]]
for c in elem.getchildren():
result += self._children(c, param)
pass
et.write(f, self.encoding())
pass
pass
- except IOError, e:
+ except IOError as e:
raise Exception("can't write to %s: %s" % (self.cfgFile, e.strerror))
pass
return
indent = " "
# dump element
- print "%s%s" % (indent * level, elem.tag)
+ print("%s%s" % (indent * level, elem.tag))
attrs = tagAttributes(elem.tag, True)
format = "%" + "-%ds" % max([len(i) for i in supportedAttributes()]) + " : %s"
for a in attrs:
- if a in elem.attrib.keys():
- print indent*(level+1) + format % (a, elem.get(a))
+ if a in list(elem.attrib.keys()):
+ print(indent*(level+1) + format % (a, elem.get(a)))
pass
pass
- print
+ print()
# dump all childrens recursively
for c in elem.getchildren():
self._dump(c, level+1)
errors.append("bad XML element: %s" % elem.tag)
else:
# check attributes
- attrs = elem.keys()
+ attrs = list(elem.keys())
for attr in attrs:
if attr not in tagAttributes(elem.tag, True):
errors.append("unsupported attribute '%s' for XML element '%s'" % (attr, elem.tag))
attrs = tagAttributes(elem.tag, True)
# check mandatory attributes
for attr in attrs:
- if attrs[attr] and (attr not in elem.keys() or not elem.get(attr).strip()):
+ if attrs[attr] and (attr not in list(elem.keys()) or not elem.get(attr).strip()):
errors.append("mandatory parameter '%s' of object '%s' is not set" % (attr, self._path(elem)))
pass
pass
# specific check for particular XML element
try:
self._checkObject(elem)
- except Exception, e:
+ except Exception as e:
errors.append("%s : %s" % (self._path(elem), str(e)))
# check all childrens recursively
for c in elem.getchildren():