Browse Source

adapt runant.py to Python3

closes #96, thanks to @twogee
master
Stefan Bodewig 5 years ago
parent
commit
99ef834ef2
2 changed files with 22 additions and 19 deletions
  1. +2
    -0
      WHATSNEW
  2. +20
    -19
      src/script/runant.py

+ 2
- 0
WHATSNEW View File

@@ -1,6 +1,8 @@
Changes from Ant 1.9.14 TO Ant 1.9.15 Changes from Ant 1.9.14 TO Ant 1.9.15
===================================== =====================================


* The runant.py script should now work with Python 3.
Github Pull Request #96


Changes from Ant 1.9.13 TO Ant 1.9.14 Changes from Ant 1.9.13 TO Ant 1.9.14
===================================== =====================================


+ 20
- 19
src/script/runant.py View File

@@ -6,7 +6,7 @@
# (the "License"); you may not use this file except in compliance with # (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at # the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0
# https://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
@@ -28,7 +28,8 @@


- the "java" executable/script is on the command path - the "java" executable/script is on the command path
""" """
import os, os.path, string, sys
import os.path
import sys


# Change it to 1 to get extra debug information # Change it to 1 to get extra debug information
debug = 0 debug = 0
@@ -36,7 +37,7 @@ debug = 0
####################################################################### #######################################################################


# If ANT_HOME is not set default to script's parent directory # If ANT_HOME is not set default to script's parent directory
if os.environ.has_key('ANT_HOME'):
if 'ANT_HOME' in os.environ:
ANT_HOME = os.environ['ANT_HOME'] ANT_HOME = os.environ['ANT_HOME']
else: else:
ANT_HOME = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) ANT_HOME = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))
@@ -46,17 +47,17 @@ ANT_LIB = os.path.join(ANT_HOME, 'lib')


# set JAVACMD (check variables JAVACMD and JAVA_HOME) # set JAVACMD (check variables JAVACMD and JAVA_HOME)
JAVACMD = None JAVACMD = None
if not os.environ.has_key('JAVACMD'):
if os.environ.has_key('JAVA_HOME'):
if 'JAVACMD' not in os.environ:
if 'JAVA_HOME' in os.environ:
if not os.path.exists(os.environ['JAVA_HOME']): if not os.path.exists(os.environ['JAVA_HOME']):
print "Warning: JAVA_HOME is not defined correctly."
print("Warning: JAVA_HOME is not defined correctly.")
else: else:
JAVA_HOME = os.environ['JAVA_HOME'] JAVA_HOME = os.environ['JAVA_HOME']
while JAVA_HOME[0] == JAVA_HOME[-1] == "\"": while JAVA_HOME[0] == JAVA_HOME[-1] == "\"":
JAVA_HOME = JAVA_HOME[1:-1] JAVA_HOME = JAVA_HOME[1:-1]
JAVACMD = os.path.join(JAVA_HOME, 'bin', 'java') JAVACMD = os.path.join(JAVA_HOME, 'bin', 'java')
else: else:
print "Warning: JAVA_HOME not set."
print("Warning: JAVA_HOME not set.")
else: else:
JAVACMD = os.environ['JAVACMD'] JAVACMD = os.environ['JAVACMD']
if not JAVACMD: if not JAVACMD:
@@ -64,41 +65,41 @@ if not JAVACMD:


launcher_jar = os.path.join(ANT_LIB, 'ant-launcher.jar') launcher_jar = os.path.join(ANT_LIB, 'ant-launcher.jar')
if not os.path.exists(launcher_jar): if not os.path.exists(launcher_jar):
print 'Warning: Unable to locate ant-launcher.jar. Expected to find it in %s' % \
ANT_LIB
print('Warning: Unable to locate ant-launcher.jar. Expected to find it ' +
'in %s' % ANT_LIB)


# Build up standard classpath (LOCALCLASSPATH) # Build up standard classpath (LOCALCLASSPATH)
LOCALCLASSPATH = launcher_jar LOCALCLASSPATH = launcher_jar
if os.environ.has_key('LOCALCLASSPATH'):
if 'LOCALCLASSPATH' in os.environ:
LOCALCLASSPATH += os.pathsep + os.environ['LOCALCLASSPATH'] LOCALCLASSPATH += os.pathsep + os.environ['LOCALCLASSPATH']


ANT_OPTS = "" ANT_OPTS = ""
if os.environ.has_key('ANT_OPTS'):
if 'ANT_OPTS' in os.environ:
ANT_OPTS = os.environ['ANT_OPTS'] ANT_OPTS = os.environ['ANT_OPTS']


OPTS = "" OPTS = ""
if os.environ.has_key('JIKESPATH'):
if 'JIKESPATH' in os.environ:
OPTS = '-Djikes.class.path=\"%s\"' % os.environ['JIKESPATH'] OPTS = '-Djikes.class.path=\"%s\"' % os.environ['JIKESPATH']


ANT_ARGS = "" ANT_ARGS = ""
if os.environ.has_key('ANT_ARGS'):
if 'ANT_ARGS' in os.environ:
ANT_ARGS = os.environ['ANT_ARGS'] ANT_ARGS = os.environ['ANT_ARGS']


CLASSPATH = "" CLASSPATH = ""
if os.environ.has_key('CLASSPATH'):
if 'CLASSPATH' in os.environ:
CLASSPATH = "-lib " + os.environ['CLASSPATH'] CLASSPATH = "-lib " + os.environ['CLASSPATH']


while JAVACMD[0] == JAVACMD[-1] == "\"": while JAVACMD[0] == JAVACMD[-1] == "\"":
JAVACMD = JAVACMD[1:-1] JAVACMD = JAVACMD[1:-1]


# Builds the commandline # Builds the commandline
cmdline = ('"%s" %s -classpath %s -Dant.home=%s %s ' + \
'org.apache.tools.ant.launch.Launcher %s %s %s') \
% (JAVACMD, ANT_OPTS, LOCALCLASSPATH, ANT_HOME, OPTS, ANT_ARGS, \
CLASSPATH, string.join(sys.argv[1:], ' '))
cmdline = ('"%s" %s -classpath %s -Dant.home=%s %s ' +
'org.apache.tools.ant.launch.Launcher %s %s %s') \
% (JAVACMD, ANT_OPTS, LOCALCLASSPATH, ANT_HOME, OPTS, ANT_ARGS,
CLASSPATH, ' '.join(sys.argv[1:]))


if debug: if debug:
print '\n%s\n\n' % (cmdline)
print('\n%s\n\n' % cmdline)
sys.stdout.flush() sys.stdout.flush()


# Run the biniou! # Run the biniou!


Loading…
Cancel
Save