mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Extract a common function.
This commit is contained in:
parent
ed07eaf3fb
commit
f18c394c33
5 changed files with 12 additions and 22 deletions
|
@ -2,13 +2,12 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import builtins
|
import builtins
|
||||||
from pysollib.mygettext import fix_gettext
|
from pysollib.mygettext import fix_gettext
|
||||||
|
|
||||||
from pysollib.gamedb import GAME_DB
|
from pysollib.gamedb import GAME_DB
|
||||||
from pysollib.gamedb import GI
|
from pysollib.gamedb import GI
|
||||||
from pysollib.mfxutil import latin1_to_ascii
|
from pysollib.mfxutil import latin1_normalize
|
||||||
# outdir = '../html'
|
# outdir = '../html'
|
||||||
pysollib_dir = '../'
|
pysollib_dir = '../'
|
||||||
|
|
||||||
|
@ -129,11 +128,7 @@ alink="#FF0000">
|
||||||
def getGameRulesFilename(n):
|
def getGameRulesFilename(n):
|
||||||
if n.startswith('Mahjongg'):
|
if n.startswith('Mahjongg'):
|
||||||
return 'mahjongg.html'
|
return 'mahjongg.html'
|
||||||
# n = re.sub(r"[\[\(].*$", "", n)
|
return latin1_normalize(n) + '.html'
|
||||||
n = latin1_to_ascii(n)
|
|
||||||
n = re.sub(r"[^\w]", "", n)
|
|
||||||
n = n.lower() + ".html"
|
|
||||||
return n
|
|
||||||
|
|
||||||
|
|
||||||
def gen_main_html():
|
def gen_main_html():
|
||||||
|
|
|
@ -31,7 +31,7 @@ import traceback
|
||||||
from pysollib.mfxutil import destruct, Struct
|
from pysollib.mfxutil import destruct, Struct
|
||||||
from pysollib.mfxutil import pickle, unpickle, UnpicklingError
|
from pysollib.mfxutil import pickle, unpickle, UnpicklingError
|
||||||
from pysollib.mfxutil import getusername, getprefdir
|
from pysollib.mfxutil import getusername, getprefdir
|
||||||
from pysollib.mfxutil import latin1_to_ascii, print_err
|
from pysollib.mfxutil import latin1_normalize, print_err
|
||||||
from pysollib.mfxutil import USE_PIL
|
from pysollib.mfxutil import USE_PIL
|
||||||
from pysollib.util import CARDSET, IMAGE_EXTENSIONS
|
from pysollib.util import CARDSET, IMAGE_EXTENSIONS
|
||||||
from pysollib.settings import PACKAGE, VERSION_TUPLE, WIN_SYSTEM
|
from pysollib.settings import PACKAGE, VERSION_TUPLE, WIN_SYSTEM
|
||||||
|
@ -1257,16 +1257,13 @@ Please select a %s type %s.
|
||||||
return None
|
return None
|
||||||
return gi.short_name
|
return gi.short_name
|
||||||
|
|
||||||
def _calcGameFn(self, n):
|
|
||||||
return re.sub(r"[^\w]", "", latin1_to_ascii(n).lower())
|
|
||||||
|
|
||||||
def getGameRulesFilename(self, id):
|
def getGameRulesFilename(self, id):
|
||||||
gi = self.gdb.get(id)
|
gi = self.gdb.get(id)
|
||||||
if gi is None:
|
if gi is None:
|
||||||
return None
|
return None
|
||||||
if gi.rules_filename is not None:
|
if gi.rules_filename is not None:
|
||||||
return gi.rules_filename
|
return gi.rules_filename
|
||||||
n = self._calcGameFn(gi.en_name) + '.html' # english name
|
n = latin1_normalize(gi.en_name) + '.html' # english name
|
||||||
f = os.path.join(self.dataloader.dir, "html", "rules", n)
|
f = os.path.join(self.dataloader.dir, "html", "rules", n)
|
||||||
if not os.path.exists(f):
|
if not os.path.exists(f):
|
||||||
n = ''
|
n = ''
|
||||||
|
@ -1279,7 +1276,7 @@ Please select a %s type %s.
|
||||||
n = self.gdb.get(id).en_name # english name
|
n = self.gdb.get(id).en_name # english name
|
||||||
if not n:
|
if not n:
|
||||||
return None
|
return None
|
||||||
return re.sub(r"[\s]", "_", self._calcGameFn(n))
|
return re.sub(r"[\s]", "_", latin1_normalize(n))
|
||||||
|
|
||||||
def getRandomGameId(self, games=None):
|
def getRandomGameId(self, games=None):
|
||||||
if games is None:
|
if games is None:
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
# ---------------------------------------------------------------------------##
|
# ---------------------------------------------------------------------------##
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
@ -79,13 +80,16 @@ def latin1_to_ascii(n):
|
||||||
# return n
|
# return n
|
||||||
n = n.encode('iso8859-1', 'replace')
|
n = n.encode('iso8859-1', 'replace')
|
||||||
# FIXME: rewrite this for better speed
|
# FIXME: rewrite this for better speed
|
||||||
n = (n.replace("\xc4", "Ae")
|
return (n.replace("\xc4", "Ae")
|
||||||
.replace("\xd6", "Oe")
|
.replace("\xd6", "Oe")
|
||||||
.replace("\xdc", "Ue")
|
.replace("\xdc", "Ue")
|
||||||
.replace("\xe4", "ae")
|
.replace("\xe4", "ae")
|
||||||
.replace("\xf6", "oe")
|
.replace("\xf6", "oe")
|
||||||
.replace("\xfc", "ue"))
|
.replace("\xfc", "ue"))
|
||||||
return n
|
|
||||||
|
|
||||||
|
def latin1_normalize(n):
|
||||||
|
return re.sub(r"[^\w]", "", latin1_to_ascii(n).lower())
|
||||||
|
|
||||||
|
|
||||||
def format_time(t):
|
def format_time(t):
|
||||||
|
|
|
@ -58,7 +58,6 @@ class Resource(Struct):
|
||||||
|
|
||||||
def getSortKey(self):
|
def getSortKey(self):
|
||||||
return self.name.lower()
|
return self.name.lower()
|
||||||
# return latin1_to_ascii(self.name).lower()
|
|
||||||
|
|
||||||
|
|
||||||
class ResourceManager:
|
class ResourceManager:
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import time
|
import time
|
||||||
# from pprint import pprint
|
# from pprint import pprint
|
||||||
import __builtin__
|
import __builtin__
|
||||||
|
@ -34,11 +33,7 @@ fix_gettext()
|
||||||
def getGameRulesFilename(n):
|
def getGameRulesFilename(n):
|
||||||
if n.startswith('Mahjongg'):
|
if n.startswith('Mahjongg'):
|
||||||
return 'mahjongg.html'
|
return 'mahjongg.html'
|
||||||
# n = re.sub(r"[\[\(].*$", "", n)
|
return latin1_normalize(n) + '.html'
|
||||||
n = latin1_to_ascii(n)
|
|
||||||
n = re.sub(r"[^\w]", "", n)
|
|
||||||
n = n.lower() + ".html"
|
|
||||||
return n
|
|
||||||
|
|
||||||
|
|
||||||
GAME_BY_TYPE = {
|
GAME_BY_TYPE = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue