set instance vars in __init__()

This commit is contained in:
Damien Elmes 2019-12-16 17:49:32 +10:00
parent 1da52f89fe
commit b4b8717a20
11 changed files with 33 additions and 5 deletions

View file

@ -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)

View file

@ -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:

View file

@ -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)

View 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()

View file

@ -58,6 +58,7 @@ class NoteImporter(Importer):
self.model = col.models.current()
self.mapping = None
self._deckMap = {}
self._tagsMapped = False
def run(self):
"Import."

View file

@ -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)

View file

@ -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."

View file

@ -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()

View file

@ -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

View file

@ -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)

View file

@ -22,6 +22,7 @@ class TagManager:
def __init__(self, col):
self.col = col
self.tags = {}
def load(self, json_):
self.tags = json.loads(json_)