mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
flake 8.
This commit is contained in:
parent
fc90baffa7
commit
c4a0d62963
2 changed files with 90 additions and 80 deletions
|
@ -23,7 +23,10 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import os, glob, traceback
|
import os
|
||||||
|
import sys
|
||||||
|
import glob
|
||||||
|
import traceback
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from pysollib.mfxutil import Struct, KwStruct
|
from pysollib.mfxutil import Struct, KwStruct
|
||||||
|
@ -35,22 +38,27 @@ from pysollib.mygettext import _
|
||||||
# * Abstract
|
# * Abstract
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
|
||||||
|
if sys.version_info > (3,):
|
||||||
|
basestring = str
|
||||||
|
|
||||||
|
|
||||||
class Resource(Struct):
|
class Resource(Struct):
|
||||||
def __init__(self, **kw):
|
def __init__(self, **kw):
|
||||||
kw = KwStruct(kw,
|
kw = KwStruct(
|
||||||
name = "",
|
kw,
|
||||||
filename = "",
|
name="",
|
||||||
basename = "", # basename of filename
|
filename="",
|
||||||
absname = "", # absolute filename
|
basename="", # basename of filename
|
||||||
|
absname="", # absolute filename
|
||||||
# implicit
|
# implicit
|
||||||
index = -1,
|
index=-1,
|
||||||
error = 0, # error while loading this resource
|
error=0, # error while loading this resource
|
||||||
)
|
)
|
||||||
Struct.__init__(self, **kw.getKw())
|
Struct.__init__(self, **kw.getKw())
|
||||||
|
|
||||||
def getSortKey(self):
|
def getSortKey(self):
|
||||||
return self.name.lower()
|
return self.name.lower()
|
||||||
#return latin1_to_ascii(self.name).lower()
|
# return latin1_to_ascii(self.name).lower()
|
||||||
|
|
||||||
|
|
||||||
class ResourceManager:
|
class ResourceManager:
|
||||||
|
@ -118,7 +126,7 @@ class ResourceManager:
|
||||||
dir = os.path.normpath(dir)
|
dir = os.path.normpath(dir)
|
||||||
if dir and os.path.isdir(dir) and dir not in result:
|
if dir and os.path.isdir(dir) and dir not in result:
|
||||||
result.append(dir)
|
result.append(dir)
|
||||||
except EnvironmentError, ex:
|
except EnvironmentError as ex:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def getSearchDirs(self, app, search, env=None):
|
def getSearchDirs(self, app, search, env=None):
|
||||||
|
@ -145,11 +153,11 @@ class ResourceManager:
|
||||||
self._addDir(result, d)
|
self._addDir(result, d)
|
||||||
else:
|
else:
|
||||||
self._addDir(result, os.path.join(dir, s))
|
self._addDir(result, os.path.join(dir, s))
|
||||||
except EnvironmentError, ex:
|
except EnvironmentError as ex:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
pass
|
pass
|
||||||
if DEBUG >= 6:
|
if DEBUG >= 6:
|
||||||
print "getSearchDirs", env, search, "->", result
|
print("getSearchDirs", env, search, "->", result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,16 +168,16 @@ class ResourceManager:
|
||||||
# CardsetInfo constants
|
# CardsetInfo constants
|
||||||
class CSI:
|
class CSI:
|
||||||
# cardset size
|
# cardset size
|
||||||
SIZE_TINY = 1
|
SIZE_TINY = 1
|
||||||
SIZE_SMALL = 2
|
SIZE_SMALL = 2
|
||||||
SIZE_MEDIUM = 3
|
SIZE_MEDIUM = 3
|
||||||
SIZE_LARGE = 4
|
SIZE_LARGE = 4
|
||||||
SIZE_XLARGE = 5
|
SIZE_XLARGE = 5
|
||||||
|
|
||||||
# cardset types
|
# cardset types
|
||||||
TYPE_FRENCH = 1
|
TYPE_FRENCH = 1
|
||||||
TYPE_HANAFUDA = 2
|
TYPE_HANAFUDA = 2
|
||||||
TYPE_TAROCK = 3
|
TYPE_TAROCK = 3
|
||||||
TYPE_MAHJONGG = 4
|
TYPE_MAHJONGG = 4
|
||||||
TYPE_HEXADECK = 5
|
TYPE_HEXADECK = 5
|
||||||
TYPE_MUGHAL_GANJIFA = 6
|
TYPE_MUGHAL_GANJIFA = 6
|
||||||
|
@ -224,28 +232,28 @@ class CSI:
|
||||||
7: _("Classic look"), #
|
7: _("Classic look"), #
|
||||||
8: _("Collectors"), # scanned collectors cardsets
|
8: _("Collectors"), # scanned collectors cardsets
|
||||||
9: _("Computers"), #
|
9: _("Computers"), #
|
||||||
10: _("Engines"), #
|
10: _("Engines"), #
|
||||||
11: _("Fantasy"), #
|
11: _("Fantasy"), #
|
||||||
30: _("Ganjifa"), #
|
30: _("Ganjifa"), #
|
||||||
12: _("Hanafuda"), #
|
12: _("Hanafuda"), #
|
||||||
29: _("Hex A Deck"), #
|
29: _("Hex A Deck"), #
|
||||||
13: _("Holiday"), #
|
13: _("Holiday"), #
|
||||||
28: _("Mahjongg"), #
|
28: _("Mahjongg"), #
|
||||||
14: _("Movies"), #
|
14: _("Movies"), #
|
||||||
31: _("Matrix"), #
|
31: _("Matrix"), #
|
||||||
15: _("Music"), #
|
15: _("Music"), #
|
||||||
16: _("Nature"), #
|
16: _("Nature"), #
|
||||||
17: _("Operating Systems"), # e.g. cards with Linux logos
|
17: _("Operating Systems"), # e.g. cards with Linux logos
|
||||||
19: _("People"), # famous people
|
19: _("People"), # famous people
|
||||||
20: _("Places"), #
|
20: _("Places"), #
|
||||||
21: _("Plain"), #
|
21: _("Plain"), #
|
||||||
22: _("Products"), #
|
22: _("Products"), #
|
||||||
18: _("Round cardsets"), #
|
18: _("Round cardsets"), #
|
||||||
23: _("Science Fiction"), #
|
23: _("Science Fiction"), #
|
||||||
24: _("Sports"), #
|
24: _("Sports"), #
|
||||||
27: _("Tarock"), #
|
27: _("Tarock"), #
|
||||||
25: _("Vehicels"), #
|
25: _("Vehicels"), #
|
||||||
26: _("Video Games"), #
|
26: _("Video Games"), #
|
||||||
}
|
}
|
||||||
|
|
||||||
# cardset nationality (suit and rank symbols)
|
# cardset nationality (suit and rank symbols)
|
||||||
|
@ -294,33 +302,34 @@ class CSI:
|
||||||
class CardsetConfig(Struct):
|
class CardsetConfig(Struct):
|
||||||
# see config.txt and _readCardsetConfig()
|
# see config.txt and _readCardsetConfig()
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Struct.__init__(self,
|
Struct.__init__(
|
||||||
|
self,
|
||||||
# line[0]
|
# line[0]
|
||||||
version = 1,
|
version=1,
|
||||||
ext = ".gif",
|
ext=".gif",
|
||||||
type = CSI.TYPE_FRENCH,
|
type=CSI.TYPE_FRENCH,
|
||||||
ncards = -1,
|
ncards=-1,
|
||||||
styles = [],
|
styles=[],
|
||||||
year = 0,
|
year=0,
|
||||||
# line[1]
|
# line[1]
|
||||||
ident = "",
|
ident="",
|
||||||
name = "",
|
name="",
|
||||||
# line[2]
|
# line[2]
|
||||||
CARDW = 0,
|
CARDW=0,
|
||||||
CARDH = 0,
|
CARDH=0,
|
||||||
CARDD = 0,
|
CARDD=0,
|
||||||
# line[3]
|
# line[3]
|
||||||
CARD_XOFFSET = 0,
|
CARD_XOFFSET=0,
|
||||||
CARD_YOFFSET = 0,
|
CARD_YOFFSET=0,
|
||||||
SHADOW_XOFFSET = 0,
|
SHADOW_XOFFSET=0,
|
||||||
SHADOW_YOFFSET = 0,
|
SHADOW_YOFFSET=0,
|
||||||
# line[4]
|
# line[4]
|
||||||
backindex = 0,
|
backindex=0,
|
||||||
# line[5]
|
# line[5]
|
||||||
backnames = (),
|
backnames=(),
|
||||||
# other
|
# other
|
||||||
CARD_DX = 0, # relative pos of real card image within Card
|
CARD_DX=0, # relative pos of real card image within Card
|
||||||
CARD_DY = 0,
|
CARD_DY=0,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -332,19 +341,20 @@ class Cardset(Resource):
|
||||||
# si is the SelectionInfo struct that will be queried by
|
# si is the SelectionInfo struct that will be queried by
|
||||||
# the "select cardset" dialogs. It can be freely modified.
|
# the "select cardset" dialogs. It can be freely modified.
|
||||||
si = Struct(type=0, size=0, styles=[], nationalities=[], dates=[])
|
si = Struct(type=0, size=0, styles=[], nationalities=[], dates=[])
|
||||||
kw = KwStruct(kw,
|
kw = KwStruct(
|
||||||
|
kw,
|
||||||
# essentials
|
# essentials
|
||||||
ranks = (),
|
ranks=(),
|
||||||
suits = (),
|
suits=(),
|
||||||
trumps = (),
|
trumps=(),
|
||||||
nbottoms = 7,
|
nbottoms=7,
|
||||||
nletters = 4,
|
nletters=4,
|
||||||
nshadows = 1 + 13,
|
nshadows=1 + 13,
|
||||||
# selection criteria
|
# selection criteria
|
||||||
si = si,
|
si=si,
|
||||||
# implicit
|
# implicit
|
||||||
backname = None,
|
backname=None,
|
||||||
dir = "",
|
dir="",
|
||||||
)
|
)
|
||||||
Resource.__init__(self, **kw.getKw())
|
Resource.__init__(self, **kw.getKw())
|
||||||
|
|
||||||
|
@ -368,7 +378,7 @@ class Cardset(Resource):
|
||||||
if lr >= 4:
|
if lr >= 4:
|
||||||
ls = min(ls, 4)
|
ls = min(ls, 4)
|
||||||
low_ranks, high_ranks = 1, 3
|
low_ranks, high_ranks = 1, 3
|
||||||
###if self.type == 3: high_ranks = 4
|
# if self.type == 3: high_ranks = 4
|
||||||
for rank in range(0, low_ranks) + range(lr-high_ranks, lr):
|
for rank in range(0, low_ranks) + range(lr-high_ranks, lr):
|
||||||
for suit in range(ls):
|
for suit in range(ls):
|
||||||
index = suit * len(self.ranks) + rank
|
index = suit * len(self.ranks) + rank
|
||||||
|
@ -385,7 +395,7 @@ class Cardset(Resource):
|
||||||
self.backname = self.backnames[self.backindex]
|
self.backname = self.backnames[self.backindex]
|
||||||
|
|
||||||
def saveSettings(self):
|
def saveSettings(self):
|
||||||
print 'saveSettings'
|
print('saveSettings')
|
||||||
|
|
||||||
|
|
||||||
class CardsetManager(ResourceManager):
|
class CardsetManager(ResourceManager):
|
||||||
|
@ -432,7 +442,7 @@ class CardsetManager(ResourceManager):
|
||||||
cs.ranks = range(12)
|
cs.ranks = range(12)
|
||||||
cs.suits = "abcdefgh"
|
cs.suits = "abcdefgh"
|
||||||
elif s == CSI.TYPE_NAVAGRAHA_GANJIFA:
|
elif s == CSI.TYPE_NAVAGRAHA_GANJIFA:
|
||||||
#???return 0 ## FIXME
|
# ???return 0 ## FIXME
|
||||||
cs.nbottoms = 12
|
cs.nbottoms = 12
|
||||||
cs.ranks = range(12)
|
cs.ranks = range(12)
|
||||||
cs.suits = "abcdefghi"
|
cs.suits = "abcdefghi"
|
||||||
|
@ -441,11 +451,11 @@ class CardsetManager(ResourceManager):
|
||||||
cs.ranks = range(12)
|
cs.ranks = range(12)
|
||||||
cs.suits = "abcdefghij"
|
cs.suits = "abcdefghij"
|
||||||
elif s == CSI.TYPE_TRUMP_ONLY:
|
elif s == CSI.TYPE_TRUMP_ONLY:
|
||||||
#???return 0 ## FIXME
|
# ???return 0 ## FIXME
|
||||||
#cs.nbottoms = 7
|
# cs.nbottoms = 7
|
||||||
#cs.ranks = ()
|
# cs.ranks = ()
|
||||||
#cs.suits = ""
|
# cs.suits = ""
|
||||||
#cs.trumps = range(cs.ncards)
|
# cs.trumps = range(cs.ncards)
|
||||||
cs.nbottoms = 1
|
cs.nbottoms = 1
|
||||||
cs.nletters = 0
|
cs.nletters = 0
|
||||||
cs.nshadows = 0
|
cs.nshadows = 0
|
||||||
|
@ -481,7 +491,8 @@ class CardsetManager(ResourceManager):
|
||||||
self.registered_styles[s] = self.registered_styles.get(s, 0) + 1
|
self.registered_styles[s] = self.registered_styles.get(s, 0) + 1
|
||||||
cs.si.nationalities = tuple([s for s in keys if s in CSI.NATIONALITY])
|
cs.si.nationalities = tuple([s for s in keys if s in CSI.NATIONALITY])
|
||||||
for s in cs.si.nationalities:
|
for s in cs.si.nationalities:
|
||||||
self.registered_nationalities[s] = self.registered_nationalities.get(s, 0) + 1
|
self.registered_nationalities[s] = \
|
||||||
|
self.registered_nationalities.get(s, 0) + 1
|
||||||
keys = (cs.year / 100,)
|
keys = (cs.year / 100,)
|
||||||
cs.si.dates = tuple([s for s in keys if s in CSI.DATE])
|
cs.si.dates = tuple([s for s in keys if s in CSI.DATE])
|
||||||
for s in cs.si.dates:
|
for s in cs.si.dates:
|
||||||
|
@ -535,4 +546,3 @@ class Music(Sample):
|
||||||
|
|
||||||
class MusicManager(SampleManager):
|
class MusicManager(SampleManager):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use String::ShellQuote qw/ shell_quote /;
|
||||||
|
|
||||||
# my $cmd = shell_quote( 'flake8', '.' );
|
# my $cmd = shell_quote( 'flake8', '.' );
|
||||||
my $cmd = shell_quote( 'flake8',
|
my $cmd = shell_quote( 'flake8',
|
||||||
grep { not($_ eq './pysollib/pysoltk.py') } glob('./pysollib/[a-p]*.py') );
|
grep { not($_ eq './pysollib/pysoltk.py') } glob('./pysollib/[a-r]*.py') );
|
||||||
|
|
||||||
# TEST
|
# TEST
|
||||||
eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." );
|
eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." );
|
||||||
|
|
Loading…
Add table
Reference in a new issue