Revert "Merge pull request #610 from evandroforks/ask_confirmation_before_moving_anki_collection"

This reverts commit a53aac40f8, reversing
changes made to e323a8f902.

Migration is about to be dropped (#1390), and the references to modules
like QtGui complicate a PyQt5/6 shim.
This commit is contained in:
Damien Elmes 2021-10-05 09:08:48 +10:00
parent aaceeec25a
commit c39a5e17e8
2 changed files with 1 additions and 78 deletions

View File

@ -54,7 +54,7 @@ appUpdate = "https://ankiweb.net/update/desktop"
appHelpSite = HELP_SITE
from aqt.main import AnkiQt # isort:skip
from aqt.profiles import ProfileManager, AnkiRestart, VideoDriver # isort:skip
from aqt.profiles import ProfileManager, VideoDriver # isort:skip
profiler: Optional[cProfile.Profile] = None
mw: Optional[AnkiQt] = None # set on init
@ -498,10 +498,6 @@ def _run(argv: Optional[list[str]] = None, exec: bool = True) -> Optional[AnkiAp
try:
pm = ProfileManager(opts.base)
pmLoadResult = pm.setupMeta()
except AnkiRestart as error:
if error.exitcode:
sys.exit(error.exitcode)
return None
except:
# will handle below
traceback.print_exc()

View File

@ -111,12 +111,6 @@ class LoadMetaResult:
loadError: bool
class AnkiRestart(SystemExit):
def __init__(self, exitcode: int = 0) -> None:
self.exitcode = exitcode
super().__init__()
class ProfileManager:
def __init__(self, base: str | None = None) -> None: #
## Settings which should be forgotten each Anki restart
@ -170,77 +164,10 @@ class ProfileManager:
return os.path.expanduser("~/Documents/Anki")
def maybeMigrateFolder(self) -> None:
newBase = self.base
oldBase = self._oldFolderLocation()
if oldBase and not os.path.exists(self.base) and os.path.isdir(oldBase):
try:
# if anything goes wrong with UI, reset to the old behavior of always migrating
self._tryToMigrateFolder(oldBase)
except AnkiRestart:
raise
except:
print("migration failed")
self.base = newBase
shutil.move(oldBase, self.base)
def _tryToMigrateFolder(self, oldBase: str) -> None:
from PyQt5 import QtGui, QtWidgets
app = QtWidgets.QApplication([])
icon = QtGui.QIcon()
icon.addPixmap(
QtGui.QPixmap("icons:anki.png"),
QtGui.QIcon.Normal,
QtGui.QIcon.Off,
)
window_title = "Data Folder Migration"
migration_directories = f"\n\n {oldBase}\n\nto\n\n {self.base}"
confirmation = QMessageBox()
confirmation.setIcon(QMessageBox.Warning)
confirmation.setWindowIcon(icon)
confirmation.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) # type: ignore
confirmation.setWindowTitle(window_title)
confirmation.setText(
"Anki needs to move its data folder from Documents/Anki to a new location. Proceed?"
)
retval = confirmation.exec()
if retval == QMessageBox.Ok:
progress = QMessageBox()
progress.setIcon(QMessageBox.Information)
progress.setStandardButtons(QMessageBox.NoButton)
progress.setWindowIcon(icon)
progress.setWindowTitle(window_title)
progress.setText("Please wait...")
progress.show()
app.processEvents() # type: ignore
shutil.move(oldBase, self.base)
progress.hide()
completion = QMessageBox()
completion.setIcon(QMessageBox.Information)
completion.setStandardButtons(QMessageBox.Ok)
completion.setWindowIcon(icon)
completion.setWindowTitle(window_title)
completion.setText("Migration complete. Please start Anki again.")
completion.show()
completion.exec()
else:
diag = QMessageBox()
diag.setIcon(QMessageBox.Warning)
diag.setWindowIcon(icon)
diag.setStandardButtons(QMessageBox.Ok)
diag.setWindowTitle(window_title)
diag.setText(
"Migration aborted. If you would like to keep the old folder location, please "
"see the Startup Options section of the manual. Anki will now quit."
)
diag.exec()
raise AnkiRestart(exitcode=0)
# Profile load/save
######################################################################