diff --git a/qt/aqt/__init__.py b/qt/aqt/__init__.py index 3e0ebd0b6..7ca034907 100644 --- a/qt/aqt/__init__.py +++ b/qt/aqt/__init__.py @@ -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() diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py index b72e2dd34..5cc57a4a0 100644 --- a/qt/aqt/profiles.py +++ b/qt/aqt/profiles.py @@ -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 ######################################################################