From 09651be9e7fc50eb2a8a5283215fc5938f3da724 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 6 Mar 2019 15:27:13 +1000 Subject: [PATCH] check a profile exists every time if something went wrong between pm.meta() and .ensureProfile() in the past, it would lead to an inability to start Anki due to the a lack of any profiles https://anki.tenderapp.com/discussions/ankidesktop/32972-linux-upgrade-problems-20-219 --- aqt/__init__.py | 3 --- aqt/profiles.py | 21 +++++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/aqt/__init__.py b/aqt/__init__.py index 05d70af0b..ae64af076 100644 --- a/aqt/__init__.py +++ b/aqt/__init__.py @@ -349,9 +349,6 @@ environment points to a valid, writable folder.""") QMessageBox.critical(None, "Error", "Your video driver is incompatible. Please start Anki again, and Anki will switch to a slower, more compatible mode.") sys.exit(1) - # remaining pm init - pm.ensureProfile() - # load the main window import aqt.main mw = aqt.main.AnkiQt(app, pm, opts, args) diff --git a/aqt/profiles.py b/aqt/profiles.py index 2a613591d..1fdf6fda6 100644 --- a/aqt/profiles.py +++ b/aqt/profiles.py @@ -126,9 +126,15 @@ a flash drive.""" % self.base) ###################################################################### def profiles(self): - return sorted(x for x in - self.db.list("select name from profiles") - if x != "_global") + def names(): + return self.db.list("select name from profiles where name != '_global'") + + n = names() + if not n: + self._ensureProfile() + n = names() + + return n def _unpickle(self, data): class Unpickler(pickle.Unpickler): @@ -338,12 +344,11 @@ create table if not exists profiles self._setDefaultLang() return True - def ensureProfile(self): + def _ensureProfile(self): "Create a new profile if none exists." - if self.firstRun: - self.create(_("User 1")) - p = os.path.join(self.base, "README.txt") - open(p, "w", encoding="utf8").write(_("""\ + self.create(_("User 1")) + p = os.path.join(self.base, "README.txt") + open(p, "w", encoding="utf8").write(_("""\ This folder stores all of your Anki data in a single location, to make backups easy. To tell Anki to use a different location, please see: