mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
flake8
This commit is contained in:
parent
0414047586
commit
27f23b2e88
7 changed files with 378 additions and 341 deletions
|
@ -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",
|
||||
|
@ -75,58 +79,61 @@ GAME_BY_TYPE = {
|
|||
|
||||
}
|
||||
|
||||
|
||||
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 '<table border="2"><tr><th>Name</th><th>Number</th></tr>'
|
||||
# for i in games_by_cat_list:
|
||||
# print '<tr><td>%s</td><td>%s</td></tr>' % i
|
||||
# print '</table>'
|
||||
print '<ul>'
|
||||
print('<ul>')
|
||||
for i in games_by_cat_list:
|
||||
print '<li>%s (%s games)</li>' % i
|
||||
print '</ul>'
|
||||
print('<li>%s (%s games)</li>' % i)
|
||||
print('</ul>')
|
||||
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 '<table border="2"><tr><th>Name</th><th>Number</th></tr>'
|
||||
## for i in games_by_type_list:
|
||||
## print '<tr><td>%s</td><td>%s</td></tr>' % i
|
||||
## print '</table>'
|
||||
print '<ul>'
|
||||
games_by_type_list.sort(key=lambda x: x[0])
|
||||
# print '<table border="2"><tr><th>Name</th><th>Number</th></tr>'
|
||||
# for i in games_by_type_list:
|
||||
# print '<tr><td>%s</td><td>%s</td></tr>' % i
|
||||
# print '</table>'
|
||||
print('<ul>')
|
||||
for i in games_by_type_list:
|
||||
print '<li>%s (%s games)</li>' % i
|
||||
print '</ul>'
|
||||
print('<li>%s (%s games)</li>' % i)
|
||||
print('</ul>')
|
||||
return
|
||||
|
||||
|
||||
def all_games(sort_by='id'):
|
||||
# rules_dir = 'rules'
|
||||
print '''<table border="2">
|
||||
print('''<table border="2">
|
||||
<tr><th>ID</th><th>Name</th><th>Alternate names</th><th>Type</th></tr>
|
||||
'''
|
||||
''')
|
||||
|
||||
if sort_by == 'id':
|
||||
get_games_func = GAME_DB.getGamesIdSortedById
|
||||
|
@ -146,31 +153,32 @@ def all_games(sort_by='id'):
|
|||
altnames = '<br>'.join(gi.altnames).encode('utf-8')
|
||||
fn = os.path.join(rules_dir, rules_fn)
|
||||
if 1 and os.path.exists(fn):
|
||||
print '''<tr><td>%s</td><td>
|
||||
print('''<tr><td>%s</td><td>
|
||||
<a href="%s" title="Rules for this game">%s</a>
|
||||
</td><td>%s</td><td>%s</td></tr>
|
||||
''' % (id, fn, name, altnames, gt)
|
||||
''' % (id, fn, name, altnames, gt))
|
||||
else:
|
||||
print '''<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>
|
||||
''' % (id, name, altnames, gt)
|
||||
print '</table>'
|
||||
print('''<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>
|
||||
''' % (id, name, altnames, gt))
|
||||
print('</table>')
|
||||
|
||||
|
||||
def create_html(sort_by):
|
||||
print '''<html>
|
||||
print('''<html>
|
||||
<head>
|
||||
<title>PySolFC - List of solitaire games</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
</head>
|
||||
<body>
|
||||
'''
|
||||
print '<b>Total games: %d</b>' % len(GAME_DB.getGamesIdSortedById())
|
||||
print '<h2>Categories</h2>'
|
||||
''')
|
||||
print('<b>Total games: %d</b>' % len(GAME_DB.getGamesIdSortedById()))
|
||||
print('<h2>Categories</h2>')
|
||||
by_category()
|
||||
print '<h2>Types</h2>'
|
||||
print('<h2>Types</h2>')
|
||||
by_type()
|
||||
# print '<h2>All games</h2>'
|
||||
all_games(sort_by)
|
||||
print '</body></html>'
|
||||
print('</body></html>')
|
||||
|
||||
|
||||
def get_text():
|
||||
|
@ -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 <EMAIL@ADDRESS>, YEAR.
|
||||
|
@ -204,9 +212,10 @@ 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
|
||||
|
@ -222,26 +231,27 @@ def old_plain_text():
|
|||
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')
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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,7 +45,7 @@ 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]]
|
||||
|
@ -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 = []
|
||||
|
@ -67,9 +77,8 @@ def show_cardset(*args):
|
|||
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
|
||||
# if not ls: return
|
||||
ls.sort()
|
||||
n = 0
|
||||
pf = None
|
||||
x, y = 10, 10
|
||||
width, height = 0, 0
|
||||
|
@ -82,10 +91,10 @@ def show_cardset(*args):
|
|||
'BICUBIC': Image.BICUBIC,
|
||||
'ANTIALIAS': Image.ANTIALIAS,
|
||||
}[filter_var.get()]
|
||||
##filter = Image.BILINEAR
|
||||
##filter = Image.BICUBIC
|
||||
##filter = Image.ANTIALIAS
|
||||
##print f
|
||||
# filter = Image.BILINEAR
|
||||
# filter = Image.BICUBIC
|
||||
# filter = Image.ANTIALIAS
|
||||
# print f
|
||||
im = Image.open(f)
|
||||
if zoom != 0:
|
||||
w, h = im.size
|
||||
|
@ -98,7 +107,7 @@ def show_cardset(*args):
|
|||
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))
|
||||
|
@ -116,9 +125,11 @@ def show_cardset(*args):
|
|||
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)
|
||||
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()
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
import os.path
|
||||
for module_name in [
|
||||
for module_name in \
|
||||
[
|
||||
'pysollib.acard',
|
||||
'pysollib.actions',
|
||||
'pysollib.app',
|
||||
|
|
|
@ -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/)
|
||||
|
||||
|
@ -186,9 +188,9 @@ if __name__ == '__main__':
|
|||
# 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(' ', '_')
|
||||
|
@ -197,12 +199,11 @@ if __name__ == '__main__':
|
|||
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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
'lineno': self.__lineno}
|
||||
else:
|
||||
self.__addentry(EMPTYSTRING.join(self.__data))
|
||||
self.__state = self.__waiting
|
||||
|
@ -455,7 +460,8 @@ class TokenEater:
|
|||
# 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
|
||||
|
@ -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:
|
||||
|
|
|
@ -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." );
|
||||
|
|
Loading…
Add table
Reference in a new issue