py/gadict_srs_anki.py
changeset 699 38ff2e2ffd5c
parent 698 5fc9bc68fb9c
child 713 c6cb8d720b51
equal deleted inserted replaced
698:5fc9bc68fb9c 699:38ff2e2ffd5c
    97         traceback.print_exc()
    97         traceback.print_exc()
    98     exit(1)
    98     exit(1)
    99 finally:
    99 finally:
   100     FIN.close()
   100     FIN.close()
   101 
   101 
       
   102 
   102 def cleanup(collection, tmpdir):
   103 def cleanup(collection, tmpdir):
   103     if collection:
   104     if collection:
   104         collection.close()
   105         collection.close()
   105     if tmpdir:
   106     if tmpdir:
   106         shutil.rmtree(tmpdir, ignore_errors=True)
   107         shutil.rmtree(tmpdir, ignore_errors=True)
   190   color: red;
   191   color: red;
   191   font-weight: bold;
   192   font-weight: bold;
   192 }
   193 }
   193 """
   194 """
   194 
   195 
       
   196 
   195 def note_add_tags(note, tags):
   197 def note_add_tags(note, tags):
   196     if isinstance(tags, str):       note.tags = [tags]
   198     if isinstance(tags, str):
   197     elif isinstance(tags, list):    note.tags = tags
   199         note.tags = [tags]
   198     elif tags is None:              pass
   200     elif isinstance(tags, list):
   199     else:                           raise Exception('Expecting string or list of tags...')
   201         note.tags = tags
       
   202     elif tags is None:
       
   203         pass
       
   204     else:
       
   205         raise Exception('Expecting string or list of tags...')
   200 
   206 
   201 
   207 
   202 class AnkiDbBuilder:
   208 class AnkiDbBuilder:
   203 
   209 
   204     def __init__(self, tmpdir, name):
   210     def __init__(self, tmpdir, name):
   319 
   325 
   320         model['id'] = model_id + 3          # Keep model['id'] unique.
   326         model['id'] = model_id + 3          # Keep model['id'] unique.
   321         collection.models.update(model)
   327         collection.models.update(model)
   322         collection.models.save(model)
   328         collection.models.save(model)
   323         self.model_pl = model
   329         self.model_pl = model
   324 
       
   325 
   330 
   326     def guid(self, nodetype, headword):
   331     def guid(self, nodetype, headword):
   327         """
   332         """
   328         :nodetype  used to generate different notes from same headword
   333         :nodetype  used to generate different notes from same headword
   329         """
   334         """
   369         export = AnkiPackageExporter(self.collection)
   374         export = AnkiPackageExporter(self.collection)
   370         export.exportInto(fname)
   375         export.exportInto(fname)
   371 
   376 
   372     def close(self):
   377     def close(self):
   373         self.collection.close()
   378         self.collection.close()
       
   379 
   374 
   380 
   375 def write_sense(buf, sense, with_examples=True):
   381 def write_sense(buf, sense, with_examples=True):
   376     buf.append("<div class='sense'>")
   382     buf.append("<div class='sense'>")
   377     if sense.pos:
   383     if sense.pos:
   378         buf.append("<span class='pos'>")
   384         buf.append("<span class='pos'>")