mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Revert "Merge pull request #610 from evandroforks/ask_confirmation_before_moving_anki_collection"
This reverts commita53aac40f8
, reversing changes made toe323a8f902
. Migration is about to be dropped (#1390), and the references to modules like QtGui complicate a PyQt5/6 shim.
This commit is contained in:
parent
aaceeec25a
commit
c39a5e17e8
2 changed files with 1 additions and 78 deletions
|
@ -54,7 +54,7 @@ appUpdate = "https://ankiweb.net/update/desktop"
|
||||||
appHelpSite = HELP_SITE
|
appHelpSite = HELP_SITE
|
||||||
|
|
||||||
from aqt.main import AnkiQt # isort:skip
|
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
|
profiler: Optional[cProfile.Profile] = None
|
||||||
mw: Optional[AnkiQt] = None # set on init
|
mw: Optional[AnkiQt] = None # set on init
|
||||||
|
@ -498,10 +498,6 @@ def _run(argv: Optional[list[str]] = None, exec: bool = True) -> Optional[AnkiAp
|
||||||
try:
|
try:
|
||||||
pm = ProfileManager(opts.base)
|
pm = ProfileManager(opts.base)
|
||||||
pmLoadResult = pm.setupMeta()
|
pmLoadResult = pm.setupMeta()
|
||||||
except AnkiRestart as error:
|
|
||||||
if error.exitcode:
|
|
||||||
sys.exit(error.exitcode)
|
|
||||||
return None
|
|
||||||
except:
|
except:
|
||||||
# will handle below
|
# will handle below
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
|
@ -111,12 +111,6 @@ class LoadMetaResult:
|
||||||
loadError: bool
|
loadError: bool
|
||||||
|
|
||||||
|
|
||||||
class AnkiRestart(SystemExit):
|
|
||||||
def __init__(self, exitcode: int = 0) -> None:
|
|
||||||
self.exitcode = exitcode
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
|
|
||||||
class ProfileManager:
|
class ProfileManager:
|
||||||
def __init__(self, base: str | None = None) -> None: #
|
def __init__(self, base: str | None = None) -> None: #
|
||||||
## Settings which should be forgotten each Anki restart
|
## Settings which should be forgotten each Anki restart
|
||||||
|
@ -170,77 +164,10 @@ class ProfileManager:
|
||||||
return os.path.expanduser("~/Documents/Anki")
|
return os.path.expanduser("~/Documents/Anki")
|
||||||
|
|
||||||
def maybeMigrateFolder(self) -> None:
|
def maybeMigrateFolder(self) -> None:
|
||||||
newBase = self.base
|
|
||||||
oldBase = self._oldFolderLocation()
|
oldBase = self._oldFolderLocation()
|
||||||
|
|
||||||
if oldBase and not os.path.exists(self.base) and os.path.isdir(oldBase):
|
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)
|
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
|
# Profile load/save
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
Loading…
Reference in a new issue