diff --git a/anki/deck.py b/anki/deck.py index b48b253f7..9834be71c 100644 --- a/anki/deck.py +++ b/anki/deck.py @@ -1574,10 +1574,11 @@ class DeckStorage(object): # attach and sync/fetch deck - first, to unicode if not isinstance(path, types.UnicodeType): path = unicode(path, sys.getfilesystemencoding()) - # sqlite needs utf8 - (engine, session) = DeckStorage._attach(path.encode("utf-8"), create) - s = session() try: + # sqlite needs utf8 + (engine, session) = DeckStorage._attach(path.encode("utf-8"), create) + s = session() + metadata.create_all(engine) if create: deck = DeckStorage._init(s) else: @@ -1633,9 +1634,11 @@ alter table decks add column newCount integer not null default 0""") try: deck = DeckStorage._upgradeDeck(deck, path) except: + traceback.print_exc() deck.fixIntegrity() deck = DeckStorage._upgradeDeck(deck, path) except OperationalError, e: + engine.dispose() if (str(e.orig).startswith("database table is locked") or str(e.orig).startswith("database is locked")): raise DeckAccessError(_("File is in use by another process"), @@ -1659,14 +1662,6 @@ alter table decks add column newCount integer not null default 0""") session = sessionmaker(bind=engine, autoflush=False, transactional=False) - try: - metadata.create_all(engine) - except DBAPIError, e: - engine.dispose() - if create: - raise DeckAccessError(_("Can't read/write deck")) - else: - raise DeckWrongFormatError("Deck is not in the right format") return (engine, session) _attach = staticmethod(_attach) diff --git a/anki/errors.py b/anki/errors.py index ce496c76e..2a155f358 100644 --- a/anki/errors.py +++ b/anki/errors.py @@ -19,15 +19,6 @@ class Error(Exception): return m class DeckAccessError(Error): - "The deck is empty." - pass - -class DeckWrongFormatError(Error): - "A file to import is in the wrong format." - pass - -class DuplicateCardError(Error): - "Attempted to add a card with the same question." pass class ImportFileError(Error):