# HG changeset patch
# User John Donoghue <john.donoghue@ieee.org>
# Date 1593879269 14400
#      Sat Jul 04 12:14:29 2020 -0400
# Node ID 55959fb9f6d8914b7d24c44707b3fa1bb627c396
# Parent  52bed5bd9bbfbe138ad56b64a61bbb8ab24c730f
Use python3 ins scripts

* Makefile.in: native mingw, depend on python3, set PYTHON3 var

* tools/msys2-install.py: update for python3 syntax

* tools/pkg-install.py: update for python3 syntax

diff -r 52bed5bd9bbf -r 55959fb9f6d8 Makefile.in
--- a/Makefile.in	Fri Jul 03 11:22:44 2020 -0400
+++ b/Makefile.in	Sat Jul 04 12:14:29 2020 -0400
@@ -280,9 +280,10 @@
 endif
 # use the a native python in native mingw
 ifeq ($(MXE_NATIVE_MINGW_BUILD),yes)
-  REQUIREMENTS += python
+  REQUIREMENTS += python3
   BUILD_TOOLS := $(filter-out build-python, $(BUILD_TOOLS))
 endif
+PYTHON3 ?= python3
 
 # use the a native awk in native mingw
 ifeq ($(MXE_NATIVE_MINGW_BUILD),yes)
@@ -657,7 +658,7 @@
   mkdir -p '$(3)' && \
   (tar cf $(3)/$($(PKG)_FILE) '.') && \
   (TMP="$(3)" \
-  $(TOP_DIR)/tools/msys2-install.py --verbose --msys-dir="$(MSYS2_DIR)" "$(3)/$($(PKG)_FILE)")
+  $(PYTHON3) $(TOP_DIR)/tools/msys2-install.py --verbose --msys-dir="$(MSYS2_DIR)" "$(3)/$($(PKG)_FILE)")
 endef
 
 define MSYS2_PKG_UPDATE
@@ -831,7 +832,7 @@
         $(CONFIGURE_CPPFLAGS) $(CONFIGURE_LDFLAGS) \
         MKOCTFILE=$(MXE_MKOCTFILE) MAKE=$(MAKE) \
         CONFIGURE_OPTIONS="$(HOST_AND_BUILD_CONFIGURE_OPTIONS)" $(4) \
-        $(TOP_DIR)/tools/pkg-install.py install -verbose "$($(PKG)_FILE)"; \
+        $(PYTHON3) $(TOP_DIR)/tools/pkg-install.py install -verbose "$($(PKG)_FILE)"; \
      fi
 endef
 endif
diff -r 52bed5bd9bbf -r 55959fb9f6d8 tools/msys2-install.py
--- a/tools/msys2-install.py	Fri Jul 03 11:22:44 2020 -0400
+++ b/tools/msys2-install.py	Sat Jul 04 12:14:29 2020 -0400
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/python3
 
 import sys
 import os
@@ -156,7 +156,7 @@
   files=glob.glob(pkgpath + pkgname + "-" + "[r0-9].*")
   for f in files:
     if env.verbose:
-      print "uninstalling " + f
+      print ("uninstalling " + f)
     shutil.rmtree(f)
 
 def install_pkg(pkg, env):
@@ -168,7 +168,7 @@
     ## Check that the directory in prefix exist. If it doesn't: create it!
     tmpdir = tempfile.mkdtemp("-pkg","tmp", env.tmp)
     if env.verbose:
-      print "using tempdir ", tmpdir
+      print ("using tempdir ", tmpdir)
     os.chdir(tmpdir)
 
     # unpack dir
@@ -202,7 +202,7 @@
           fullpath = fullpath[tmplen:]
           filelist.append(fullpath)
           if env.verbose:
-            print "installing " + fullpath
+            print ("installing " + fullpath)
 
           # dele old file fo can copy new with perms (if ld file would allow write)
           if os.path.isfile(env.msysdir + "/" + fullpath):
@@ -211,7 +211,7 @@
           shutil.copy2(os.path.join(root, file), env.msysdir + "/" + fullpath)
 
     if env.verbose:
-      print "creating package files"
+      print ("creating package files")
 
     # create pkg files needed
     pkg_name_ver = pkginfo.get('pkgname', [''])[0] + "-" + pkginfo.get('pkgver',[''])[0]
@@ -225,7 +225,7 @@
 
   finally:
     if env.verbose:
-      print "cleaning up"
+      print ("cleaning up")
     os.chdir(currdir)
 
     if env.cleanup:
@@ -239,7 +239,7 @@
   files = []
  
   for a in args:
-    print a
+    print ("{}".format(a))
     c=a.split("=")
     key=c[0]
     if len(c) > 1:
@@ -275,7 +275,7 @@
   return status
 
 def show_usage():
-  print sys.argv[0], "[options] pkg1 [pkg2]"
+  print (sys.argv[0], "[options] pkg1 [pkg2]")
 
 if __name__ == "__main__":
   if len(sys.argv) > 1:
diff -r 52bed5bd9bbf -r 55959fb9f6d8 tools/pkg-install.py
--- a/tools/pkg-install.py	Fri Jul 03 11:22:44 2020 -0400
+++ b/tools/pkg-install.py	Sat Jul 04 12:14:29 2020 -0400
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/python3
 import sys
 import os
 import re
@@ -24,15 +24,15 @@
   cleanup = False;
 
 def show_usage():
-  print sys.argv(0), "[options] pkg1 [pkg2]"
+  print (sys.argv[0], "[options] pkg1 [pkg2]")
 
 def verify_directory(dirname):
   for f in [ "COPYING", "DESCRIPTION" ]:
     if os.path.isfile(dirname + "/" + f) == False:
-      raise Exception, "package is missing file " + f
+      raise Exception("package is missing file " + f)
 
 def get_description(descfile):
-  with open(descfile, 'r') as f:
+  with open(descfile, 'rt', encoding='latin-1') as f:
     lines = f.read().splitlines()
     pat_match = re.compile("(?P<name>[-\w]+):\s*(?P<value>\w.*)")
     lineval = ""
@@ -52,7 +52,7 @@
 
 def extract_pkg(filename, nm):
   pkg = []
-  with open(filename, 'r') as f:
+  with open(filename, 'rt', encoding='latin-1') as f:
     lines = f.read().splitlines()
     for l in lines:
       so = re.search(nm, l, re.M|re.S)
@@ -64,7 +64,7 @@
   body = []
   if not os.path.isfile(filename):
     return body
-  with open(filename, 'rt') as f:
+  with open(filename, 'rt', encoding='latin-1') as f:
     lines = f.read().splitlines()
     for l in lines:
       if l.startswith("%!"):
@@ -109,7 +109,7 @@
   # somewhere and then on initial startup, run the post_install
   if os.path.isfile(packdir + "/post_install.m") == True:
     if env.verbose:
-      print "Copying .. post_install.m"
+      print ("Copying .. post_install.m")
     destdir = env.prefix + "/share/octave/site/m/once_only"
     if os.path.exists(destdir) == False:
       os.makedirs(destdir)
@@ -117,7 +117,7 @@
 
 def create_pkgadddel (env, packdir, nm):
   if env.verbose:
-    print "Creating...", nm
+    print ("Creating...", nm)
 
   instfid = open(env.m_dir + "/" + nm, "a")
   if os.path.exists(env.arch_dir) == True:
@@ -148,7 +148,7 @@
 
   # add PKG_XXX from packdir if exists
   if os.path.isfile(packdir + "/" + nm) == True:
-    with open(packdir + "/" + nm, 'r') as f:
+    with open(packdir + "/" + nm, 'r', encoding='latin-1') as f:
       lines = f.read().splitlines()
       for a in lines:
         archfid.write("%s\n" % a)
@@ -172,7 +172,7 @@
   for a in files:
     if os.path.isfile(a):
       if verbose:
-        print "copy " + a + " to " + destdir + "/"
+        print ("copy " + a + " to " + destdir + "/")
       shutil.copy2(a, destdir)
     if os.path.isdir(a):
       name= os.path.basename(a)
@@ -185,7 +185,7 @@
   instdir = pkgdir + "/inst"
 
   if env.verbose:
-    print "Copying m files ..."
+    print ("Copying m files ...")
 
   files = list(instdir + "/" + a for a in os.listdir(instdir))
   # filter for arch folder
@@ -196,7 +196,7 @@
 
   if os.path.exists(instdir + "/" + env.arch) == True:
     if env.verbose:
-      print "Copying arch files ..."
+      print ("Copying arch files ...")
     files = list(instdir + "/" + env.arch + "/" + a for a in os.listdir(instdir + "/" + env.arch))
     if len(files) > 0:
       if os.path.exists(env.arch_dir) == False:
@@ -206,7 +206,7 @@
 
   # packinfo
   if env.verbose:
-    print "Copying packinfo files ..."
+    print ("Copying packinfo files ...")
   if os.path.exists(env.m_dir + "/packinfo") == False:
     os.makedirs(env.m_dir + "/packinfo")
   copyfile([pkgdir + "/DESCRIPTION"], env.m_dir + "/packinfo")
@@ -218,7 +218,7 @@
 
   # index file
   if env.verbose:
-    print "Copying/creating INDEX ..."
+    print ("Copying/creating INDEX ...")
   if os.path.isfile(pkgdir + "/INDEX") == True:
     copyfile([pkgdir + "/INDEX"], env.m_dir + "/packinfo")
   else:
@@ -231,7 +231,7 @@
   docdir = pkgdir + "/doc"
   if os.path.exists(docdir) == True:
     if env.verbose:
-      print "Copying doc files ..."
+      print ("Copying doc files ...")
     files = (docdir + "/" + a for a in os.listdir(docdir))
     copyfile(files, env.m_dir + "/doc")
 
@@ -239,7 +239,7 @@
   bindir = pkgdir + "/bin"
   if os.path.exists(bindir) == True:
     if env.verbose:
-      print "Copying bin files ..."
+      print ("Copying bin files ...")
     files = (bindir + "/" + a for a in os.listdir(bindir))
     copyfile(files, env.m_dir + "/bin")
 
@@ -253,20 +253,20 @@
 
     if os.path.isfile(src + "/configure") == True:
       if env.verbose:
-        print "running ./configure " + env.config_opts
+        print ("running ./configure " + env.config_opts)
 
       if os.system("./configure " + env.config_opts + "") != 0:
-        raise Exception, "configure failed - stopping install"
+        raise Exception("configure failed - stopping install")
 
     if os.path.isfile(src + "/Makefile") == True:
       if env.verbose:
-        print "running make ..."
+        print ("running make ...")
       if os.system(env.make + " --directory '" + src + "'" ) != 0:
-        raise Exception, "make failed during build - stopping install"
+        raise Exception("make failed during build - stopping install")
 
     # extract any tests
     if env.verbose:
-      print "checking for src BIST tests"
+      print ("checking for src BIST tests")
 
     files = os.listdir(src)
     srcfiles = fnmatch.filter(files, "*.cc") + fnmatch.filter(files,"*.cpp") + fnmatch.filter(files, "*.cxx") + fnmatch.filter(files, "*.c")
@@ -283,7 +283,7 @@
     archdir = instdir + "/" + env.arch
 
     if os.path.isfile(files) == True:
-      raise Exception, "make using FILES not supported yet"
+      raise Exception("make using FILES not supported yet")
       pass # TODO yet
     else:
       # get .m, .oct and .mex files
@@ -313,18 +313,18 @@
 def uninstall_pkg(pkg,env):
   # uninstall existing directories
   if env.verbose:
-     print "Uninstalling " + env.pkg
+     print ("Uninstalling " + env.pkg)
 
   files=glob.glob(env.prefix + "/share/octave/packages/" + env.pkg + "-" + "*")
   for f in files:
     if env.verbose:
-      print "removing dir " + f
+      print ("removing dir " + f)
     shutil.rmtree(f)
 
   files=glob.glob(env.prefix + "/lib/octave/packages/" + env.pkg + "-" + "*")
   for f in files:
     if env.verbose:
-      print "removing dir " + f
+      print ("removing dir " + f)
     shutil.rmtree(f)
 
   pass
@@ -334,7 +334,7 @@
   currdir = os.getcwd()
 
   if env.verbose:
-     print "Installing " + pkg
+     print ("Installing " + pkg)
 
   try:
     ## Check that the directory in prefix exist. If it doesn't: create it!
@@ -350,7 +350,7 @@
     # get list for files creates
     files=os.listdir(tmpdir)
     if len(files) != 1:
-      print "Expected to unpack to only one directory"
+      print ("Expected to unpack to only one directory")
 
     packdir = os.path.abspath(files[0])
 
@@ -381,7 +381,7 @@
     add_package_list(env, desc)
   finally:
     if env.verbose:
-      print "cleaning up"
+      print ("cleaning up")
     os.chdir(currdir)
 
     if env.cleanup:
@@ -410,7 +410,7 @@
   currdir = os.getcwd()
 
   if env.verbose:
-    print "Rebuilding package"
+    print ("Rebuilding package")
 
   try:
     oct_dir = env.prefix + "/share/octave"
@@ -422,7 +422,7 @@
     descs=glob.glob(pkg_dir + "/*/packinfo/DESCRIPTION")
 
     if env.verbose:
-      print "Rebuilding pkg list {}".format(pkg_list_file)
+      print ("Rebuilding pkg list {}".format(pkg_list_file))
 
     with open(pkg_list_file, "w") as f:
       f.write("# Created by pkg-install.py\n")
@@ -528,7 +528,7 @@
 
   operation = args[0]
   if operation != "install" and operation != "rebuild":
-    raise Exception, "Expected pkg operation 'install' or 'rebuild'"
+    raise Exception("Expected pkg operation 'install' or 'rebuild'")
 
 
   args = args[1:]
@@ -597,12 +597,12 @@
   env.bindir = os.popen(env.octave_config + " -p BINDIR").read().rstrip("\r\n")
 
   if env.verbose:
-    print "operation=", operation
-    print "mkoctfile=", env.mkoctfile
-    print "arch=", env.arch
-    print "prefix=", env.prefix
-    print "files=", files
-    print "verbose=", env.verbose
+    print ("operation=", operation)
+    print ("mkoctfile=", env.mkoctfile)
+    print ("arch=", env.arch)
+    print ("prefix=", env.prefix)
+    print ("files=", files)
+    print ("verbose=", env.verbose)
 
   if operation == "install":
     for a in files:
