mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 22:42:25 -04:00
abort download missing media early; remove obsolete forceMediaDir
This commit is contained in:
parent
e5d9697d28
commit
1bbffec0d6
2 changed files with 7 additions and 13 deletions
|
@ -152,7 +152,6 @@ class Deck(object):
|
|||
|
||||
def _initVars(self):
|
||||
self.tmpMediaDir = None
|
||||
self.forceMediaDir = None
|
||||
self.lastTags = u""
|
||||
self.lastLoaded = time.time()
|
||||
self.undoEnabled = False
|
||||
|
@ -2998,11 +2997,7 @@ where key = :key""", key=key, value=value):
|
|||
def mediaDir(self, create=False):
|
||||
"Return the media directory if exists. None if couldn't create."
|
||||
if self.path:
|
||||
# file-backed
|
||||
if self.forceMediaDir:
|
||||
dir = self.forceMediaDir
|
||||
else:
|
||||
dir = re.sub("(?i)\.(anki)$", ".media", self.path)
|
||||
dir = re.sub("(?i)\.(anki)$", ".media", self.path)
|
||||
if create == None:
|
||||
# don't create, but return dir
|
||||
return dir
|
||||
|
|
|
@ -245,7 +245,6 @@ def downloadMissing(deck):
|
|||
if not urls:
|
||||
return None
|
||||
mdir = deck.mediaDir(create=True)
|
||||
os.chdir(mdir)
|
||||
deck.startProgress()
|
||||
missing = {}
|
||||
for (id, fid, val, mid) in deck.s.all("""
|
||||
|
@ -256,20 +255,20 @@ where facts.id = fields.factId"""):
|
|||
for (full, fname, repl) in mediaRefs(val):
|
||||
if not os.path.exists(os.path.join(mdir, fname)) and mid in urls:
|
||||
missing[fname] = mid
|
||||
success = 0
|
||||
for c, file in enumerate(missing.keys()):
|
||||
deck.updateProgress(label=_("Downloading %(a)d of %(b)d...") % {
|
||||
'a': c,
|
||||
'b': len(missing),
|
||||
})
|
||||
try:
|
||||
data = urllib2.urlopen(urls[missing[file]] + file).read()
|
||||
open(file, "wb").write(data)
|
||||
success += 1
|
||||
path = urls[missing[file]] + file
|
||||
url = urllib2.urlopen(path)
|
||||
open(file, "wb").write(url.read())
|
||||
except:
|
||||
pass
|
||||
deck.finishProgress()
|
||||
return (False, path)
|
||||
deck.finishProgress()
|
||||
return len(missing), success
|
||||
return (True, len(missing))
|
||||
|
||||
# Export original files
|
||||
##########################################################################
|
||||
|
|
Loading…
Reference in a new issue