From 69a9425cd0e28ac2a60a982e88b9a16f02a3516b Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Mon, 6 Apr 2020 23:02:28 +0200 Subject: [PATCH] replace _path by path (because it's not private here) --- pylib/anki/decks.py | 30 ++++++++++++++++-------------- pylib/anki/importing/anki2.py | 4 ++-- pylib/anki/sched.py | 2 +- pylib/anki/schedv2.py | 4 ++-- pylib/anki/template.py | 2 +- qt/aqt/browser.py | 2 +- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/pylib/anki/decks.py b/pylib/anki/decks.py index 263906b41..24052084e 100644 --- a/pylib/anki/decks.py +++ b/pylib/anki/decks.py @@ -126,7 +126,7 @@ class DeckManager: # child of an existing deck then it needs to be renamed deck = self.get(did) if "::" in deck["name"]: - base = self._path(deck["name"])[-1] + base = self.path(deck["name"])[-1] suffix = "" while True: # find an unused name @@ -260,7 +260,7 @@ class DeckManager: ontoDeckName = self.get(ontoDeckDid)["name"] if ontoDeckDid is None or ontoDeckDid == "": - if len(self._path(draggedDeckName)) > 1: + if len(self.path(draggedDeckName)) > 1: self.rename(draggedDeck, self._basename(draggedDeckName)) elif self._canDragAndDrop(draggedDeckName, ontoDeckName): draggedDeck = self.get(draggedDeckDid) @@ -282,29 +282,31 @@ class DeckManager: return True def _isParent(self, parentDeckName: str, childDeckName: str) -> Any: - return self._path(childDeckName) == self._path(parentDeckName) + [ + return self.path(childDeckName) == self.path(parentDeckName) + [ self._basename(childDeckName) ] def _isAncestor(self, ancestorDeckName: str, descendantDeckName: str) -> Any: - ancestorPath = self._path(ancestorDeckName) - return ancestorPath == self._path(descendantDeckName)[0 : len(ancestorPath)] + ancestorPath = self.path(ancestorDeckName) + return ancestorPath == self.path(descendantDeckName)[0 : len(ancestorPath)] @staticmethod - def _path(name: str) -> Any: + def path(name: str) -> Any: return name.split("::") + _path = path + def _basename(self, name: str) -> Any: - return self._path(name)[-1] + return self.path(name)[-1] @classmethod def key(cls, deck: Dict[str, Any]) -> List[str]: - return cls._path(deck["name"]) + return cls.path(deck["name"]) def _ensureParents(self, name: str) -> Any: "Ensure parents exist, and return name with case matching parents." s = "" - path = self._path(name) + path = self.path(name) if len(path) < 2: return name for p in path[:-1]: @@ -469,14 +471,14 @@ class DeckManager: self.save(deck) # ensure no sections are blank - if not all(self._path(deck["name"])): + if not all(self.path(deck["name"])): self.col.log("fix deck with missing sections", deck["name"]) deck["name"] = "recovered%d" % intTime(1000) self.save(deck) # immediate parent must exist if "::" in deck["name"]: - immediateParent = "::".join(self._path(deck["name"])[:-1]) + immediateParent = "::".join(self.path(deck["name"])[:-1]) if immediateParent not in names: self.col.log("fix deck with missing parent", deck["name"]) self._ensureParents(deck["name"]) @@ -579,7 +581,7 @@ class DeckManager: childMap[deck["id"]] = node # add note to immediate parent - parts = self._path(deck["name"]) + parts = self.path(deck["name"]) if len(parts) > 1: immediateParent = "::".join(parts[:-1]) pid = nameMap[immediateParent]["id"] @@ -591,7 +593,7 @@ class DeckManager: "All parents of did." # get parent and grandparent names parents: List[str] = [] - for part in self._path(self.get(did)["name"])[:-1]: + for part in self.path(self.get(did)["name"])[:-1]: if not parents: parents.append(part) else: @@ -609,7 +611,7 @@ class DeckManager: "All existing parents of name" if "::" not in name: return [] - names = self._path(name)[:-1] + names = self.path(name)[:-1] head = [] parents = [] diff --git a/pylib/anki/importing/anki2.py b/pylib/anki/importing/anki2.py index 33a92fd58..3ab83098a 100644 --- a/pylib/anki/importing/anki2.py +++ b/pylib/anki/importing/anki2.py @@ -258,13 +258,13 @@ class Anki2Importer(Importer): name = g["name"] # if there's a prefix, replace the top level deck if self.deckPrefix: - tmpname = "::".join(DeckManager._path(name)[1:]) + tmpname = "::".join(DeckManager.path(name)[1:]) name = self.deckPrefix if tmpname: name += "::" + tmpname # manually create any parents so we can pull in descriptions head = "" - for parent in DeckManager._path(name)[:-1]: + for parent in DeckManager.path(name)[:-1]: if head: head += "::" head += parent diff --git a/pylib/anki/sched.py b/pylib/anki/sched.py index 3d79e1b69..272b0bf9c 100644 --- a/pylib/anki/sched.py +++ b/pylib/anki/sched.py @@ -154,7 +154,7 @@ class Scheduler(V2): data = [] def parent(name): - parts = DeckManager._path(name) + parts = DeckManager.path(name) if len(parts) < 2: return None parts = parts[:-1] diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index f787142b0..e437a4d4a 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -241,7 +241,7 @@ order by due""" data = [] def parent(name): - parts = DeckManager._path(name) + parts = DeckManager.path(name) if len(parts) < 2: return None parts = parts[:-1] @@ -280,7 +280,7 @@ order by due""" def _groupChildren(self, grps: List[List[Any]]) -> Any: # first, split the group names into components for g in grps: - g[0] = DeckManager._path(g[0]) + g[0] = DeckManager.path(g[0]) # and sort based on those components grps.sort(key=itemgetter(0)) # then run main function diff --git a/pylib/anki/template.py b/pylib/anki/template.py index 06e198844..5ed110441 100644 --- a/pylib/anki/template.py +++ b/pylib/anki/template.py @@ -154,7 +154,7 @@ def fields_for_rendering( fields["Tags"] = note.stringTags().strip() fields["Type"] = card.note_type()["name"] fields["Deck"] = col.decks.name(card.odid or card.did) - fields["Subdeck"] = DeckManager._path(fields["Deck"])[-1] + fields["Subdeck"] = DeckManager.path(fields["Deck"])[-1] fields["Card"] = card.template()["name"] flag = card.userFlag() fields["CardFlag"] = flag and f"flag{flag}" or "" diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 2dbb60aeb..1b487bb07 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -1303,7 +1303,7 @@ QTableView {{ gridline-color: {grid} }} def addDecks(parent, decks): for head, did, rev, lrn, new, children in decks: name = self.mw.col.decks.get(did)["name"] - shortname = DeckManager._path(name)[-1] + shortname = DeckManager.path(name)[-1] if children: subm = parent.addMenu(shortname) subm.addItem(_("Filter"), self._filterFunc("deck", name))