Author: Alastair McKinstry <mckinstry@debian.org>
Description: Make the python code python2-3 agnostic.
Last-Updated:2015-05-02
Forwarded: no

Index: adios-1.13.1/utils/skel/bin/skel_extract.py
===================================================================
--- adios-1.13.1.orig/utils/skel/bin/skel_extract.py
+++ adios-1.13.1/utils/skel/bin/skel_extract.py
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 
+from __future__ import absolute_import, division, print_function, unicode_literals
 import argparse
 import xml.dom.minidom
 import sys
@@ -46,7 +47,7 @@ def extract (skel_output, dest, select,
     # check the selected fields
     for field in selected_fields:
         if not field in keys:
-            print 'Invalid selection, field ' + field
+            print('Invalid selection, field ' + field)
             return
 
     #Print the header
@@ -153,13 +154,13 @@ def extract_R (skel_output, select, rank
 def parse_iteration (filename):
     #assume filename ends with .xml
     if not filename.endswith (".xml"):
-        print "Warning: filename does not meet expectations, should end with .xml"
+        print("Warning: filename does not meet expectations, should end with .xml")
 
     filename = filename [:-4]
 
     iteration = filename.rsplit ("_", 1)[1]
 
-    print iteration
+    print(iteration)
 
     return iteration
 
Index: adios-1.13.1/utils/skel/lib/skelconf.py
===================================================================
--- adios-1.13.1.orig/utils/skel/lib/skelconf.py
+++ adios-1.13.1/utils/skel/lib/skelconf.py
@@ -1,5 +1,5 @@
+from __future__ import absolute_import, division, print_function, unicode_literals
 import xml.dom.minidom
-
 import skel_settings
 import skel_have_adios_timing
 
@@ -10,7 +10,7 @@ class skelConfig:
 
         nodes = doc.childNodes
         if (nodes.length != 1):
-            print 'malformed param file, should contain only a single skel-config element'
+            print('malformed param file, should contain only a single skel-config element')
             raise SystemExit
         self.config_node = nodes[0]
 
Index: adios-1.13.1/utils/gpp/ad_config.py
===================================================================
--- adios-1.13.1.orig/utils/gpp/ad_config.py
+++ adios-1.13.1/utils/gpp/ad_config.py
@@ -1,3 +1,4 @@
+from __future__ import absolute_import, division, print_function, unicode_literals
 import xml.dom.minidom
 import type_mapper
 
@@ -182,7 +183,7 @@ class var:
             return None
         else:
             # place the dimensions in a list and remove the time-index if it is there.
-            dims = filter (lambda x : x != self.time_index, self.var_node.getAttribute ('dimensions').split(',') )
+            dims = [x for x in self.var_node.getAttribute ('dimensions').split(',') if x != self.time_index]
             cleandims = []
             #print('       get_dimensions of var '+self.get_fullpath())
             for d in dims:
Index: adios-1.13.1/utils/skel/lib/adios.py
===================================================================
--- adios-1.13.1.orig/utils/skel/lib/adios.py
+++ adios-1.13.1/utils/skel/lib/adios.py
@@ -1,5 +1,5 @@
+from __future__ import print_function
 import xml.dom.minidom
-
 import typeMapper
 
 class adiosConfig:
@@ -12,7 +12,7 @@ class adiosConfig:
         doc = xml.dom.minidom.parse (config_file_name)
         nodes = doc.childNodes
         if (nodes.length != 1):
-            print 'malformed adios config file, should contain only a single adios-config element'
+            print('malformed adios config file, should contain only a single adios-config element')
             raise SystemExit
         self.config_node = nodes[0]
 
@@ -47,7 +47,7 @@ class adiosConfig:
 
     def get_buffer (self):
         #return the buffer info
-        print 'implement get_buffer'
+        print('implement get_buffer')
 
     def get_host_language (self):
         return self.host_language
@@ -157,7 +157,7 @@ class var:
             return None
         else:
             # place the dimensions in a list and remove the time-index if it is there.
-            dims = filter (lambda x : x != self.time_index, self.var_node.getAttribute ('dimensions').split(',') )
+            dims = [x for x in self.var_node.getAttribute ('dimensions').split(',') if x != self.time_index]
             cleandims = []
             for d in dims:
 
Index: adios-1.13.1/utils/skel/lib/argparse.py
===================================================================
--- adios-1.13.1.orig/utils/skel/lib/argparse.py
+++ adios-1.13.1/utils/skel/lib/argparse.py
@@ -81,7 +81,6 @@ __all__ = [
     'ZERO_OR_MORE',
 ]
 
-
 import copy as _copy
 import os as _os
 import re as _re
Index: adios-1.13.1/utils/skel/lib/skel_install.py
===================================================================
--- adios-1.13.1.orig/utils/skel/lib/skel_install.py
+++ adios-1.13.1/utils/skel/lib/skel_install.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-
+from __future__ import absolute_import, division, print_function, unicode_literals
 import skel_settings
 
 def main(argv=None):
Index: adios-1.13.1/utils/skel/lib/skel_makefile.py
===================================================================
--- adios-1.13.1.orig/utils/skel/lib/skel_makefile.py
+++ adios-1.13.1/utils/skel/lib/skel_makefile.py
@@ -1,5 +1,7 @@
 #!/usr/bin/env python
 
+# from __future__ import absolute_import, division, print_function, unicode_literals
+from __future__ import print_function, unicode_literals
 import argparse
 import os
 import sys
@@ -38,7 +40,7 @@ def generate_makefiles_with_args (parent
     try:
         config = adios.adiosConfig (args.project + '_skel.xml')
     except (IOError):
-        print "XXError reading " + args.project + "_skel.xml. Try running skel xml " + args.project + " first."
+        print ("XXError reading " + args.project + "_skel.xml. Try running skel xml " + args.project + " first.")
         return 1
 
 
@@ -49,8 +51,8 @@ def generate_makefiles_with_args (parent
         try:
             params = skelconf.skelConfig (args.project + '_params.xml')
         except (IOError):
-            print "Error reading " + args.project + "_params.xml. Try running skel params " + args.project + " first,"
-            print "then check that " + args.project + "_params.xml exists."
+            print("Error reading " + args.project + "_params.xml. Try running skel params " + args.project + " first,")
+            print("then check that " + args.project + "_params.xml exists.")
             return
 
         generate_makefiles (params, config)
@@ -201,10 +203,10 @@ def main(argv=None):
 
     lang = config.get_host_language ()
     if 'c' == lang or 'C' == lang:
-        print 'generating C flavored Makefile'
+        print('generating C flavored Makefile')
         generate_makefiles_c (params)
     else:
-        print 'generating fortran flavored Makefile'
+        print('generating fortran flavored Makefile')
         generate_makefiles_fortran (params)
 
 
Index: adios-1.13.1/utils/skel/lib/skel_params.py
===================================================================
--- adios-1.13.1.orig/utils/skel/lib/skel_params.py
+++ adios-1.13.1/utils/skel/lib/skel_params.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+from __future__ import absolute_import, division, print_function, unicode_literals
 import sys
 import os
 import argparse
@@ -31,11 +32,11 @@ def pparse_command_line (parent_parser):
 
 def generate_param_file_with_args (parent_parser):
     args = pparse_command_line (parent_parser)
-   
+
     try:
         config = adios.adiosConfig (args.project + '_skel.xml')
     except (IOError):
-        print "XXError reading " + args.project + "_skel.xml. Try running skel xml " + args.project + " first."
+        print("XXError reading " + args.project + "_skel.xml. Try running skel xml " + args.project + " first.")
         return 1
 
  
@@ -43,13 +44,13 @@ def generate_param_file_with_args (paren
 
     # Only proceed if outfilename does not already exist, or if -f was used
     if os.path.exists (outfilename) and not args.force:
-        print "%s exists, aborting. Delete the file or use -f to overwrite." % outfilename
+        print( "%s exists, aborting. Delete the file or use -f to overwrite." % outfilename)
         return 999
 
     try:
         config = adios.adiosConfig (args.project + '_skel.xml')
     except (IOError):
-        print "Error reading " + args.project + "_skel.xml. Try running skel xml " + args.project + " first."
+        print( "Error reading " + args.project + "_skel.xml. Try running skel xml " + args.project + " first.")
         return 1
 
     generate_param_file (args.project, outfilename, config, args.group, args.bpls)
@@ -60,7 +61,7 @@ def generate_param_file (app, outfile, c
     param_file = open (outfile, 'w')
 
     if bplsfile is not None:
-        print "Using bpls data in %s" % bplsfile
+        print("Using bpls data in %s" % bplsfile)
         bpdata = skel_bpls.bpls (open (bplsfile, 'r') )
 
     #Write the file header
@@ -164,7 +165,7 @@ def main(argv=None):
 
     # Only proceed if outfilename does not already exist.
     if os.path.exists (outfilename):
-        print "%s exists, aborting. Delete the file or use '-f' to overwrite."
+        print("%s exists, aborting. Delete the file or use '-f' to overwrite.")
         return 999
 
     generate_param_file (args.project, outfilename, config, args.group)
Index: adios-1.13.1/utils/skel/lib/skel_settings.py
===================================================================
--- adios-1.13.1.orig/utils/skel/lib/skel_settings.py
+++ adios-1.13.1/utils/skel/lib/skel_settings.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-
+from __future__ import absolute_import, division, print_function
 import sys
 import os.path
 import shutil
@@ -20,8 +20,8 @@ class skel_settings:
                 continue
             split_line = line.split('=')
             if not len (split_line) == 2:
-                print 'Malformed configuration line: ' + line
-                print 'Ignoring'
+                print('Malformed configuration line: ' + line)
+                print('Ignoring')
                 continue
             self.settings_dict[split_line[0]] = split_line[1]
 
Index: adios-1.13.1/utils/skel/lib/skel_source.py
===================================================================
--- adios-1.13.1.orig/utils/skel/lib/skel_source.py
+++ adios-1.13.1/utils/skel/lib/skel_source.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+from __future__ import absolute_import, division, print_function, unicode_literals
 import sys
 import os
 import argparse
@@ -84,25 +85,25 @@ def generate_c_write (outfile, config, p
         # same program var (as is done by genarray)
         c_file.write ('\n\n// Scalar declarations')
         declarations = set()
-        for v in filter (lambda x : x.is_scalar(), g.get_vars() ):
+        for v in [x for x in g.get_vars() if x.is_scalar()]:
             declarations.add (adios.cFormatter.get_declaration (v, params.get_group (g.get_name() ) ) )
 
         for d in declarations:
             c_file.write (d)
 
         # Now the initializations
-        for v in filter (lambda x : x.is_scalar(), g.get_vars() ):
+        for v in [x for x in g.get_vars() if x.is_scalar()]:
             c_file.write (adios.cFormatter.get_initialization (v, params.get_group (g.get_name() ) ) )
 
         c_file.write ('\n\n// Array declarations')
         declarations = set()
-        for v in filter (lambda x : not x.is_scalar(), g.get_vars() ):
+        for v in [x for x in g.get_vars() if not x.is_scalar()]:
             declarations.add (adios.cFormatter.get_declaration (v, params.get_group (g.get_name() ) ) )
 
         for d in declarations:
             c_file.write ('\n' + d)
 
-        for v in filter (lambda x : not x.is_scalar(), g.get_vars() ):
+        for v in [x for x in g.get_vars() if not x.is_scalar()]:
             c_file.write (adios.cFormatter.get_initialization (v, params.get_group (g.get_name() ) ) )
 
         if measure.use_sleep_before_open():
@@ -220,7 +221,7 @@ def generate_c_write (outfile, config, p
         # free the array memory
         c_file.write ('\n\n// Free the arrays')
         frees = set()
-        for v in filter (lambda x : not x.is_scalar(), g.get_vars() ):
+        for v in [x for x in g.get_vars() if not x.is_scalar()]:
             frees.add ('\nfree (' + v.get_gwrite() + ');')
 
         for f in frees:
@@ -297,7 +298,7 @@ def generate_fortran_write (outfile, con
         # same program var (as is done by genarray)
         f_file.write ('\n\n! Scalar declarations')
         declarations = set()
-        for v in filter (lambda x : x.is_scalar(), g.get_vars() ):
+        for v in [x for x in g.get_vars() if  x.is_scalar()]:
             declarations.add (adios.fortranFormatter.get_declaration (v, params.get_group (g.get_name() ) ) )
 
         for d in declarations:
@@ -305,7 +306,7 @@ def generate_fortran_write (outfile, con
 
         f_file.write ('\n\n! Array declarations')
         declarations = set()
-        for v in filter (lambda x : not x.is_scalar(), g.get_vars() ):
+        for v in [x for x in g.get_vars() if not x.is_scalar()]:
             declarations.add (adios.fortranFormatter.get_declaration (v, params.get_group (g.get_name() ) ) )
 
         for d in declarations:
@@ -335,13 +336,13 @@ def generate_fortran_write (outfile, con
         # For now, just do the numerical values first, then come back and do the more
         # complicated ones. This won't cover something like a depends on b, b depends on c,
         # but it will work for the moment
-        for v in filter (lambda x : x.is_scalar(), g.get_vars() ):
+        for v in [x for x in g.get_vars() if x.is_scalar()]:
             #split at the spaces, just print the ones where the third element is a number
             init_str = adios.fortranFormatter.get_initialization (v, params.get_group (g.get_name() ) )
             if init_str.split (None, 2)[2].isdigit():
                 f_file.write (init_str)
 
-        for v in filter (lambda x : x.is_scalar(), g.get_vars() ):
+        for v in [x for x in g.get_vars() if x.is_scalar()]:
             #split at the spaces, just print the ones where the third element is a number
             init_str = adios.fortranFormatter.get_initialization (v, params.get_group (g.get_name() ) )
             if not init_str.split (None, 2)[2].isdigit():
@@ -350,7 +351,7 @@ def generate_fortran_write (outfile, con
         f_file.write ('\n\n! Initialize the arrays')
 
 		# And the vector initializations
-        for v in filter (lambda x : not x.is_scalar(), g.get_vars() ):
+        for v in [x for x in g.get_vars() if not x.is_scalar()]:
             f_file.write (adios.fortranFormatter.get_initialization (v, params.get_group (g.get_name() ) ) )
 
 
@@ -535,7 +536,7 @@ def generate_c_read_all (outfile, config
         # same program var (as is done by genarray)
         c_file.write ('\n\n// Scalar declarations')
         declarations = set()
-        for v in filter (lambda x : x.is_scalar(), g.get_vars() ):
+        for v in [x for x in g.get_vars() if x.is_scalar()]:
             declarations.add (adios.cFormatter.get_declaration (v, params.get_group (g.get_name() ) ) )
 
         for d in declarations:
@@ -543,7 +544,7 @@ def generate_c_read_all (outfile, config
 
         c_file.write ('\n\n// Array declarations')
         declarations = set()
-        for v in filter (lambda x : not x.is_scalar(), g.get_vars() ):
+        for v in [x for x in g.get_vars() if not x.is_scalar()]:
             declarations.add (adios.cFormatter.get_declaration (v, params.get_group (g.get_name() ) ) )
 
         for d in declarations:
@@ -620,7 +621,7 @@ def generate_c_read_all (outfile, config
         # free the array memory
         c_file.write ('\n\n// Free the arrays')
         frees = set()
-        for v in filter (lambda x : not x.is_scalar(), g.get_vars() ):
+        for v in [x for x in g.get_vars() if not x.is_scalar()]:
             frees.add ('\nfree (' + v.get_gwrite() + ');')
 
         for f in frees:
@@ -683,7 +684,7 @@ def create_source_from_yaml (args, confi
 
     # Only proceed if outfilename does not already exist, or if -f was used
     if os.path.exists (outfilename) and not args.force:
-        print "%s exists, aborting. Delete the file or use -f to overwrite." % outfilename
+        print( "%s exists, aborting. Delete the file or use -f to overwrite." % outfilename)
         return 999
 
     skel_file = open (outfilename, 'w')
@@ -707,7 +708,7 @@ def create_sources_with_args (parent_par
     try:
         config = adios.adiosConfig (args.project + '_skel.xml')
     except (IOError):
-        print "XXError reading " + args.project + "_skel.xml. Try running skel xml " + args.project + " first."
+        print( "XXError reading " + args.project + "_skel.xml. Try running skel xml " + args.project + " first.")
         return 1
 
 
@@ -715,7 +716,7 @@ def create_sources_with_args (parent_par
         create_source_from_yaml(args, config)
     else:
         if args.noxml:
-            print "NOXML generation only supported with yaml input. Generating XML based code."
+            print( "NOXML generation only supported with yaml input. Generating XML based code.")
         create_source_from_xml (args, config)
 
 
@@ -724,8 +725,8 @@ def create_source_from_xml (args, config
     try:
         params = skelconf.skelConfig (args.project + '_params.xml')
     except (IOError):
-        print "Error reading " + args.project + "_params.xml. Try running skel params " + args.project + " first,"
-        print "then check that " + args.project + "_params.xml exists."
+        print( "Error reading " + args.project + "_params.xml. Try running skel params " + args.project + " first,")
+        print("then check that " + args.project + "_params.xml exists.")
         return  
 
     # Determine the target language
Index: adios-1.13.1/utils/skel/lib/skel_submit.py
===================================================================
--- adios-1.13.1.orig/utils/skel/lib/skel_submit.py
+++ adios-1.13.1/utils/skel/lib/skel_submit.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-
+from __future__ import absolute_import, division, print_function, unicode_literals
 import argparse
 import os
 
@@ -123,7 +123,7 @@ def generate_submit_scripts_from_yaml (a
 
     # Only proceed if outfilename does not already exist, or if -f was used
     if os.path.exists (outfilename) and not args.force:
-        print "%s exists, aborting. Delete the file or use -f to overwrite." % outfilename
+        print( "%s exists, aborting. Delete the file or use -f to overwrite." % outfilename)
         return 999
 
     skel_file = open (outfilename, 'w')
@@ -154,7 +154,7 @@ def generate_submit_scripts_with_args (p
     try:
         config = adios.adiosConfig (args.project + '_skel.xml')
     except (IOError):
-        print "XXError reading " + args.project + "_skel.xml. Try running skel xml " + args.project + " first."
+        print( "XXError reading " + args.project + "_skel.xml. Try running skel xml " + args.project + " first.")
         return 1
 
 
@@ -164,8 +164,8 @@ def generate_submit_scripts_with_args (p
         try:
             params = skelconf.skelConfig (args.project + '_params.xml')
         except (IOError):
-            print "Error reading " + args.project + "_params.xml. Try running skel params " + args.project + " first,"
-            print "then check that " + args.project + "_params.xml exists."
+            print("Error reading " + args.project + "_params.xml. Try running skel params " + args.project + " first,")
+            print("then check that " + args.project + "_params.xml exists.")
             return 1
 
         generate_submit_scripts_from_xml (params)
Index: adios-1.13.1/utils/skel/lib/skel_xml.py
===================================================================
--- adios-1.13.1.orig/utils/skel/lib/skel_xml.py
+++ adios-1.13.1/utils/skel/lib/skel_xml.py
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 
+from __future__ import absolute_import, division, print_function, unicode_literals
 import argparse
 import os
 import xml.dom.minidom
@@ -68,7 +69,7 @@ def create_from_yaml (project,args):
 
     # Only proceed if outfilename does not already exist, or if -f was used
     if os.path.exists (outfilename) and not args.force:
-        print "%s exists, aborting. Delete the file or use -f to overwrite." % outfilename
+        print( "%s exists, aborting. Delete the file or use -f to overwrite." % outfilename)
         return 999
 
     skel_file = open (outfilename, 'w')
@@ -91,7 +92,7 @@ def create_from_xml (project, args):
 
     # Only proceed if outfilename does not already exist, or if -f was used
     if os.path.exists (outfilename) and not args.force:
-        print "%s exists, aborting. Delete the file or use -f to overwrite." % outfilename
+        print( "%s exists, aborting. Delete the file or use -f to overwrite." % outfilename)
         return 999
 
     skel_file = open (outfilename, 'w')
Index: adios-1.13.1/wrappers/numpy/tests/test_adios_mpi.py
===================================================================
--- adios-1.13.1.orig/wrappers/numpy/tests/test_adios_mpi.py
+++ adios-1.13.1/wrappers/numpy/tests/test_adios_mpi.py
@@ -4,7 +4,7 @@ Example:
 
 $ mpiexec -n 4 python ./test_adios_mpi.py
 """
-
+from __future__ import print_function
 import adios_mpi as ad
 import numpy as np
 from mpi4py import MPI
