catch and report issues when downgrading

This commit is contained in:
Damien Elmes 2020-04-16 09:53:29 +10:00
parent 07343f6c9f
commit a7d5d27778
2 changed files with 28 additions and 8 deletions

View file

@ -347,13 +347,24 @@ close the profile or restart Anki."""
def _on_downgrade(self):
self.progress.start()
profiles = self.pm.profiles()
def downgrade():
self.pm.downgrade(profiles)
return self.pm.downgrade(profiles)
def on_done(future):
self.progress.finish()
future.result()
showInfo("Profiles can now be opened with an older version of Anki.")
problems = future.result()
if not problems:
showInfo("Profiles can now be opened with an older version of Anki.")
else:
showWarning(
"The following profiles could not be downgraded: {}".format(
", ".join(problems)
)
)
return
self.profileDiag.close()
self.taskman.run_in_background(downgrade, on_done)
def loadProfile(self, onsuccess: Optional[Callable] = None) -> None:
@ -458,7 +469,9 @@ close the profile or restart Anki."""
self._loadCollection()
except Exception as e:
if "FileTooNew" in str(e):
showWarning("This profile requires a newer version of Anki to open. Did you forget to use the Downgrade button prior to switching Anki versions?")
showWarning(
"This profile requires a newer version of Anki to open. Did you forget to use the Downgrade button prior to switching Anki versions?"
)
else:
showWarning(
tr(TR.ERRORS_UNABLE_OPEN_COLLECTION) + "\n" + traceback.format_exc()

View file

@ -11,7 +11,7 @@ import locale
import pickle
import random
import shutil
from typing import Any, Dict, Optional, List
from typing import Any, Dict, List, Optional
from send2trash import send2trash
@ -279,7 +279,9 @@ and no other programs are accessing your profile folders, then try again."""
# Downgrade
######################################################################
def downgrade(self, profiles=List[str]):
def downgrade(self, profiles=List[str]) -> List[str]:
"Downgrade all profiles. Return a list of profiles that couldn't be opened."
problem_profiles = []
for name in profiles:
path = os.path.join(self.base, name, "collection.anki2")
if not os.path.exists(path):
@ -288,8 +290,13 @@ and no other programs are accessing your profile folders, then try again."""
if db.scalar("select ver from col") == 11:
# nothing to do
continue
c = Collection(path)
c.close(save=False, downgrade=True)
try:
c = Collection(path)
c.close(save=False, downgrade=True)
except Exception as e:
print(e)
problem_profiles.append(name)
return problem_profiles
# Helpers
######################################################################