summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Rohdewald <wolfgang@rohdewald.de>2016-08-11 15:07:18 (GMT)
committerWolfgang Rohdewald <wolfgang@rohdewald.de>2016-08-24 10:26:53 (GMT)
commit88f019b7f2480c95bb193f909920913975bfaedf (patch)
tree959339bb741943ec6800f08988a49213b38b9af6
parentf0b6970680fc8298b0d63e44e96d542cbd575096 (diff)
remove support for mixing python2 and python3 and merge version with defaultPort
twisted PB does not support mixing python3 and python3 either
-rw-r--r--src/about.py2
-rw-r--r--src/common.py16
-rw-r--r--src/humanclient.py5
-rwxr-xr-xsrc/kajonggtest.py24
-rw-r--r--src/kde.py2
-rw-r--r--src/kdestub.py4
-rw-r--r--src/login.py17
-rw-r--r--src/query.py18
-rw-r--r--src/server.py4
9 files changed, 45 insertions, 47 deletions
diff --git a/src/about.py b/src/about.py
index 399289a..a0c1647 100644
--- a/src/about.py
+++ b/src/about.py
@@ -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")
diff --git a/src/common.py b/src/common.py
index 7b5b99f..f014c5e 100644
--- a/src/common.py
+++ b/src/common.py
@@ -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
diff --git a/src/humanclient.py b/src/humanclient.py
index 9d0ec66..74094c1 100644
--- a/src/humanclient.py
+++ b/src/humanclient.py
@@ -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:
diff --git a/src/kajonggtest.py b/src/kajonggtest.py
index 0d3ce9b..28c2b39 100755
--- a/src/kajonggtest.py
+++ b/src/kajonggtest.py
@@ -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()
diff --git a/src/kde.py b/src/kde.py
index 7d3621c..d1e18c6 100644
--- a/src/kde.py
+++ b/src/kde.py
@@ -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))
diff --git a/src/kdestub.py b/src/kdestub.py
index 935e1da..13d0a9b 100644
--- a/src/kdestub.py
+++ b/src/kdestub.py
@@ -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'],
diff --git a/src/login.py b/src/login.py
index 5765564..55711c7 100644
--- a/src/login.py
+++ b/src/login.py
@@ -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':
diff --git a/src/query.py b/src/query.py
index ec0adfd..3c94732 100644
--- a/src/query.py
+++ b/src/query.py
@@ -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:
diff --git a/src/server.py b/src/server.py
index 75ddb2c..04d8877 100644
--- a/src/server.py
+++ b/src/server.py
@@ -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)' %