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): def __init__(self, col):
self.col = col self.col = col
self.decks = {}
self.dconf = {}
def load(self, decks, dconf): def load(self, decks, dconf):
self.decks = json.loads(decks) self.decks = json.loads(decks)

View file

@ -19,6 +19,14 @@ class Anki2Importer(Importer):
deckPrefix = None deckPrefix = None
allowUpdate = True 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): def run(self, media=None):
self._prepareFiles() self._prepareFiles()
if media is not None: if media is not None:

View file

@ -10,6 +10,12 @@ from anki.importing.anki2 import Anki2Importer
class AnkiPackageImporter(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): def run(self):
# extract the deck from the zip file # extract the deck from the zip file
self.zip = z = zipfile.ZipFile(self.file) self.zip = z = zipfile.ZipFile(self.file)

View file

@ -14,12 +14,13 @@ class TextImporter(NoteImporter):
needDelimiter = True needDelimiter = True
patterns = ("\t", "|", ",", ";", ":") patterns = ("\t", "|", ",", ";", ":")
def __init__(self, *args): def __init__(self, col, file):
NoteImporter.__init__(self, *args) NoteImporter.__init__(self, col, file)
self.lines = None self.lines = None
self.fileobj = None self.fileobj = None
self.delimiter = None self.delimiter = None
self.tagsToAdd = [] self.tagsToAdd = []
self.numFields = 0
def foreignNotes(self): def foreignNotes(self):
self.open() self.open()

View file

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

View file

@ -78,10 +78,10 @@ class SupermemoXmlImporter(NoteImporter):
Code should be upgrade to support importing of SM2006 exports. Code should be upgrade to support importing of SM2006 exports.
""" """
def __init__(self, *args): def __init__(self, col, file):
"""Initialize internal varables. """Initialize internal varables.
Pameters to be exposed to GUI are stored in self.META""" 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 = addBasicModel(self.col)
m['name'] = "Supermemo" m['name'] = "Supermemo"
self.col.models.save(m) self.col.models.save(m)

View file

@ -77,6 +77,8 @@ class ModelManager:
def __init__(self, col): def __init__(self, col):
self.col = col self.col = col
self.models = {}
self.changed = False
def load(self, json_): def load(self, json_):
"Load registry from JSON." "Load registry from JSON."

View file

@ -10,6 +10,7 @@ class Note:
def __init__(self, col, model=None, id=None): def __init__(self, col, model=None, id=None):
assert not (model and id) assert not (model and id)
self.col = col self.col = col
self.newlyAdded = False
if id: if id:
self.id = id self.id = id
self.load() self.load()

View file

@ -18,6 +18,7 @@ class CardStats:
def __init__(self, col, card): def __init__(self, col, card):
self.col = col self.col = col
self.card = card self.card = card
self.txt = ""
def report(self): def report(self):
c = self.card c = self.card

View file

@ -34,6 +34,11 @@ class Syncer:
self.col = col self.col = col
self.server = server self.server = server
# these are set later; provide dummy values for type checking
self.lnewer = False
self.maxUsn = 0
self.tablesLeft = []
def sync(self): def sync(self):
"Returns 'noChanges', 'fullSync', 'success', etc" "Returns 'noChanges', 'fullSync', 'success', etc"
self.syncMsg = "" self.syncMsg = ""
@ -707,6 +712,7 @@ class MediaSyncer:
def __init__(self, col, server=None): def __init__(self, col, server=None):
self.col = col self.col = col
self.server = server self.server = server
self.downloadCount = 0
def sync(self): def sync(self):
# check if there have been any changes # check if there have been any changes
@ -726,7 +732,6 @@ class MediaSyncer:
# loop through and process changes from server # loop through and process changes from server
self.col.log("last local usn is %s"%lastUsn) self.col.log("last local usn is %s"%lastUsn)
self.downloadCount = 0
while True: while True:
data = self.server.mediaChanges(lastUsn=lastUsn) data = self.server.mediaChanges(lastUsn=lastUsn)

View file

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