mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
catch and report issues when downgrading
This commit is contained in:
parent
07343f6c9f
commit
a7d5d27778
2 changed files with 28 additions and 8 deletions
|
@ -347,13 +347,24 @@ close the profile or restart Anki."""
|
||||||
def _on_downgrade(self):
|
def _on_downgrade(self):
|
||||||
self.progress.start()
|
self.progress.start()
|
||||||
profiles = self.pm.profiles()
|
profiles = self.pm.profiles()
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
self.pm.downgrade(profiles)
|
return self.pm.downgrade(profiles)
|
||||||
|
|
||||||
def on_done(future):
|
def on_done(future):
|
||||||
self.progress.finish()
|
self.progress.finish()
|
||||||
future.result()
|
problems = future.result()
|
||||||
showInfo("Profiles can now be opened with an older version of Anki.")
|
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.profileDiag.close()
|
||||||
|
|
||||||
self.taskman.run_in_background(downgrade, on_done)
|
self.taskman.run_in_background(downgrade, on_done)
|
||||||
|
|
||||||
def loadProfile(self, onsuccess: Optional[Callable] = None) -> None:
|
def loadProfile(self, onsuccess: Optional[Callable] = None) -> None:
|
||||||
|
@ -458,7 +469,9 @@ close the profile or restart Anki."""
|
||||||
self._loadCollection()
|
self._loadCollection()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if "FileTooNew" in str(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:
|
else:
|
||||||
showWarning(
|
showWarning(
|
||||||
tr(TR.ERRORS_UNABLE_OPEN_COLLECTION) + "\n" + traceback.format_exc()
|
tr(TR.ERRORS_UNABLE_OPEN_COLLECTION) + "\n" + traceback.format_exc()
|
||||||
|
|
|
@ -11,7 +11,7 @@ import locale
|
||||||
import pickle
|
import pickle
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
from typing import Any, Dict, Optional, List
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
from send2trash import send2trash
|
from send2trash import send2trash
|
||||||
|
|
||||||
|
@ -279,7 +279,9 @@ and no other programs are accessing your profile folders, then try again."""
|
||||||
# Downgrade
|
# 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:
|
for name in profiles:
|
||||||
path = os.path.join(self.base, name, "collection.anki2")
|
path = os.path.join(self.base, name, "collection.anki2")
|
||||||
if not os.path.exists(path):
|
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:
|
if db.scalar("select ver from col") == 11:
|
||||||
# nothing to do
|
# nothing to do
|
||||||
continue
|
continue
|
||||||
c = Collection(path)
|
try:
|
||||||
c.close(save=False, downgrade=True)
|
c = Collection(path)
|
||||||
|
c.close(save=False, downgrade=True)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
problem_profiles.append(name)
|
||||||
|
return problem_profiles
|
||||||
|
|
||||||
# Helpers
|
# Helpers
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
Loading…
Reference in a new issue