mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
fix media db check on non-unicode dir
This commit is contained in:
parent
276ec634b9
commit
0a9c498cbd
1 changed files with 6 additions and 2 deletions
|
@ -143,11 +143,15 @@ def rebuildMediaDir(deck, delete=False, dirty=True):
|
||||||
deck.s.statement("update media set size = 0")
|
deck.s.statement("update media set size = 0")
|
||||||
# look through cards for media references
|
# look through cards for media references
|
||||||
refs = {}
|
refs = {}
|
||||||
|
def norm(s):
|
||||||
|
if isinstance(s, unicode):
|
||||||
|
return unicodedata.normalize('NFD', s)
|
||||||
|
return s
|
||||||
for (question, answer) in deck.s.all(
|
for (question, answer) in deck.s.all(
|
||||||
"select question, answer from cards"):
|
"select question, answer from cards"):
|
||||||
for txt in (question, answer):
|
for txt in (question, answer):
|
||||||
for f in mediaFiles(txt):
|
for f in mediaFiles(txt):
|
||||||
f = unicodedata.normalize('NFD', f)
|
f = norm(f)
|
||||||
if f in refs:
|
if f in refs:
|
||||||
refs[f] += 1
|
refs[f] += 1
|
||||||
else:
|
else:
|
||||||
|
@ -162,7 +166,7 @@ def rebuildMediaDir(deck, delete=False, dirty=True):
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
# ignore directories
|
# ignore directories
|
||||||
continue
|
continue
|
||||||
file = unicodedata.normalize('NFD', file)
|
file = norm(file)
|
||||||
if file not in refs:
|
if file not in refs:
|
||||||
unused.append(file)
|
unused.append(file)
|
||||||
# optionally delete
|
# optionally delete
|
||||||
|
|
Loading…
Reference in a new issue