From fa57fd3ad9b10bd931d6b2efd083847842cd55cc Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 21 Apr 2014 14:50:18 +0900 Subject: [PATCH 1/5] don't fail if \n in cloze --- anki/template/template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anki/template/template.py b/anki/template/template.py index 9431d30cc..89b64b52a 100644 --- a/anki/template/template.py +++ b/anki/template/template.py @@ -4,7 +4,7 @@ from anki.hooks import runFilter from anki.template import furigana; furigana.install() from anki.template import hint; hint.install() -clozeReg = r"\{\{c%s::(.*?)(::(.*?))?\}\}" +clozeReg = r"(?s)\{\{c%s::(.*?)(::(.*?))?\}\}" modifiers = {} def modifier(symbol): From bd289fc37e853a13438bd5384f21131743276e4c Mon Sep 17 00:00:00 2001 From: ispedals Date: Mon, 21 Apr 2014 17:04:46 -0400 Subject: [PATCH 2/5] Close file descriptors before unlinking Unlinking a file before closing may not be supported on non-POSIX systems such as Windows. This allows more tests to run to completion. --- tests/shared.py | 2 ++ tests/test_collection.py | 5 +++-- tests/test_exporting.py | 20 +++++++++++++++----- tests/test_upgrade.py | 5 +++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/tests/shared.py b/tests/shared.py index 0f19f548a..a8ba830bc 100644 --- a/tests/shared.py +++ b/tests/shared.py @@ -15,6 +15,7 @@ def assertException(exception, func): def getEmptyDeck(): if len(getEmptyDeck.master) == 0: (fd, nam) = tempfile.mkstemp(suffix=".anki2") + os.close(fd) os.unlink(nam) col = aopen(nam) col.db.close() @@ -28,6 +29,7 @@ getEmptyDeck.master = "" # Fallback for when the DB needs options passed in. def getEmptyDeckWith(**kwargs): (fd, nam) = tempfile.mkstemp(suffix=".anki2") + os.close(fd) os.unlink(nam) return aopen(nam, **kwargs) diff --git a/tests/test_collection.py b/tests/test_collection.py index 578b3fdd2..8e1e99a88 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -1,6 +1,6 @@ # coding: utf-8 -import os +import os, tempfile from tests.shared import assertException, getEmptyDeck from anki.stdmodels import addBasicModel @@ -11,8 +11,9 @@ newMod = None def test_create(): global newPath, newMod - path = "/tmp/test_attachNew.anki2" + (fd, path) = tempfile.mkstemp(suffix=".anki2", prefix="test_attachNew") try: + os.close(fd) os.unlink(path) except OSError: pass diff --git a/tests/test_exporting.py b/tests/test_exporting.py index 1e6d6b3fb..428a621a4 100644 --- a/tests/test_exporting.py +++ b/tests/test_exporting.py @@ -36,7 +36,9 @@ def test_export_anki(): deck.decks.setConf(dobj, confId) # export e = AnkiExporter(deck) - newname = unicode(tempfile.mkstemp(prefix="ankitest", suffix=".anki2")[1]) + fd, newname = tempfile.mkstemp(prefix="ankitest", suffix=".anki2") + newname = unicode(newname) + os.close(fd) os.unlink(newname) e.exportInto(newname) # exporting should not have changed conf for original deck @@ -54,7 +56,9 @@ def test_export_anki(): # conf should be 1 assert dobj['conf'] == 1 # try again, limited to a deck - newname = unicode(tempfile.mkstemp(prefix="ankitest", suffix=".anki2")[1]) + fd, newname = tempfile.mkstemp(prefix="ankitest", suffix=".anki2") + newname = unicode(newname) + os.close(fd) os.unlink(newname) e.did = 1 e.exportInto(newname) @@ -69,7 +73,9 @@ def test_export_ankipkg(): n['Front'] = u'[sound:今日.mp3]' deck.addNote(n) e = AnkiPackageExporter(deck) - newname = unicode(tempfile.mkstemp(prefix="ankitest", suffix=".apkg")[1]) + fd, newname = tempfile.mkstemp(prefix="ankitest", suffix=".apkg") + newname = unicode(newname) + os.close(fd) os.unlink(newname) e.exportInto(newname) @@ -92,7 +98,9 @@ def test_export_anki_due(): # export e = AnkiExporter(deck) e.includeSched = True - newname = unicode(tempfile.mkstemp(prefix="ankitest", suffix=".anki2")[1]) + fd, newname = tempfile.mkstemp(prefix="ankitest", suffix=".anki2") + newname = unicode(newname) + os.close(fd) os.unlink(newname) e.exportInto(newname) # importing into a new deck, the due date should be equivalent @@ -115,7 +123,9 @@ def test_export_anki_due(): @nose.with_setup(setup1) def test_export_textnote(): e = TextNoteExporter(deck) - f = unicode(tempfile.mkstemp(prefix="ankitest")[1]) + fd, f = tempfile.mkstemp(prefix="ankitest") + f = unicode(f) + os.close(fd) os.unlink(f) e.exportInto(f) e.includeTags = True diff --git a/tests/test_upgrade.py b/tests/test_upgrade.py index c293a9118..155c13ca0 100644 --- a/tests/test_upgrade.py +++ b/tests/test_upgrade.py @@ -1,6 +1,6 @@ # coding: utf-8 -import datetime, shutil +import datetime, shutil, tempfile from anki import Collection from anki.consts import * from shared import getUpgradeDeckPath, testDir @@ -63,8 +63,9 @@ def test_invalid_ords(): assert deck.db.scalar("select count() from cards where ord = 1") == 1 def test_upgrade2(): - p = "/tmp/alpha-upgrade.anki2" + fd, p = tempfile.mkstemp(suffix=".anki2", prefix="alpha-upgrade") if os.path.exists(p): + os.close(fd) os.unlink(p) shutil.copy2(os.path.join(testDir, "support/anki2-alpha.anki2"), p) col = Collection(p) From 5629533b3895bf0bf9e4143f18516b81d483967e Mon Sep 17 00:00:00 2001 From: Adam Mesha Date: Tue, 22 Apr 2014 01:16:39 +0300 Subject: [PATCH 3/5] Add hooks before and after a state change. Useful for plugin authors. --- aqt/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aqt/main.py b/aqt/main.py index 19ab5ea81..05c28c684 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -383,7 +383,9 @@ the manual for information on how to restore from an automatic backup.")) if cleanup: cleanup(state) self.state = state + runHook('beforeStateChange', state, oldState, *args) getattr(self, "_"+state+"State")(oldState, *args) + runHook('afterStateChange', state, oldState, *args) def _deckBrowserState(self, oldState): self.deckBrowser.show() From 00dd291819d97361e5790f82b26977493a0d294c Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 23 Apr 2014 08:16:45 +0900 Subject: [PATCH 4/5] bump version --- anki/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anki/__init__.py b/anki/__init__.py index 21869eadd..d7f33c917 100644 --- a/anki/__init__.py +++ b/anki/__init__.py @@ -30,6 +30,6 @@ if arch[1] == "ELF": sys.path.insert(0, os.path.join(ext, "py2.%d-%s" % ( sys.version_info[1], arch[0][0:2]))) -version="2.0.25" # build scripts grep this line, so preserve formatting +version="2.0.26" # build scripts grep this line, so preserve formatting from anki.storage import Collection __all__ = ["Collection"] From b4c52150132a0b32b6cb943b527f956d36669f61 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 23 Apr 2014 08:20:00 +0900 Subject: [PATCH 5/5] allow app modal again now that qt's been fixed --- aqt/progress.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/aqt/progress.py b/aqt/progress.py index f661f12a1..13b218a88 100644 --- a/aqt/progress.py +++ b/aqt/progress.py @@ -96,8 +96,7 @@ Your pysqlite2 is too old. Anki will appear frozen during long operations.""" self._win.setCancelButton(None) self._win.setAutoClose(False) self._win.setAutoReset(False) - if not isMac: - self._win.setWindowModality(Qt.ApplicationModal) + self._win.setWindowModality(Qt.ApplicationModal) # we need to manually manage minimum time to show, as qt gets confused # by the db handler self._win.setMinimumDuration(100000)