Skip to content

Commit

Permalink
Merge pull request #1394 from xael-fry/pr_1355_v3
Browse files Browse the repository at this point in the history
[#1353, #1355] update python 3
  • Loading branch information
xael-fry authored Apr 3, 2022
2 parents b791ed8 + d99cf34 commit 6b17d80
Show file tree
Hide file tree
Showing 799 changed files with 3,448 additions and 251,617 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ jobs:
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0

- name: Set up python 2
uses: actions/setup-python@v2
- name: Set up python 3
uses: actions/setup-python@v3
with:
python-version: '2.x'
python-version: '3.x'
architecture: 'x64'
cache: 'pip'
cache-dependency-path: '**/requirements.txt'
- run: pip install -r python/requirements.txt

- name: Set up JDK ${{ matrix.jdk }}
uses: actions/setup-java@v2
Expand Down Expand Up @@ -79,4 +82,4 @@ jobs:
name: play-${{ github.sha }}
if-no-files-found: error
path: |
./framework/dist/*
./framework/dist/*
2 changes: 1 addition & 1 deletion framework/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
<condition property="playExtension" value="">
<and><os family="unix"/></and>
</condition>
<condition property="pythonExecutable" value="${basedir}/../python/python.exe">
<condition property="pythonExecutable" value="python">
<and><os family="windows"/></and>
</condition>
<condition property="pythonExecutable" value="python">
Expand Down
93 changes: 48 additions & 45 deletions framework/pym/play/application.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import print_function
from builtins import input
from builtins import object
import sys
import os
import os.path
Expand All @@ -24,23 +27,23 @@ def __init__(self, application_path, env, ignoreMissingModules = False):
# only parse conf it is exists - if it should be there, it will be caught later
# (depends on command)
confExists = os.path.exists(os.path.join(self.path, 'conf', 'application.conf'));
if application_path is not None and confExists:
if application_path != None and confExists:
confFolder = os.path.join(application_path, 'conf/')
try:
self.conf = PlayConfParser(confFolder, env)
except Exception as err:
print "~ Failed to parse application configuration", err
print("~ Failed to parse application configuration", err)
self.conf = None # No app / Invalid app
else:
self.conf = None
self.play_env = env

if env.has_key('jpda.port'):
if 'jpda.port' in env:
self.jpda_port = env['jpda.port']
else:
self.jpda_port = self.readConf('jpda.port')

if env.has_key('jpda.address'):
if 'jpda.address' in env:
self.jpda_address = env['jpda.address']
else:
self.jpda_address = self.readConf('jpda.address')
Expand All @@ -54,9 +57,9 @@ def check(self):
assert os.path.exists(os.path.join(self.path, 'conf', 'routes'))
assert os.path.exists(os.path.join(self.path, 'conf', 'application.conf'))
except AssertionError:
print "~ Oops. conf/routes or conf/application.conf missing."
print "~ %s does not seem to host a valid application." % os.path.normpath(self.path)
print "~"
print("~ Oops. conf/routes or conf/application.conf missing.")
print("~ %s does not seem to host a valid application." % os.path.normpath(self.path))
print("~")
sys.exit(-1)

def readConf(self, key):
Expand All @@ -78,20 +81,20 @@ def modules(self):
application_mode = "dev"
if application_mode == 'dev':
#Load docviewer module
modules.append(os.path.normpath(os.path.join(self.play_env["basedir"], 'modules/docviewer')))
modules.append(os.path.normpath(os.path.join(self.play_env["basedir"], 'modules/docviewer')))

for m in self.readConfs('module.'):
if '${play.path}' in m:
m = m.replace('${play.path}', self.play_env["basedir"])
if m[0] is not '/':
if m[0] != '/':
m = os.path.normpath(os.path.join(self.path, m))
if not os.path.exists(m) and not self.ignoreMissingModules:
print "~ Oops,"
print "~ Module not found: %s" % (m)
print "~"
print("~ Oops,")
print("~ Module not found: %s" % (m))
print("~")
if m.startswith('${play.path}/modules'):
print "~ You can try to install the missing module using 'play install %s'" % (m[21:])
print "~"
print("~ You can try to install the missing module using 'play install %s'" % (m[21:]))
print("~")
sys.exit(-1)
modules.append(m)
if self.path and os.path.exists(os.path.join(self.path, 'modules')):
Expand All @@ -108,26 +111,26 @@ def modules(self):
return set(modules) # Ensure we don't have duplicates

def module_names(self):
return map(lambda x: x[7:],self.conf.getAllKeys("module."))
return [x[7:] for x in self.conf.getAllKeys("module.")]

def override(self, f, t):
fromFile = None
for module in self.modules():
pc = os.path.join(module, f)
if os.path.exists(pc): fromFile = pc
if not fromFile:
print "~ %s not found in any module" % f
print "~ "
print("~ %s not found in any module" % f)
print("~ ")
sys.exit(-1)
toFile = os.path.join(self.path, t)
if os.path.exists(toFile):
response = raw_input("~ Warning! %s already exists and will be overridden (y/n)? " % toFile)
response = input("~ Warning! %s already exists and will be overridden (y/n)? " % toFile)
if not response == 'y':
return
if not os.path.exists(os.path.dirname(toFile)):
os.makedirs(os.path.dirname(toFile))
shutil.copyfile(fromFile, toFile)
print "~ Copied %s to %s " % (fromFile, toFile)
print("~ Copied %s to %s " % (fromFile, toFile))

def name(self):
return self.readConf("application.name")
Expand Down Expand Up @@ -207,15 +210,15 @@ def fw_cp_args(self):
return cp_args

def pid_path(self):
if self.play_env.has_key('pid_file'):
if 'pid_file' in self.play_env:
return os.path.join(self.path, self.play_env['pid_file'])
elif os.environ.has_key('PLAY_PID_PATH'):
elif 'PLAY_PID_PATH' in os.environ:
return os.environ['PLAY_PID_PATH']
else:
return os.path.join(self.path, 'server.pid')

def log_path(self):
if not os.environ.has_key('PLAY_LOG_PATH'):
if 'PLAY_LOG_PATH' not in os.environ:
log_path = os.path.join(self.path, 'logs')
else:
log_path = os.environ['PLAY_LOG_PATH']
Expand All @@ -231,12 +234,12 @@ def check_jpda(self):
else:
s.bind((self.jpda_address, int(self.jpda_port)))
s.close()
except socket.error, e:
except socket.error as e:
if "disable_random_jpda" in self.play_env and self.play_env["disable_random_jpda"]:
print 'JPDA port %s is already used, and command line option "-f" was specified. Cannot start server\n' % self.jpda_port
print('JPDA port %s is already used, and command line option "-f" was specified. Cannot start server\n' % self.jpda_port)
sys.exit(-1)
else:
print 'JPDA port %s is already used. Will try to use any free port for debugging' % self.jpda_port
print('JPDA port %s is already used. Will try to use any free port for debugging' % self.jpda_port)
self.jpda_port = 0

def java_args_memory(self, java_args):
Expand Down Expand Up @@ -272,43 +275,43 @@ def java_cmd(self, java_args, cp_args=None, className='play.server.Server', args
if cp_args is None:
cp_args = self.cp_args()

if self.play_env.has_key('jpda.port'):
if 'jpda.port' in self.play_env:
self.jpda_port = self.play_env['jpda.port']

if self.play_env.has_key('jpda.address'):
if 'jpda.address' in self.play_env:
self.jpda_address = self.play_env['jpda.address']

application_mode = self.readConf('application.mode').lower()
if not application_mode:
print "~ Warning: no application.mode defined in you conf/application.conf. Using DEV mode."
print("~ Warning: no application.mode defined in you conf/application.conf. Using DEV mode.")
application_mode = "dev"


if application_mode == 'prod':
java_args.append('-server')

if self.play_env.has_key('jvm_version'):
if 'jvm_version' in self.play_env:
javaVersion = self.play_env['jvm_version']
else:
javaVersion = getJavaVersion()
print "~ using java version \"%s\"" % javaVersion
print("~ using java version \"%s\"" % javaVersion)

if javaVersion.startswith("1.5") or javaVersion.startswith("1.6") or javaVersion.startswith("1.7"):
print "~ ERROR: java version prior to 1.8 are no longer supported: current version \"%s\" : please update" % javaVersion
print("~ ERROR: java version prior to 1.8 are no longer supported: current version \"%s\" : please update" % javaVersion)

java_args.append('-noverify')

java_policy = self.readConf('java.policy')
if java_policy != '':
policyFile = os.path.join(self.path, 'conf', java_policy)
if os.path.exists(policyFile):
print "~ using policy file \"%s\"" % policyFile
print("~ using policy file \"%s\"" % policyFile)
java_args.append('-Djava.security.manager')
java_args.append('-Djava.security.policy==%s' % policyFile)

if self.play_env.has_key('http.port'):
if 'http.port' in self.play_env:
args += ["--http.port=%s" % self.play_env['http.port']]
if self.play_env.has_key('https.port'):
if 'https.port' in self.play_env:
args += ["--https.port=%s" % self.play_env['https.port']]

java_args.append('-Dfile.encoding=utf-8')
Expand Down Expand Up @@ -345,7 +348,7 @@ def _absoluteToRelative(path, start):
return os.path.curdir
return os.path.join(*rel_list)

class PlayConfParser:
class PlayConfParser(object):

DEFAULTS = {
'http.port': '9000',
Expand All @@ -355,15 +358,15 @@ class PlayConfParser:
def __init__(self, confFolder, env):
self.id = env["id"]
self.entries = self.readFile(confFolder, "application.conf")
if env.has_key('jpda.port'):
if 'jpda.port' in env:
self.entries['jpda.port'] = env['jpda.port']
if env.has_key('http.port'):
if 'http.port' in env:
self.entries['http.port'] = env['http.port']
if env.has_key('jvm_version'):
if 'jvm_version' in env:
self.entries['jvm_version'] = env['jvm_version']

def readFile(self, confFolder, filename):
f = file(confFolder + filename)
f = open(confFolder + filename, 'r')
result = dict()
for line in f:
linedef = line.strip()
Expand All @@ -382,12 +385,12 @@ def readFile(self, confFolder, filename):
washedResult = dict()

# first get all keys with correct framework id
for (key, value) in result.items():
for (key, value) in list(result.items()):
if key.startswith('%' + self.id + '.'):
stripedKey = key[(len(self.id)+2):]
washedResult[stripedKey]=value
# now get all without framework id if we don't already have it
for (key, value) in result.items():
for (key, value) in list(result.items()):
if not key.startswith('%'):
# check if we already have it
if not (key in washedResult):
Expand All @@ -396,7 +399,7 @@ def readFile(self, confFolder, filename):

# find all @include
includeFiles = []
for (key, value) in washedResult.items():
for (key, value) in list(washedResult.items()):
if key.startswith('@include.'):
includeFiles.append(value)

Expand All @@ -407,10 +410,10 @@ def readFile(self, confFolder, filename):
fromIncludeFile = self.readFile(confFolder, self._expandValue(includeFile))

# add everything from include file
for (key, value) in fromIncludeFile.items():
for (key, value) in list(fromIncludeFile.items()):
washedResult[key]=value
except Exception as err:
print "~ Failed to load included configuration %s: %s" % (includeFile, err)
print("~ Failed to load included configuration %s: %s" % (includeFile, err))

return washedResult

Expand All @@ -423,7 +426,7 @@ def get(self, key):

def getAllKeys(self, query):
result = []
for (key, value) in self.entries.items():
for (key, value) in list(self.entries.items()):
if key.startswith(query):
result.append(key)
return result
Expand Down
18 changes: 11 additions & 7 deletions framework/pym/play/cmdloader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import print_function
import imp
import os
import warnings
import traceback

def play_formatwarning(msg, *a):
# ignore everything except the message
Expand All @@ -9,7 +11,7 @@ def play_formatwarning(msg, *a):

warnings.formatwarning = play_formatwarning

class CommandLoader:
class CommandLoader(object):
def __init__(self, play_path):
self.path = os.path.join(play_path, 'framework', 'pym', 'play', 'commands')
self.commands = {}
Expand All @@ -23,7 +25,9 @@ def load_core(self):
name = filename.replace(".py", "")
mod = load_python_module(name, self.path)
self._load_cmd_from(mod)
except:
except Exception as e:
print (e)
traceback.print_exc()
warnings.warn("!! Warning: could not load core command file " + filename, RuntimeWarning)

def load_play_module(self, modname):
Expand All @@ -33,10 +37,10 @@ def load_play_module(self, modname):
leafname = os.path.basename(modname).split('.')[0]
mod = imp.load_source(leafname, os.path.join(modname, "commands.py"))
self._load_cmd_from(mod)
except Exception, e:
print '~'
print '~ !! Error while loading %s: %s' % (commands, e)
print '~'
except Exception as e:
print('~')
print('~ !! Error while loading %s: %s' % (commands, e))
print('~')
pass # No command to load in this module

def _load_cmd_from(self, mod):
Expand All @@ -57,6 +61,6 @@ def load_python_module(name, location):
try:
return imp.load_module(name, mod_desc[0], mod_desc[1], mod_desc[2])
finally:
if mod_file is not None and not mod_file.closed:
if mod_file != None and not mod_file.closed:
mod_file.close()

7 changes: 4 additions & 3 deletions framework/pym/play/commands/ant.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import os, os.path
import shutil
import time
Expand All @@ -20,6 +21,6 @@ def execute(**kargs):

shutil.copyfile(os.path.join(play_env["basedir"], 'resources/build.xml'), os.path.join(app.path, 'build.xml'))

print "~ OK, a build.xml file has been created"
print "~ Define the PLAY_PATH env property, and use it with ant run|start|stop"
print "~"
print("~ OK, a build.xml file has been created")
print("~ Define the PLAY_PATH env property, and use it with ant run|start|stop")
print("~")
Loading

0 comments on commit 6b17d80

Please sign in to comment.