diff --git a/anki/groups.py b/anki/groups.py index b59358059..712ab23fb 100644 --- a/anki/groups.py +++ b/anki/groups.py @@ -137,6 +137,9 @@ class GroupManager(object): assert gid != 1 if not str(gid) in self.groups: return + # delete children first + for name, id in self.children(gid): + self.rem(id, cardsToo) # delete cards too? if cardsToo: self.deck.remCards(self.cids(gid)) @@ -264,12 +267,18 @@ usn=?,mod=? where id in %s""" % ids2str(cids), # current group self.deck.conf['curGroup'] = gid # and active groups (current + all children) + actv = self.children(gid) + actv.sort() + self.deck.conf['activeGroups'] = [gid] + [a[1] for a in actv] + + def children(self, gid): + "All children of gid, as (name, id)." + name = self.get(gid)['name'] actv = [] for g in self.all(): if g['name'].startswith(name + "::"): actv.append((g['name'], g['id'])) - actv.sort() - self.deck.conf['activeGroups'] = [gid] + [a[1] for a in actv] + return actv def parents(self, gid): "All parents of gid." diff --git a/anki/importing/anki1.py b/anki/importing/anki1.py index 7f82d7307..d0fb1c6cb 100644 --- a/anki/importing/anki1.py +++ b/anki/importing/anki1.py @@ -26,7 +26,7 @@ class Anki1Importer(Anki2Importer): # merge deck.close() mdir = self.file.replace(".anki", ".media") - self.file = deck.path self.groupPrefix = os.path.basename(self.file).replace(".anki", "") + self.file = deck.path Anki2Importer.run(self, mdir) diff --git a/anki/importing/anki2.py b/anki/importing/anki2.py index 33a2bbe6c..98f41e91e 100644 --- a/anki/importing/anki2.py +++ b/anki/importing/anki2.py @@ -41,6 +41,8 @@ class Anki2Importer(Importer): self._importFacts() self._importCards() self._importMedia() + self.dst.db.execute("vacuum") + self.dst.db.execute("analyze") # Facts ###################################################################### @@ -109,6 +111,8 @@ class Anki2Importer(Importer): return dmid # need to add to local and update index m = self.dst.models._add(self.src.models.get(mid)) + # need to save so the css is updated + self.dst.models.save(m) h = self.dst.models.scmhash(m) mid = int(m['id']) self._dstModels[mid] = h diff --git a/anki/media.py b/anki/media.py index e6f2d8943..a50b0df30 100644 --- a/anki/media.py +++ b/anki/media.py @@ -168,6 +168,8 @@ If the same name exists, compare checksums.""" def copyTo(self, rdir): ldir = self.dir() + if not os.path.exists(ldir): + return for f in os.listdir(ldir): src = os.path.join(ldir, f) dst = os.path.join(rdir, f) diff --git a/anki/models.py b/anki/models.py index 40e144bbe..7db161975 100644 --- a/anki/models.py +++ b/anki/models.py @@ -94,7 +94,9 @@ class ModelManager(object): def current(self): "Get current model." try: - return self.get(self.deck.groups.top()['curModel']) + m = self.get(self.deck.groups.top()['curModel']) + assert m + return m except: return self.models.values()[0]