mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
set instance vars in __init__()
This commit is contained in:
parent
1da52f89fe
commit
b4b8717a20
11 changed files with 33 additions and 5 deletions
|
@ -96,6 +96,8 @@ class DeckManager:
|
|||
|
||||
def __init__(self, col):
|
||||
self.col = col
|
||||
self.decks = {}
|
||||
self.dconf = {}
|
||||
|
||||
def load(self, decks, dconf):
|
||||
self.decks = json.loads(decks)
|
||||
|
|
|
@ -19,6 +19,14 @@ class Anki2Importer(Importer):
|
|||
deckPrefix = None
|
||||
allowUpdate = True
|
||||
|
||||
def __init__(self, col, file):
|
||||
super().__init__(col, file)
|
||||
|
||||
# set later, defined here for typechecking
|
||||
self.src = None
|
||||
self._decks = {}
|
||||
self.mustResetLearning = False
|
||||
|
||||
def run(self, media=None):
|
||||
self._prepareFiles()
|
||||
if media is not None:
|
||||
|
|
|
@ -10,6 +10,12 @@ from anki.importing.anki2 import Anki2Importer
|
|||
|
||||
class AnkiPackageImporter(Anki2Importer):
|
||||
|
||||
def __init__(self, col, file):
|
||||
super().__init__(col, file)
|
||||
# set later; set here for typechecking
|
||||
self.nameToNum = {}
|
||||
self.zip = None
|
||||
|
||||
def run(self):
|
||||
# extract the deck from the zip file
|
||||
self.zip = z = zipfile.ZipFile(self.file)
|
||||
|
|
|
@ -14,12 +14,13 @@ class TextImporter(NoteImporter):
|
|||
needDelimiter = True
|
||||
patterns = ("\t", "|", ",", ";", ":")
|
||||
|
||||
def __init__(self, *args):
|
||||
NoteImporter.__init__(self, *args)
|
||||
def __init__(self, col, file):
|
||||
NoteImporter.__init__(self, col, file)
|
||||
self.lines = None
|
||||
self.fileobj = None
|
||||
self.delimiter = None
|
||||
self.tagsToAdd = []
|
||||
self.numFields = 0
|
||||
|
||||
def foreignNotes(self):
|
||||
self.open()
|
||||
|
|
|
@ -58,6 +58,7 @@ class NoteImporter(Importer):
|
|||
self.model = col.models.current()
|
||||
self.mapping = None
|
||||
self._deckMap = {}
|
||||
self._tagsMapped = False
|
||||
|
||||
def run(self):
|
||||
"Import."
|
||||
|
|
|
@ -78,10 +78,10 @@ class SupermemoXmlImporter(NoteImporter):
|
|||
Code should be upgrade to support importing of SM2006 exports.
|
||||
"""
|
||||
|
||||
def __init__(self, *args):
|
||||
def __init__(self, col, file):
|
||||
"""Initialize internal varables.
|
||||
Pameters to be exposed to GUI are stored in self.META"""
|
||||
NoteImporter.__init__(self, *args)
|
||||
NoteImporter.__init__(self, col, file)
|
||||
m = addBasicModel(self.col)
|
||||
m['name'] = "Supermemo"
|
||||
self.col.models.save(m)
|
||||
|
|
|
@ -77,6 +77,8 @@ class ModelManager:
|
|||
|
||||
def __init__(self, col):
|
||||
self.col = col
|
||||
self.models = {}
|
||||
self.changed = False
|
||||
|
||||
def load(self, json_):
|
||||
"Load registry from JSON."
|
||||
|
|
|
@ -10,6 +10,7 @@ class Note:
|
|||
def __init__(self, col, model=None, id=None):
|
||||
assert not (model and id)
|
||||
self.col = col
|
||||
self.newlyAdded = False
|
||||
if id:
|
||||
self.id = id
|
||||
self.load()
|
||||
|
|
|
@ -18,6 +18,7 @@ class CardStats:
|
|||
def __init__(self, col, card):
|
||||
self.col = col
|
||||
self.card = card
|
||||
self.txt = ""
|
||||
|
||||
def report(self):
|
||||
c = self.card
|
||||
|
|
|
@ -34,6 +34,11 @@ class Syncer:
|
|||
self.col = col
|
||||
self.server = server
|
||||
|
||||
# these are set later; provide dummy values for type checking
|
||||
self.lnewer = False
|
||||
self.maxUsn = 0
|
||||
self.tablesLeft = []
|
||||
|
||||
def sync(self):
|
||||
"Returns 'noChanges', 'fullSync', 'success', etc"
|
||||
self.syncMsg = ""
|
||||
|
@ -707,6 +712,7 @@ class MediaSyncer:
|
|||
def __init__(self, col, server=None):
|
||||
self.col = col
|
||||
self.server = server
|
||||
self.downloadCount = 0
|
||||
|
||||
def sync(self):
|
||||
# check if there have been any changes
|
||||
|
@ -726,7 +732,6 @@ class MediaSyncer:
|
|||
|
||||
# loop through and process changes from server
|
||||
self.col.log("last local usn is %s"%lastUsn)
|
||||
self.downloadCount = 0
|
||||
while True:
|
||||
data = self.server.mediaChanges(lastUsn=lastUsn)
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ class TagManager:
|
|||
|
||||
def __init__(self, col):
|
||||
self.col = col
|
||||
self.tags = {}
|
||||
|
||||
def load(self, json_):
|
||||
self.tags = json.loads(json_)
|
||||
|
|
Loading…
Reference in a new issue