mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
add progress info to card/fact export
This commit is contained in:
parent
b4f1d6622a
commit
ea2fa24fed
1 changed files with 16 additions and 1 deletions
|
@ -26,6 +26,7 @@ class Exporter(object):
|
||||||
self.limitCardIds = []
|
self.limitCardIds = []
|
||||||
|
|
||||||
def exportInto(self, path):
|
def exportInto(self, path):
|
||||||
|
self._escapeCount = 0
|
||||||
file = open(path, "wb")
|
file = open(path, "wb")
|
||||||
self.doExport(file)
|
self.doExport(file)
|
||||||
file.close()
|
file.close()
|
||||||
|
@ -35,6 +36,10 @@ class Exporter(object):
|
||||||
text = text.replace("\n", "<br>")
|
text = text.replace("\n", "<br>")
|
||||||
text = text.replace("\t", " " * 8)
|
text = text.replace("\t", " " * 8)
|
||||||
if removeFields:
|
if removeFields:
|
||||||
|
# beautifulsoup is slow
|
||||||
|
self._escapeCount += 1
|
||||||
|
if self._escapeCount % 100 == 0:
|
||||||
|
self.deck.updateProgress()
|
||||||
s = BS(text)
|
s = BS(text)
|
||||||
all = s('span', {'class': re.compile("fm.*")})
|
all = s('span', {'class': re.compile("fm.*")})
|
||||||
for e in all:
|
for e in all:
|
||||||
|
@ -175,11 +180,15 @@ class TextCardExporter(Exporter):
|
||||||
self.includeTags = False
|
self.includeTags = False
|
||||||
|
|
||||||
def doExport(self, file):
|
def doExport(self, file):
|
||||||
strids = ids2str(self.cardIds())
|
ids = self.cardIds()
|
||||||
|
strids = ids2str(ids)
|
||||||
|
self.deck.startProgress((len(ids) + 1) / 50)
|
||||||
|
self.deck.updateProgress(_("Exporting..."))
|
||||||
cards = self.deck.s.all("""
|
cards = self.deck.s.all("""
|
||||||
select cards.question, cards.answer, cards.id from cards
|
select cards.question, cards.answer, cards.id from cards
|
||||||
where cards.id in %s
|
where cards.id in %s
|
||||||
order by cards.created""" % strids)
|
order by cards.created""" % strids)
|
||||||
|
self.deck.updateProgress()
|
||||||
if self.includeTags:
|
if self.includeTags:
|
||||||
self.cardTags = dict(self.deck.s.all("""
|
self.cardTags = dict(self.deck.s.all("""
|
||||||
select cards.id, cards.tags || "," || facts.tags from cards, facts
|
select cards.id, cards.tags || "," || facts.tags from cards, facts
|
||||||
|
@ -194,6 +203,7 @@ order by cards.created""" % strids))
|
||||||
if out:
|
if out:
|
||||||
out += "\n"
|
out += "\n"
|
||||||
file.write(out.encode("utf-8"))
|
file.write(out.encode("utf-8"))
|
||||||
|
self.deck.finishProgress()
|
||||||
|
|
||||||
def tags(self, id):
|
def tags(self, id):
|
||||||
if self.includeTags:
|
if self.includeTags:
|
||||||
|
@ -211,6 +221,8 @@ class TextFactExporter(Exporter):
|
||||||
|
|
||||||
def doExport(self, file):
|
def doExport(self, file):
|
||||||
cardIds = self.cardIds()
|
cardIds = self.cardIds()
|
||||||
|
self.deck.startProgress()
|
||||||
|
self.deck.updateProgress(_("Exporting..."))
|
||||||
facts = self.deck.s.all("""
|
facts = self.deck.s.all("""
|
||||||
select factId, value, facts.created from facts, fields
|
select factId, value, facts.created from facts, fields
|
||||||
where
|
where
|
||||||
|
@ -220,6 +232,7 @@ where cards.id in %s)
|
||||||
and facts.id = fields.factId
|
and facts.id = fields.factId
|
||||||
order by factId, ordinal""" % ids2str(cardIds))
|
order by factId, ordinal""" % ids2str(cardIds))
|
||||||
txt = ""
|
txt = ""
|
||||||
|
self.deck.updateProgress()
|
||||||
if self.includeTags:
|
if self.includeTags:
|
||||||
self.factTags = dict(self.deck.s.all(
|
self.factTags = dict(self.deck.s.all(
|
||||||
"select id, tags from facts where id in %s" %
|
"select id, tags from facts where id in %s" %
|
||||||
|
@ -230,11 +243,13 @@ order by factId, ordinal""" % ids2str(cardIds))
|
||||||
"\t".join([self.escapeText(x[1]) for x in group]) +
|
"\t".join([self.escapeText(x[1]) for x in group]) +
|
||||||
self.tags(group[0][0]))
|
self.tags(group[0][0]))
|
||||||
for group in groups]
|
for group in groups]
|
||||||
|
self.deck.updateProgress()
|
||||||
groups.sort(key=itemgetter(0))
|
groups.sort(key=itemgetter(0))
|
||||||
out = [ret[1] for ret in groups]
|
out = [ret[1] for ret in groups]
|
||||||
self.count = len(out)
|
self.count = len(out)
|
||||||
out = "\n".join(out)
|
out = "\n".join(out)
|
||||||
file.write(out.encode("utf-8"))
|
file.write(out.encode("utf-8"))
|
||||||
|
self.deck.finishProgress()
|
||||||
|
|
||||||
def tags(self, id):
|
def tags(self, id):
|
||||||
if self.includeTags:
|
if self.includeTags:
|
||||||
|
|
Loading…
Reference in a new issue