mirror of
https://github.com/erkin/ponysay.git
synced 2024-11-26 06:07:59 +01:00
the implemention for --restrict, the data storing is not yet implemented
This commit is contained in:
parent
055b28e8dc
commit
2765e8f33f
1 changed files with 26 additions and 8 deletions
34
ponysay.py
34
ponysay.py
|
@ -601,7 +601,7 @@ class Ponysay():
|
||||||
if strict: return STest(key, value)
|
if strict: return STest(key, value)
|
||||||
if invert: return ITest(key, value)
|
if invert: return ITest(key, value)
|
||||||
return NTest(key, value)
|
return NTest(key, value)
|
||||||
def logic(cells): # note inverted return value
|
def logic(cells):
|
||||||
for alternative in table:
|
for alternative in table:
|
||||||
ok = True
|
ok = True
|
||||||
for cell in alternative:
|
for cell in alternative:
|
||||||
|
@ -609,13 +609,15 @@ class Ponysay():
|
||||||
ok = False
|
ok = False
|
||||||
break
|
break
|
||||||
if ok:
|
if ok:
|
||||||
return False
|
return True
|
||||||
return True
|
return False
|
||||||
ponies = {}
|
ponies = {}
|
||||||
for ponydir in self.ponydirs:
|
for ponydir in self.ponydirs:
|
||||||
for pony in self.restrictedPonies(ponydir, logic):
|
for pony in self.restrictedPonies(ponydir, logic):
|
||||||
if (pony in oldponies) and (ponies[pony] == ponydir + pony + '.pony'):
|
if (pony not in passed) and (pony in oldponies):
|
||||||
del ponies[pony]
|
ponyfile = ponydir + pony + '.pony'
|
||||||
|
if oldponies[pony] == ponyfile:
|
||||||
|
ponies[pony] = ponyfile
|
||||||
oldponies = ponies
|
oldponies = ponies
|
||||||
ponies = {}
|
ponies = {}
|
||||||
(termh, termw) = self.__gettermsize()
|
(termh, termw) = self.__gettermsize()
|
||||||
|
@ -660,9 +662,25 @@ class Ponysay():
|
||||||
return ponies[pony]
|
return ponies[pony]
|
||||||
|
|
||||||
|
|
||||||
#### FIXME not yet implemented
|
'''
|
||||||
def restrictedPonies(self, ponyday, logic):
|
Get ponies that pass restriction
|
||||||
return False
|
|
||||||
|
@param ponydir:str Pony directory
|
||||||
|
@param logic:dict<str, str>→bool Restriction test functor
|
||||||
|
@return :list<str> Passed ponies
|
||||||
|
'''
|
||||||
|
def restrictedPonies(self, ponydir, logic):
|
||||||
|
import cPickle
|
||||||
|
passed = []
|
||||||
|
if os.path.exists(ponydir + 'metadata'):
|
||||||
|
data = None
|
||||||
|
with open(ponydir + 'metadata', 'rb') as file:
|
||||||
|
data = cPickle.load(file)
|
||||||
|
for ponydata in data:
|
||||||
|
(pony, meta) = ponydata
|
||||||
|
if logic(meta):
|
||||||
|
passed.append(pony)
|
||||||
|
return passed
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in a new issue