diff --git a/scripts/all_games.py b/scripts/all_games.py index 4a317442..b87cad2f 100755 --- a/scripts/all_games.py +++ b/scripts/all_games.py @@ -2,23 +2,13 @@ # -*- mode: python; coding: koi8-r; -*- # -import sys, os, re, time -from pprint import pprint - -os.environ['LANG'] = 'C' +import sys +import os +import re +import time +# from pprint import pprint import __builtin__ -__builtin__.__dict__['_'] = lambda x: x -__builtin__.__dict__['n_'] = lambda x: x - -pysollib_path = os.path.join(sys.path[0], '..') -sys.path[0] = os.path.normpath(pysollib_path) -rules_dir = os.path.normpath(os.path.join(pysollib_path, 'data/html/rules')) -#pprint(sys.path) -#print rules_dir - from pysollib.mygettext import fix_gettext -fix_gettext() - import pysollib.games import pysollib.games.special import pysollib.games.ultra @@ -28,15 +18,29 @@ from pysollib.gamedb import GAME_DB from pysollib.gamedb import GI from pysollib.mfxutil import latin1_to_ascii from pysollib.resource import CSI +os.environ['LANG'] = 'C' +__builtin__.__dict__['_'] = lambda x: x +__builtin__.__dict__['n_'] = lambda x: x + +pysollib_path = os.path.join(sys.path[0], '..') +sys.path[0] = os.path.normpath(pysollib_path) +rules_dir = os.path.normpath(os.path.join(pysollib_path, 'data/html/rules')) +# pprint(sys.path) +# print rules_dir + +fix_gettext() + def getGameRulesFilename(n): - if n.startswith('Mahjongg'): return 'mahjongg.html' - ##n = re.sub(r"[\[\(].*$", "", n) + if n.startswith('Mahjongg'): + return 'mahjongg.html' + # n = re.sub(r"[\[\(].*$", "", n) n = latin1_to_ascii(n) n = re.sub(r"[^\w]", "", n) n = n.lower() + ".html" return n + GAME_BY_TYPE = { GI.GT_BAKERS_DOZEN: "Baker's Dozen", GI.GT_BELEAGUERED_CASTLE: "Beleaguered Castle", @@ -70,63 +74,66 @@ GAME_BY_TYPE = { GI.GT_HANAFUDA: "Hanafuda", GI.GT_DASHAVATARA_GANJIFA: "Dashavatara Ganjifa", GI.GT_MAHJONGG: "Mahjongg", - GI.GT_MUGHAL_GANJIFA:"Mughal Ganjifa", - GI.GT_SHISEN_SHO:"Shisen-Sho", + GI.GT_MUGHAL_GANJIFA: "Mughal Ganjifa", + GI.GT_SHISEN_SHO: "Shisen-Sho", } + def by_category(): games = GAME_DB.getGamesIdSortedById() games_by_cat = {} for id in games: gi = GAME_DB.get(id) gt = CSI.TYPE_NAME[gi.category] - if games_by_cat.has_key(gt): + if gt in games_by_cat: games_by_cat[gt] += 1 else: games_by_cat[gt] = 1 games_by_cat_list = [(i, j) for i, j in games_by_cat.items()] - games_by_cat_list.sort(lambda i, j: cmp(j[1], i[1])) + games_by_cat_list.sort(key=lambda x: x[1]) # print '' # for i in games_by_cat_list: # print '' % i # print '
NameNumber
%s%s
' - print '') return + def by_type(): games = GAME_DB.getGamesIdSortedById() games_by_type = {} for id in games: gi = GAME_DB.get(id) - if not GAME_BY_TYPE.has_key(gi.si.game_type): - print gi.si.game_type + if gi.si.game_type not in GAME_BY_TYPE: + print(gi.si.game_type) continue gt = GAME_BY_TYPE[gi.si.game_type] - if games_by_type.has_key(gt): + if gt in games_by_type: games_by_type[gt] += 1 else: games_by_type[gt] = 1 games_by_type_list = games_by_type.items() - games_by_type_list.sort(lambda i, j: cmp(i[0], j[0])) -## print '' -## for i in games_by_type_list: -## print '' % i -## print '
NameNumber
%s%s
' - print '') return + def all_games(sort_by='id'): - #rules_dir = 'rules' - print ''' + # rules_dir = 'rules' + print('''
-''' +''') if sort_by == 'id': get_games_func = GAME_DB.getGamesIdSortedById @@ -146,38 +153,39 @@ def all_games(sort_by='id'): altnames = '
'.join(gi.altnames).encode('utf-8') fn = os.path.join(rules_dir, rules_fn) if 1 and os.path.exists(fn): - print ''' -''' % (id, fn, name, altnames, gt) +''' % (id, fn, name, altnames, gt)) else: - print ''' -''' % (id, name, altnames, gt) - print '
IDNameAlternate namesType
%s + print('''
%s %s %s%s
%s%s%s%s
' + print('''%s%s%s%s +''' % (id, name, altnames, gt)) + print('') + def create_html(sort_by): - print ''' + print(''' PySolFC - List of solitaire games -''' - print 'Total games: %d' % len(GAME_DB.getGamesIdSortedById()) - print '

Categories

' +''') + print('Total games: %d' % len(GAME_DB.getGamesIdSortedById())) + print('

Categories

') by_category() - print '

Types

' + print('

Types

') by_type() - #print '

All games

' + # print '

All games

' all_games(sort_by) - print '' + print('') def get_text(): - #get_games_func = GAME_DB.getGamesIdSortedById + # get_games_func = GAME_DB.getGamesIdSortedById get_games_func = GAME_DB.getGamesIdSortedByName - games_list = {} # for unique + games_list = {} # for unique for id in get_games_func(): gi = GAME_DB.get(id) games_list[gi.name] = '' @@ -187,7 +195,7 @@ def get_text(): games_list[n] = '' games_list = games_list.keys() games_list.sort() - print '''\ + print('''\ # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR ORGANIZATION # FIRST AUTHOR , YEAR. @@ -204,44 +212,46 @@ msgstr "" "Content-Transfer-Encoding: ENCODING\\n" "Generated-By: %s 0.1\\n" -''' % (time.asctime(), sys.argv[0]) +''' % (time.asctime(), sys.argv[0])) for g in games_list: - print 'msgid "%s"\nmsgstr ""\n' % g.encode('utf-8') + print('msgid "%s"\nmsgstr ""\n' % g.encode('utf-8')) + def old_plain_text(): - #get_games_func = GAME_DB.getGamesIdSortedById + # get_games_func = GAME_DB.getGamesIdSortedById get_games_func = GAME_DB.getGamesIdSortedByName - games_list = {} # for unique + games_list = {} # for unique for id in get_games_func(): gi = GAME_DB.get(id) games_list[gi.name] = '' - #if gi.name != gi.short_name: + # if gi.name != gi.short_name: # games_list[gi.short_name] = '' for n in gi.altnames: games_list[n] = '' games_list = games_list.keys() games_list.sort() for g in games_list: - print g.encode('utf-8') + print(g.encode('utf-8')) + def plain_text(): get_games_func = GAME_DB.getGamesIdSortedByName for id in get_games_func(): gi = GAME_DB.get(id) if gi.category == GI.GC_FRENCH: - ##print str(gi.gameclass) - ##gc = gi.gameclass - ##h = gc.Hint_Class is None and 'None' or gc.Hint_Class.__name__ - ##print gi.name.encode('utf-8'), h - print gi.name.encode('utf-8') + # print str(gi.gameclass) + # gc = gi.gameclass + # h = gc.Hint_Class is None and 'None' or gc.Hint_Class.__name__ + # print gi.name.encode('utf-8'), h + print(gi.name.encode('utf-8')) for n in gi.altnames: - print n.encode('utf-8') - ##name = gi.name.lower() - ##name = re.sub('\W', '', name) - ##print id, name #, gi.si.game_type, gi.si.game_type == GI.GC_FRENCH + print(n.encode('utf-8')) + # name = gi.name.lower() + # name = re.sub('\W', '', name) + # print id, name #, gi.si.game_type, + # gi.si.game_type == GI.GC_FRENCH -## if len(sys.argv) < 2 or sys.argv[1] == 'html': sort_by = 'id' if len(sys.argv) > 2: @@ -255,6 +265,3 @@ elif sys.argv[1] == 'text': plain_text() else: sys.exit('invalid argument') - - - diff --git a/scripts/cardset_viewer.py b/scripts/cardset_viewer.py index 741961fa..803e6dcf 100755 --- a/scripts/cardset_viewer.py +++ b/scripts/cardset_viewer.py @@ -2,10 +2,14 @@ # -*- mode: python; coding: koi8-r; -*- # -import sys, os +import sys +import os from glob import glob from math import sqrt, sin, cos, pi -from Tkinter import * +from Tkinter import BOTH, Button, Frame, PhotoImage, NW, Text, Toplevel, X, YES +from Tkinter import RIGHT, Tk, Listbox, NS, END, Scrollbar, Canvas, NSEW +from Tkinter import HORIZONTAL, Label, EW, IntVar, StringVar, LEFT, Checkbutton +from Tkinter import OptionMenu try: from PIL import Image, ImageTk except ImportError: @@ -25,9 +29,12 @@ cardset_type = { all_imgs = False + class Cardset: def __init__(self, dir, name, type, ext, x, y): - self.dir, self.name, self.type, self.ext, self.x, self.y = dir, name, type, ext, x, y + self.dir, self.name, self.type, self.ext, self.x, self.y = \ + dir, name, type, ext, x, y + def create_cs_list(ls): cardsets_list = {} @@ -38,12 +45,12 @@ def create_cs_list(ls): try: ext = l0[2] except IndexError: - ##print f + # print f ext = '.gif' if len(l0) > 3: type = cardset_type[l0[3]] else: - #type = 'Unknown' + # type = 'Unknown' type = 'French' l1 = lines[1].split(';') name = l1[1].strip() @@ -53,8 +60,11 @@ def create_cs_list(ls): cardsets_list[name] = cs return cardsets_list + tk_images = [] zoom = 0 + + def show_cardset(*args): global tk_images tk_images = [] @@ -66,10 +76,9 @@ def show_cardset(*args): if all_imgs: ls += glob(os.path.join(cs.dir, 'bottom*'+cs.ext)) ls += glob(os.path.join(cs.dir, 'l*'+cs.ext)) - #ls = glob(os.path.join(cs.dir, '*.gif')) - ##if not ls: return + # ls = glob(os.path.join(cs.dir, '*.gif')) + # if not ls: return ls.sort() - n = 0 pf = None x, y = 10, 10 width, height = 0, 0 @@ -77,28 +86,28 @@ def show_cardset(*args): for f in ls: if Image: filter = { - 'NEAREST' : Image.NEAREST, - 'BILINEAR' : Image.BILINEAR, - 'BICUBIC' : Image.BICUBIC, + 'NEAREST': Image.NEAREST, + 'BILINEAR': Image.BILINEAR, + 'BICUBIC': Image.BICUBIC, 'ANTIALIAS': Image.ANTIALIAS, - } [filter_var.get()] - ##filter = Image.BILINEAR - ##filter = Image.BICUBIC - ##filter = Image.ANTIALIAS - ##print f + }[filter_var.get()] + # filter = Image.BILINEAR + # filter = Image.BICUBIC + # filter = Image.ANTIALIAS + # print f im = Image.open(f) if zoom != 0: w, h = im.size im = im.convert('RGBA') # for save transparency if rotate_var.get(): # rotate - #if filter == Image.ANTIALIAS: + # if filter == Image.ANTIALIAS: # filter = Image.BICUBIC z = zoom*5 a = abs(pi/2/90*z) neww = int(w*cos(a)+h*sin(a)) newh = int(h*cos(a)+w*sin(a)) - ##print w, h, neww, newh + # print w, h, neww, newh d = int(sqrt(w*w+h*h)) dx, dy = (d-w)/2, (d-h)/2 newim = Image.new('RGBA', (d, d)) @@ -115,10 +124,12 @@ def show_cardset(*args): z = max(0.2, z) if 1: tmp = Image.new('RGBA', (w+2, h+2)) - tmp.paste(im, (1,1), im) - im = tmp.resize((int(w*z), int(h*z)), resample=filter) + tmp.paste(im, (1, 1), im) + im = tmp.resize((int(w*z), int(h*z)), + resample=filter) else: - im = im.resize((int(w*z), int(h*z)), resample=filter) + im = im.resize((int(w*z), int(h*z)), + resample=filter) t = '%d %%' % int(z*100) zoom_label.config(text=t) @@ -140,32 +151,36 @@ def show_cardset(*args): else: x += image.width()+10 canvas.create_image(x, y, image=image, anchor=NW) - ##canvas.create_rectangle(x, y, x+image.width(), y+image.height()) + # canvas.create_rectangle(x, y, x+image.width(), y+image.height()) width = max(width, x) height = max(height, y) width, height = width+image.width()+10, height+image.height()+10 canvas.config(scrollregion=(0, 0, width, height)) - ##print image.width(), image.height() + # print image.width(), image.height() label.config(text='''\ Name: %s Type: %s Directory: %s''' % (cs.name, cs.type, cs.dir)) + def zoom_in(*args): global zoom zoom += 1 show_cardset() + def zoom_out(*args): global zoom zoom -= 1 show_cardset() + def zoom_cancel(*args): global zoom zoom = 0 show_cardset() + def show_info(*args): if list_box.curselection(): cs_name = list_box.get(list_box.curselection()) @@ -180,6 +195,7 @@ def show_info(*args): button = Button(b_frame, text='Close', command=top.destroy) button.pack(side=RIGHT) + def create_widgets(): global list_box, canvas, label, zoom_label # @@ -253,6 +269,7 @@ def create_widgets(): return root + if __name__ == '__main__': if '-a' in sys.argv: sys.argv.remove('-a') @@ -260,7 +277,8 @@ if __name__ == '__main__': if len(sys.argv) > 1: data_dir = sys.argv[1] else: - data_dir = os.path.normpath(os.path.join(sys.path[0], os.pardir, 'data')) + data_dir = os.path.normpath( + os.path.join(sys.path[0], os.pardir, 'data')) ls = glob(os.path.join(data_dir, '*', 'config.txt')) cardsets_dict = create_cs_list(ls) root = create_widgets() diff --git a/scripts/create_iss.py b/scripts/create_iss.py index ed6292e0..c7a0d959 100755 --- a/scripts/create_iss.py +++ b/scripts/create_iss.py @@ -1,8 +1,15 @@ #!/usr/bin/env python +import os +import pysollib.settings +import sys + +if sys.version_info > (3,): + def execfile(fn): + return exec(open(fn).read()) + prog_name = 'PySol Fan Club edition' -import os dirs_list = [] files_list = [] @@ -11,8 +18,7 @@ for root, dirs, files in os.walk('dist'): files_list.append(root) dirs_list.append(root) -execfile(os.path.join('pysollib', 'settings.py')) -prog_version = VERSION +prog_version = pysollib.settings.VERSION out = open('setup.iss', 'w') @@ -45,5 +51,3 @@ print >> out, 'Source: "*"; DestDir: "{app}"' for d in files_list[1:]: d = d.replace('dist\\', '') print >> out, 'Source: "%s\\*"; DestDir: "{app}\\%s"' % (d, d) - - diff --git a/scripts/gen_individual_importing_tests.py b/scripts/gen_individual_importing_tests.py index 68dd7428..40194a73 100644 --- a/scripts/gen_individual_importing_tests.py +++ b/scripts/gen_individual_importing_tests.py @@ -1,202 +1,203 @@ #!/usr/bin/env python import os.path -for module_name in [ -'pysollib.acard', -'pysollib.actions', -'pysollib.app', -'pysollib.configobj.configobj', -'pysollib.configobj.validate', -'pysollib.customgame', -'pysollib.game', -'pysollib.gamedb', -'pysollib.games.acesup', -'pysollib.games.algerian', -'pysollib.games.auldlangsyne', -'pysollib.games.bakersdozen', -'pysollib.games.bakersgame', -'pysollib.games.beleagueredcastle', -'pysollib.games.bisley', -'pysollib.games.braid', -'pysollib.games.bristol', -'pysollib.games.buffalobill', -'pysollib.games.calculation', -'pysollib.games.camelot', -'pysollib.games.canfield', -'pysollib.games.capricieuse', -'pysollib.games.curdsandwhey', -'pysollib.games.dieboesesieben', -'pysollib.games.diplomat', -'pysollib.games.doublets', -'pysollib.games.eiffeltower', -'pysollib.games.fan', -'pysollib.games.fortythieves', -'pysollib.games.freecell', -'pysollib.games.glenwood', -'pysollib.games.golf', -'pysollib.games.grandduchess', -'pysollib.games.grandfathersclock', -'pysollib.games.gypsy', -'pysollib.games.harp', -'pysollib.games.headsandtails', -'pysollib.games.katzenschwanz', -'pysollib.games.klondike', -'pysollib.games.labyrinth', -'pysollib.games.larasgame', -'pysollib.games.mahjongg.mahjongg', -'pysollib.games.mahjongg.mahjongg1', -'pysollib.games.mahjongg.mahjongg2', -'pysollib.games.mahjongg.mahjongg3', -'pysollib.games.mahjongg.shisensho', -'pysollib.games.matriarchy', -'pysollib.games.montana', -'pysollib.games.montecarlo', -'pysollib.games.napoleon', -'pysollib.games.needle', -'pysollib.games.numerica', -'pysollib.games.osmosis', -'pysollib.games.parallels', -'pysollib.games.pasdedeux', -'pysollib.games.picturegallery', -'pysollib.games.pileon', -'pysollib.games.pushpin', -'pysollib.games.pyramid', -'pysollib.games.royalcotillion', -'pysollib.games.royaleast', -'pysollib.games.sanibel', -'pysollib.games.siebenbisas', -'pysollib.games.simplex', -'pysollib.games.special.hanoi', -'pysollib.games.special.memory', -'pysollib.games.special.pegged', -'pysollib.games.special.poker', -'pysollib.games.special.tarock', -'pysollib.games.spider', -'pysollib.games.sthelena', -'pysollib.games.sultan', -'pysollib.games.takeaway', -'pysollib.games.terrace', -'pysollib.games.threepeaks', -'pysollib.games.tournament', -'pysollib.games.ultra.dashavatara', -'pysollib.games.ultra.hanafuda', -'pysollib.games.ultra.hanafuda1', -'pysollib.games.ultra.hanafuda_common', -'pysollib.games.ultra.hexadeck', -'pysollib.games.ultra.larasgame', -'pysollib.games.ultra.matrix', -'pysollib.games.ultra.mughal', -'pysollib.games.ultra.tarock', -'pysollib.games.unionsquare', -'pysollib.games.wavemotion', -'pysollib.games.windmill', -'pysollib.games.yukon', -'pysollib.games.zodiac', -'pysollib.help', -'pysollib.hint', -'pysollib.images', -'pysollib.init', -'pysollib.layout', -'pysollib.macosx.appSupport', -'pysollib.main', -'pysollib.mfxutil', -'pysollib.move', -'pysollib.mygettext', -'pysollib.options', -'pysollib.pysolaudio', -'pysollib.pysolgtk.card', -'pysollib.pysolgtk.colorsdialog', -'pysollib.pysolgtk.edittextdialog', -'pysollib.pysolgtk.findcarddialog', -'pysollib.pysolgtk.fontsdialog', -'pysollib.pysolgtk.gameinfodialog', -'pysollib.pysolgtk.menubar', -'pysollib.pysolgtk.playeroptionsdialog', -'pysollib.pysolgtk.progressbar', -'pysollib.pysolgtk.pysoltree', -'pysollib.pysolgtk.selectcardset', -'pysollib.pysolgtk.selectgame', -'pysollib.pysolgtk.selecttile', -'pysollib.pysolgtk.soundoptionsdialog', -'pysollib.pysolgtk.statusbar', -'pysollib.pysolgtk.timeoutsdialog', -'pysollib.pysolgtk.tkcanvas', -'pysollib.pysolgtk.tkconst', -'pysollib.pysolgtk.tkhtml', -'pysollib.pysolgtk.tkstats', -'pysollib.pysolgtk.tkutil', -'pysollib.pysolgtk.tkwidget', -'pysollib.pysolgtk.tkwrap', -'pysollib.pysolgtk.toolbar', -'pysollib.pysolrandom', -'pysollib.pysoltk', -'pysollib.resource', -'pysollib.settings', -'pysollib.stack', -'pysollib.stats', -'pysollib.tile.basetilemfxdialog', -'pysollib.tile.colorsdialog', -'pysollib.tile.edittextdialog', -'pysollib.tile.fontsdialog', -'pysollib.tile.gameinfodialog', -'pysollib.tile.menubar', -'pysollib.tile.playeroptionsdialog', -'pysollib.tile.progressbar', -'pysollib.tile.selectcardset', -'pysollib.tile.selectgame', -'pysollib.tile.selecttile', -'pysollib.tile.selecttree', -'pysollib.tile.solverdialog', -'pysollib.tile.soundoptionsdialog', -'pysollib.tile.statusbar', -'pysollib.tile.timeoutsdialog', -'pysollib.tile.tkhtml', -'pysollib.tile.tkstats', -'pysollib.tile.tktree', -'pysollib.tile.tkwidget', -'pysollib.tile.toolbar', -'pysollib.tile.ttk', -'pysollib.tile.wizarddialog', -'pysollib.tk.colorsdialog', -'pysollib.tk.edittextdialog', -'pysollib.tk.fontsdialog', -'pysollib.tk.gameinfodialog', -'pysollib.tk.menubar', -'pysollib.tk.playeroptionsdialog', -'pysollib.tk.progressbar', -'pysollib.tk.selectcardset', -'pysollib.tk.selectgame', -'pysollib.tk.selecttile', -'pysollib.tk.selecttree', -'pysollib.tk.solverdialog', -'pysollib.tk.soundoptionsdialog', -'pysollib.tk.statusbar', -'pysollib.tk.tabpage', -'pysollib.tk.timeoutsdialog', -'pysollib.tk.tkhtml', -'pysollib.tk.tkstats', -'pysollib.tk.tktree', -'pysollib.tk.tkwidget', -'pysollib.tk.toolbar', -'pysollib.tk.wizarddialog', -'pysollib.ui.tktile.card', -'pysollib.ui.tktile.colorsdialog', -'pysollib.ui.tktile.edittextdialog', -'pysollib.ui.tktile.findcarddialog', -'pysollib.ui.tktile.menubar', -'pysollib.ui.tktile.solverdialog', -'pysollib.ui.tktile.tkcanvas', -'pysollib.ui.tktile.tkconst', -'pysollib.ui.tktile.tkhtml', -'pysollib.ui.tktile.tkutil', -'pysollib.ui.tktile.tkwrap', -'pysollib.util', -'pysollib.winsystems.aqua', -'pysollib.winsystems.common', -'pysollib.winsystems.win32', -'pysollib.winsystems.x11', -'pysollib.wizardpresets', -'pysollib.wizardutil', -]: +for module_name in \ + [ + 'pysollib.acard', + 'pysollib.actions', + 'pysollib.app', + 'pysollib.configobj.configobj', + 'pysollib.configobj.validate', + 'pysollib.customgame', + 'pysollib.game', + 'pysollib.gamedb', + 'pysollib.games.acesup', + 'pysollib.games.algerian', + 'pysollib.games.auldlangsyne', + 'pysollib.games.bakersdozen', + 'pysollib.games.bakersgame', + 'pysollib.games.beleagueredcastle', + 'pysollib.games.bisley', + 'pysollib.games.braid', + 'pysollib.games.bristol', + 'pysollib.games.buffalobill', + 'pysollib.games.calculation', + 'pysollib.games.camelot', + 'pysollib.games.canfield', + 'pysollib.games.capricieuse', + 'pysollib.games.curdsandwhey', + 'pysollib.games.dieboesesieben', + 'pysollib.games.diplomat', + 'pysollib.games.doublets', + 'pysollib.games.eiffeltower', + 'pysollib.games.fan', + 'pysollib.games.fortythieves', + 'pysollib.games.freecell', + 'pysollib.games.glenwood', + 'pysollib.games.golf', + 'pysollib.games.grandduchess', + 'pysollib.games.grandfathersclock', + 'pysollib.games.gypsy', + 'pysollib.games.harp', + 'pysollib.games.headsandtails', + 'pysollib.games.katzenschwanz', + 'pysollib.games.klondike', + 'pysollib.games.labyrinth', + 'pysollib.games.larasgame', + 'pysollib.games.mahjongg.mahjongg', + 'pysollib.games.mahjongg.mahjongg1', + 'pysollib.games.mahjongg.mahjongg2', + 'pysollib.games.mahjongg.mahjongg3', + 'pysollib.games.mahjongg.shisensho', + 'pysollib.games.matriarchy', + 'pysollib.games.montana', + 'pysollib.games.montecarlo', + 'pysollib.games.napoleon', + 'pysollib.games.needle', + 'pysollib.games.numerica', + 'pysollib.games.osmosis', + 'pysollib.games.parallels', + 'pysollib.games.pasdedeux', + 'pysollib.games.picturegallery', + 'pysollib.games.pileon', + 'pysollib.games.pushpin', + 'pysollib.games.pyramid', + 'pysollib.games.royalcotillion', + 'pysollib.games.royaleast', + 'pysollib.games.sanibel', + 'pysollib.games.siebenbisas', + 'pysollib.games.simplex', + 'pysollib.games.special.hanoi', + 'pysollib.games.special.memory', + 'pysollib.games.special.pegged', + 'pysollib.games.special.poker', + 'pysollib.games.special.tarock', + 'pysollib.games.spider', + 'pysollib.games.sthelena', + 'pysollib.games.sultan', + 'pysollib.games.takeaway', + 'pysollib.games.terrace', + 'pysollib.games.threepeaks', + 'pysollib.games.tournament', + 'pysollib.games.ultra.dashavatara', + 'pysollib.games.ultra.hanafuda', + 'pysollib.games.ultra.hanafuda1', + 'pysollib.games.ultra.hanafuda_common', + 'pysollib.games.ultra.hexadeck', + 'pysollib.games.ultra.larasgame', + 'pysollib.games.ultra.matrix', + 'pysollib.games.ultra.mughal', + 'pysollib.games.ultra.tarock', + 'pysollib.games.unionsquare', + 'pysollib.games.wavemotion', + 'pysollib.games.windmill', + 'pysollib.games.yukon', + 'pysollib.games.zodiac', + 'pysollib.help', + 'pysollib.hint', + 'pysollib.images', + 'pysollib.init', + 'pysollib.layout', + 'pysollib.macosx.appSupport', + 'pysollib.main', + 'pysollib.mfxutil', + 'pysollib.move', + 'pysollib.mygettext', + 'pysollib.options', + 'pysollib.pysolaudio', + 'pysollib.pysolgtk.card', + 'pysollib.pysolgtk.colorsdialog', + 'pysollib.pysolgtk.edittextdialog', + 'pysollib.pysolgtk.findcarddialog', + 'pysollib.pysolgtk.fontsdialog', + 'pysollib.pysolgtk.gameinfodialog', + 'pysollib.pysolgtk.menubar', + 'pysollib.pysolgtk.playeroptionsdialog', + 'pysollib.pysolgtk.progressbar', + 'pysollib.pysolgtk.pysoltree', + 'pysollib.pysolgtk.selectcardset', + 'pysollib.pysolgtk.selectgame', + 'pysollib.pysolgtk.selecttile', + 'pysollib.pysolgtk.soundoptionsdialog', + 'pysollib.pysolgtk.statusbar', + 'pysollib.pysolgtk.timeoutsdialog', + 'pysollib.pysolgtk.tkcanvas', + 'pysollib.pysolgtk.tkconst', + 'pysollib.pysolgtk.tkhtml', + 'pysollib.pysolgtk.tkstats', + 'pysollib.pysolgtk.tkutil', + 'pysollib.pysolgtk.tkwidget', + 'pysollib.pysolgtk.tkwrap', + 'pysollib.pysolgtk.toolbar', + 'pysollib.pysolrandom', + 'pysollib.pysoltk', + 'pysollib.resource', + 'pysollib.settings', + 'pysollib.stack', + 'pysollib.stats', + 'pysollib.tile.basetilemfxdialog', + 'pysollib.tile.colorsdialog', + 'pysollib.tile.edittextdialog', + 'pysollib.tile.fontsdialog', + 'pysollib.tile.gameinfodialog', + 'pysollib.tile.menubar', + 'pysollib.tile.playeroptionsdialog', + 'pysollib.tile.progressbar', + 'pysollib.tile.selectcardset', + 'pysollib.tile.selectgame', + 'pysollib.tile.selecttile', + 'pysollib.tile.selecttree', + 'pysollib.tile.solverdialog', + 'pysollib.tile.soundoptionsdialog', + 'pysollib.tile.statusbar', + 'pysollib.tile.timeoutsdialog', + 'pysollib.tile.tkhtml', + 'pysollib.tile.tkstats', + 'pysollib.tile.tktree', + 'pysollib.tile.tkwidget', + 'pysollib.tile.toolbar', + 'pysollib.tile.ttk', + 'pysollib.tile.wizarddialog', + 'pysollib.tk.colorsdialog', + 'pysollib.tk.edittextdialog', + 'pysollib.tk.fontsdialog', + 'pysollib.tk.gameinfodialog', + 'pysollib.tk.menubar', + 'pysollib.tk.playeroptionsdialog', + 'pysollib.tk.progressbar', + 'pysollib.tk.selectcardset', + 'pysollib.tk.selectgame', + 'pysollib.tk.selecttile', + 'pysollib.tk.selecttree', + 'pysollib.tk.solverdialog', + 'pysollib.tk.soundoptionsdialog', + 'pysollib.tk.statusbar', + 'pysollib.tk.tabpage', + 'pysollib.tk.timeoutsdialog', + 'pysollib.tk.tkhtml', + 'pysollib.tk.tkstats', + 'pysollib.tk.tktree', + 'pysollib.tk.tkwidget', + 'pysollib.tk.toolbar', + 'pysollib.tk.wizarddialog', + 'pysollib.ui.tktile.card', + 'pysollib.ui.tktile.colorsdialog', + 'pysollib.ui.tktile.edittextdialog', + 'pysollib.ui.tktile.findcarddialog', + 'pysollib.ui.tktile.menubar', + 'pysollib.ui.tktile.solverdialog', + 'pysollib.ui.tktile.tkcanvas', + 'pysollib.ui.tktile.tkconst', + 'pysollib.ui.tktile.tkhtml', + 'pysollib.ui.tktile.tkutil', + 'pysollib.ui.tktile.tkwrap', + 'pysollib.util', + 'pysollib.winsystems.aqua', + 'pysollib.winsystems.common', + 'pysollib.winsystems.win32', + 'pysollib.winsystems.x11', + 'pysollib.wizardpresets', + 'pysollib.wizardutil', + ]: open(os.path.join(".", "tests", "individually-importing", "import_" + module_name + ".py"), 'w').write('''#!/usr/bin/env python import sys sys.path.append("./tests/lib") @@ -206,4 +207,4 @@ plan(1) sys.path.insert(0, ".") import %(module_name)s ok(1, "imported") -''' % { 'module_name': module_name }) +''' % {'module_name': module_name}) diff --git a/scripts/mahjongg_utils.py b/scripts/mahjongg_utils.py index 8aeefba2..d5c050c2 100755 --- a/scripts/mahjongg_utils.py +++ b/scripts/mahjongg_utils.py @@ -1,10 +1,12 @@ #!/usr/bin/env python # -*- mode: python; coding: utf-8; -*- -import sys, os, re +import sys +import os alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + def decode_layout(layout): # decode tile positions assert layout[0] == "0" @@ -21,10 +23,11 @@ def decode_layout(layout): tiles.sort() return tiles + def encode_layout(layout): # encode positions s = '0' - ##layout.sort() + # layout.sort() x_max = max([t[1] for t in layout]) y_max = max([t[2] for t in layout]) for x in range(x_max+1): @@ -46,7 +49,6 @@ def encode_layout(layout): return s - def parse_kyodai(filename): # Kyodai (http://www.kyodai.com/) @@ -179,30 +181,29 @@ if __name__ == '__main__': layout = parse_func(filename) layout = normalize(layout) - #print filename, len(layout) + # print filename, len(layout) s = encode_layout(layout) # check lt = decode_layout(s) if lt != layout: - print '*** ERROR ***' + print('*** ERROR ***') else: - ##print s + # print s gamename = os.path.split(filename)[1].split('.')[0] - #classname = gamename.replace(' ', '_') - #classname = 'Mahjongg_' + re.sub('\W', '', classname) + # classname = gamename.replace(' ', '_') + # classname = 'Mahjongg_' + re.sub('\W', '', classname) ncards = len(layout) if ncards != 144: - print '''r(%d, "%s", ncards=%d, layout="%s") -''' % (gameid, gamename, ncards, s) + print('''r(%d, "%s", ncards=%d, layout="%s") +''' % (gameid, gamename, ncards, s)) else: - print '''r(%d, "%s", layout="%s") -''' % (gameid, gamename, s) + print('''r(%d, "%s", layout="%s") +''' % (gameid, gamename, s)) gameid += 1 - diff --git a/scripts/pygettext.py b/scripts/pygettext.py index 8d19413d..8e0860ab 100755 --- a/scripts/pygettext.py +++ b/scripts/pygettext.py @@ -16,12 +16,16 @@ # Added very simple support for ngettext # +import sys +import functools + # for selftesting try: import fintl _ = fintl.gettext except ImportError: - _ = lambda s: s + def _(s): + return s __doc__ = _("""pygettext -- Python equivalent of xgettext(1) @@ -160,7 +164,6 @@ If `inputfile' is -, standard input is read. import os import imp -import sys import glob import time import getopt @@ -168,6 +171,9 @@ import token import tokenize import operator +if sys.version_info > (3,): + basestring = str + __version__ = '1.6con' default_keywords = ['_'] @@ -176,8 +182,6 @@ default_ngettext_keywords = ['ngettext'] EMPTYSTRING = '' - - # The normal pot-file header. msgmerge and Emacs's po-mode work better if it's # there. pot_header = _('''\ @@ -207,9 +211,9 @@ def usage(code, msg=''): sys.exit(code) - escapes = [] + def make_escapes(pass_iso8859): global escapes if pass_iso8859: @@ -241,7 +245,7 @@ def escape(s): def safe_eval(s): # unwrap quotes, safely - return eval(s, {'__builtins__':{}}, {}) + return eval(s, {'__builtins__': {}}, {}) def normalize(s): @@ -269,7 +273,7 @@ def containsAny(str, set): def _visit_pyfiles(list, dirname, names): """Helper for getFilesForName().""" # get extension for python source files - if not globals().has_key('_py_ext'): + if '_py_ext' not in globals(): global _py_ext _py_ext = [triple[0] for triple in imp.get_suffixes() if triple[2] == imp.PY_SOURCE][0] @@ -299,7 +303,8 @@ def _get_modpkg_path(dotted_name, pathlist=None): # we have a dotted path, import top-level package try: file, pathname, description = imp.find_module(parts[0], pathlist) - if file: file.close() + if file: + file.close() except ImportError: return None @@ -367,9 +372,9 @@ class TokenEater: def __call__(self, ttype, tstring, stup, etup, line): # dispatch -# import token -# print >> sys.stderr, 'ttype:', token.tok_name[ttype], \ -# 'tstring:', tstring + # import token + # print >> sys.stderr, 'ttype:', token.tok_name[ttype], \ + # 'tstring:', tstring self.__state(ttype, tstring, stup[0]) def __waiting(self, ttype, tstring, lineno): @@ -435,11 +440,11 @@ class TokenEater: self.__addentry(tuple(data)) elif self.__options.verbose: print >> sys.stderr, _( - '*** %(file)s:%(lineno)s: incorrect ngettext format' + '*** %(file)s:%(lineno)s: incorrect ' + 'ngettext format' ) % { - 'file': self.__curfile, - 'lineno': self.__lineno - } + 'file': self.__curfile, + 'lineno': self.__lineno} else: self.__addentry(EMPTYSTRING.join(self.__data)) self.__state = self.__waiting @@ -449,13 +454,14 @@ class TokenEater: token.NEWLINE, tokenize.NL]: if self.__ngettext and ttype == tokenize.OP and tstring == ',': self.__data.append(None) - elif self.__ngettext: # and ttype == tokenize.NUMBER: + elif self.__ngettext: # and ttype == tokenize.NUMBER: pass else: # warn if we see anything else than STRING or whitespace if self.__options.verbose: print >> sys.stderr, _( - '*** %(file)s:%(lineno)s: Seen unexpected token "%(token)s"' + '*** %(file)s:%(lineno)s: Seen unexpected ' + 'token "%(token)s"' ) % { 'token': tstring, 'file': self.__curfile, @@ -466,7 +472,7 @@ class TokenEater: def __addentry(self, msg, lineno=None, isdocstring=0): if lineno is None: lineno = self.__lineno - if not msg in self.__options.toexclude: + if msg not in self.__options.toexclude: entry = (self.__curfile, lineno) self.__messages.setdefault(msg, {})[entry] = isdocstring @@ -497,7 +503,7 @@ class TokenEater: # If the entry was gleaned out of a docstring, then add a # comment stating so. This is to aid translators who may wish # to skip translating some unimportant docstrings. - if reduce(operator.__add__, v.values()): + if functools.reduce(operator.__add__, v.values()): isdocstring = 1 # k is the message string, v is a dictionary-set of (filename, # lineno) tuples. We want to sort the entries in v first by @@ -541,7 +547,6 @@ class TokenEater: print >> fp, 'msgstr[1] ""\n' - def main(): global default_keywords try: @@ -554,7 +559,7 @@ def main(): 'style=', 'verbose', 'version', 'width=', 'exclude-file=', 'docstrings', 'no-docstrings', ]) - except getopt.error, msg: + except getopt.error as msg: usage(1, msg) # for holding option values @@ -563,7 +568,7 @@ def main(): GNU = 1 SOLARIS = 2 # defaults - extractall = 0 # FIXME: currently this option has no effect at all. + extractall = 0 # FIXME: currently this option has no effect at all. escape = 0 keywords = [] ngettext_keywords = [] @@ -578,8 +583,8 @@ def main(): nodocstrings = {} options = Options() - locations = {'gnu' : options.GNU, - 'solaris' : options.SOLARIS, + locations = {'gnu': options.GNU, + 'solaris': options.SOLARIS, } # parse options @@ -615,7 +620,7 @@ def main(): elif opt in ('-v', '--verbose'): options.verbose = 1 elif opt in ('-V', '--version'): - print _('pygettext.py (xgettext for Python) %s') % __version__ + print(_('pygettext.py (xgettext for Python) %s') % __version__) sys.exit(0) elif opt in ('-w', '--width'): try: @@ -671,19 +676,19 @@ def main(): for filename in args: if filename == '-': if options.verbose: - print _('Reading standard input') + print(_('Reading standard input')) fp = sys.stdin closep = 0 else: if options.verbose: - print _('Working on %s') % filename + print(_('Working on %s') % filename) fp = open(filename) closep = 1 try: eater.set_filename(filename) try: tokenize.tokenize(fp.readline, eater) - except tokenize.TokenError, e: + except tokenize.TokenError as e: print >> sys.stderr, '%s: %s, line %d, column %d' % ( e[0], filename, e[1][0], e[1][1]) finally: diff --git a/tests/style/py-flake8.t b/tests/style/py-flake8.t index 4176e628..fddae8b2 100644 --- a/tests/style/py-flake8.t +++ b/tests/style/py-flake8.t @@ -20,13 +20,14 @@ my %skip = ./pysollib/games/special/__init__.py ./pysollib/games/ultra/__init__.py ./pysollib/pysoltk.py + ./scripts/all_games.py ./pysollib/tile/ttk.py ) ); # my $cmd = shell_quote( 'flake8', '.' ); my $cmd = shell_quote( 'flake8', - grep { not exists $skip{$_} } glob('*.py ./tests/board_gen/*.py ./pysollib/*.py ./pysollib/[cmgpuw]*/{*/*.py,*.py} ./pysollib/tile/*.py ./pysollib/ui/tktile/*.py') ); + grep { not exists $skip{$_} } glob('./*.py ./scripts/*.py ./tests/board_gen/*.py ./pysollib/*.py ./pysollib/[cmgpuw]*/{*/*.py,*.py} ./pysollib/tile/*.py ./pysollib/ui/tktile/*.py') ); # TEST eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." );