Commit 88f019b7 authored by Wolfgang Rohdewald's avatar Wolfgang Rohdewald

remove support for mixing python2 and python3 and merge version with defaultPort

twisted PB does not support mixing python3 and python3 either
parent f0b69706
......@@ -31,7 +31,7 @@ class About(object):
self.appName = "kajongg"
catalog = ""
homePage = "http://kde.org/applications/games/kajongg/"
version = Internal.version
version = str(Internal.defaultPort)
programName = ki18n("Kajongg")
description = ki18n(
"Mah Jongg - the ancient Chinese board game for 4 players")
......
......@@ -43,12 +43,17 @@ if platform.python_version_tuple()[0] == '3':
bytes = bytes
long = int
isPython3 = True
interpreterName = 'python3'
else:
# pylint: disable=redefined-builtin
unicode = unicode
bytes = str
long = long
isPython3 = False
if os.name == 'nt':
interpreterName = 'python'
else:
interpreterName = 'python2'
WINDS = u'ESWN'
LIGHTSOURCES = [u'NE', u'NW', u'SW', u'SE']
......@@ -220,12 +225,6 @@ class Options(object):
def __init__(self):
raise Exception('Options is not meant to be instantiated')
@staticmethod
def defaultPort():
"""8000 plus version: for version 4.9.5 we use 8409"""
parts = Internal.version.split('.')
return 8000 + int(parts[0]) * 100 + int(parts[1])
class SingleshotOptions(object):
......@@ -262,7 +261,10 @@ class __Internal(object):
"""
# pylint: disable=too-many-instance-attributes
Preferences = None
version = '4.13.0'
if isPython3:
defaultPort = 8300
else:
defaultPort = 8200
logPrefix = 'C'
isServer = False
scaleScene = True
......
......@@ -435,7 +435,8 @@ class HumanClient(Client):
maxGameId = int(maxGameId) if maxGameId else 0
self.callServer('setClientProperties',
Internal.db.identifier,
voiceId, maxGameId, Internal.version).addCallbacks(self.__initTableList, self.__versionError)
voiceId, maxGameId,
Internal.defaultPort).addCallbacks(self.__initTableList, self.__versionError)
def __initTableList(self, dummy):
"""first load of the list. Process options like --demo, --table, --join"""
......@@ -891,6 +892,8 @@ class HumanClient(Client):
if debugArgs[0] == 'setClientProperties':
debugArgs[1] = 'DBID'
debugArgs[3] = 'GAMEID'
if debugArgs[4] >= 8300:
debugArgs[4] -= 300
if self.game:
self.game.debug('callServer(%s)' % repr(debugArgs))
else:
......
......@@ -35,7 +35,7 @@ from tempfile import mkdtemp
from optparse import OptionParser
from common import Debug, StrMixin
from common import Debug, StrMixin, isPython3, interpreterName
from util import removeIfExists, gitHead, checkMemory
from compat import Csv, CsvWriter
......@@ -173,13 +173,8 @@ class Server(StrMixin):
print('starting server for %s commit=%s in %s' % (' ' * 16, job.commitId, self.clone.tmpdir))
cmd = [os.path.join(
job.srcDir(),
'kajonggserver3.py' if OPTIONS.server3 else 'kajonggserver.py')]
if OPTIONS.server3:
cmd.insert(0, 'python3')
elif os.name == 'nt':
cmd.insert(0, 'python')
else:
cmd.insert(0, 'python2')
'kajonggserver3.py' if isPython3 else 'kajonggserver.py')]
cmd.insert(0, interpreterName)
if OPTIONS.usePort:
self.portNumber = random.randrange(1025, 65000)
cmd.append('--port={port}'.format(port=self.portNumber))
......@@ -278,12 +273,7 @@ class Job(StrMixin):
cmd.append('--socket={sock}'.format(sock=self.server.socketName))
if self.server.portNumber:
cmd.append('--port={port}'.format(port=self.server.portNumber))
if OPTIONS.client3:
cmd.insert(0, 'python3')
elif os.name == 'nt':
cmd.insert(0, 'python')
else:
cmd.insert(0, 'python2')
cmd.insert(0, interpreterName)
if OPTIONS.rounds:
cmd.append('--rounds={rounds}'.format(rounds=OPTIONS.rounds))
if self.aiVariant != 'Default':
......@@ -638,12 +628,6 @@ def parse_options():
help='check all commits: either a comma separated list or a range from..until')
parser.add_option('', '--debug', dest='debug',
help=Debug.help())
parser.add_option(
'', '--client3', dest='client3', action='store_true', default=False,
help='use Python 3 for all clients')
parser.add_option(
'', '--server3', dest='server3', action='store_true', default=False,
help='use Python 3 for all servers')
return parser.parse_args()
......
......@@ -120,4 +120,4 @@ def socketName():
if Options.socket:
return Options.socket
else:
return os.path.normpath('{}/socket{}'.format(serverDir, Options.defaultPort()))
return os.path.normpath('{}/socket{}'.format(serverDir, Internal.defaultPort))
......@@ -1088,7 +1088,7 @@ class KConfig(SafeConfigParser):
for section in self._sections:
filePointer.write(("[%s]\n" % section).encode('utf-8'))
for (key, value) in self._sections[section].items():
key = str(key).encode('utf-8')
key = bytes(str(key).encode('utf-8')) # pylint bug, bytes() should not be needed
value = str(value).encode('utf-8')
if key == "__name__":
continue
......@@ -1331,7 +1331,7 @@ class AboutKajonggDialog(KDialog):
hLayout1.addWidget(IconLabel('kajongg', self))
h1vLayout = QVBoxLayout()
h1vLayout.addWidget(QLabel('Kajongg'))
h1vLayout.addWidget(QLabel(i18n('Version %1', Internal.version)))
h1vLayout.addWidget(QLabel(i18n('Protocol version %1', Internal.defaultPort)))
underVersions = []
try:
versions = subprocess.Popen(['kde4-config', '-v'],
......
......@@ -42,7 +42,7 @@ from dialogs import DeferredDialog, QuestionYesNo, MustChooseKDialog
from log import logWarning, logException, logInfo, logDebug, m18n, m18nc, SERVERMARK
from util import removeIfExists, which
from common import Internal, Options, SingleshotOptions, Debug, isAlive, english, unicode
from common import nativeString, unicodeString
from common import isPython3, nativeString, unicodeString, interpreterName
from game import Players
from query import Query
from statesaver import StateSaver
......@@ -85,7 +85,7 @@ class Url(unicode):
if obj.port is None and obj.isLocalHost and not obj.useSocket:
obj.port = obj.__findFreePort()
if obj.port is None and not obj.isLocalHost:
obj.port = Options.defaultPort()
obj.port = Internal.defaultPort
if Debug.connections:
logDebug(repr(obj))
......@@ -130,7 +130,7 @@ class Url(unicode):
"""find an unused port on the current system.
used when we want to start a local server on windows"""
assert self.isLocalHost
for port in chain([Options.defaultPort()], range(2000, 19000)):
for port in chain([Internal.defaultPort], range(2000, 19000)):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
try:
......@@ -178,22 +178,21 @@ class Url(unicode):
def __findServerProgram():
"""how should we start the server?"""
result = []
serverPython = 'python3' if Options.server3 else 'python'
if sys.argv[0].endswith('kajongg.py'):
tryServer = sys.argv[0].replace('.py', 'server.py')
if os.path.exists(tryServer):
result = [serverPython, tryServer]
result = [interpreterName, tryServer]
elif sys.argv[0].endswith('kajongg.pyw'):
tryServer = sys.argv[0].replace('.pyw', 'server.py')
if os.path.exists(tryServer):
result = [serverPython, tryServer]
result = [interpreterName, tryServer]
elif sys.argv[0].endswith('kajongg.exe'):
tryServer = sys.argv[0].replace('.exe', 'server.exe')
if os.path.exists(tryServer):
result = [tryServer]
else:
result = ['kajonggserver']
if Options.server3:
if isPython3:
result[-1] = result[-1].replace('server', 'server3')
if Debug.connections:
logDebug(m18n('trying to start local server %1', result))
......@@ -212,7 +211,9 @@ class Url(unicode):
args.append('--port=%d' % self.port)
if self.isLocalGame:
args.append(
'--db={}'.format(os.path.normpath(appdataDir() + 'local.db')))
'--db={}'.format(
os.path.normpath(
appdataDir() + 'local{}.db'.format('3' if isPython3 else ''))))
if Debug.argString:
args.append('--debug=%s' % Debug.argString)
if os.name == 'nt':
......
......@@ -35,7 +35,7 @@ from kde import appdataDir
from util import Duration
from log import logInfo, logWarning, logException, logError, logDebug, m18ncE, m18n
from common import IntDict, Options, Internal, Debug, nativeStringArgs, unicodeString
from common import unicode, isPython3
class QueryException(Exception):
......@@ -157,7 +157,11 @@ class DBHandle(sqlite3.Connection):
@return: The full path for kajonggserver.db or kajongg.db.
@rtype: C{str}
"""
name = 'kajonggserver.db' if Internal.isServer else 'kajongg.db'
name = 'kajonggserver' if Internal.isServer else 'kajongg'
if isPython3:
name += '3.db'
else:
name += '.db'
return Options.dbPath if Options.dbPath else appdataDir() + name
@property
......@@ -371,7 +375,7 @@ class PrepareDB(object):
self.createTables()
self.__generateDbIdent()
Query(
'UPDATE general SET schemaversion=?', (Internal.version,))
'UPDATE general SET schemaversion=?', (Internal.defaultPort,))
finally:
Internal.db.close(silent=True)
if os.path.exists(self.path):
......@@ -398,8 +402,12 @@ class PrepareDB(object):
"""upgrade the structure of an existing kajongg database"""
try:
Internal.db = DBHandle(self.path)
allVersions = list(['4.13.0'])
assert allVersions[-1] == Internal.version
if isPython3:
allVersions = list(['4.13.0', '8300'])
else:
allVersions = list(['4.13.0', '8200'])
assert allVersions[-1] == str(Internal.defaultPort), '{} != {}'.format(
allVersions[-1], str(Internal.defaultPort))
# skip versions before current db versions:
currentVersion = self.__currentVersion()
while allVersions and allVersions[0] <= currentVersion:
......
......@@ -1351,7 +1351,7 @@ class User(pb.Avatar):
self.voiceId = voiceId
self.maxGameId = maxGameId
clientVersion = nativeString(clientVersion)
serverVersion = Internal.version
serverVersion = Internal.defaultPort
if clientVersion != serverVersion:
# we assume that versions x.y.* are compatible
if clientVersion is None:
......@@ -1435,7 +1435,7 @@ def parseArgs():
"""as the name says"""
from optparse import OptionParser
parser = OptionParser()
defaultPort = Options.defaultPort()
defaultPort = Internal.defaultPort
parser.add_option('', '--port', dest='port',
help=m18n(
'the server will listen on PORT (%d)' %
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment