mirror of
https://github.com/ankitects/anki.git
synced 2025-11-09 14:17:13 -05:00
remove self explanatory module docstrings; strip trailing whitespace
This commit is contained in:
parent
9f55c831c0
commit
9421a037f6
25 changed files with 45 additions and 193 deletions
|
|
@ -28,7 +28,7 @@ Edit the card:
|
||||||
|
|
||||||
fields = card.fact.model.fieldModels
|
fields = card.fact.model.fieldModels
|
||||||
for field in fields:
|
for field in fields:
|
||||||
card.fact[field.name] = "newvalue"
|
card.fact[field.name] = 'newvalue'
|
||||||
card.fact.setModified(textChanged=True, deck=deck)
|
card.fact.setModified(textChanged=True, deck=deck)
|
||||||
deck.setModified()
|
deck.setModified()
|
||||||
|
|
||||||
|
|
@ -46,7 +46,6 @@ Save & close:
|
||||||
deck.save()
|
deck.save()
|
||||||
deck.close()
|
deck.close()
|
||||||
"""
|
"""
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
__import__('pkg_resources').declare_namespace(__name__)
|
__import__('pkg_resources').declare_namespace(__name__)
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Cards
|
|
||||||
====================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import time, sys, math, random
|
import time, sys, math, random
|
||||||
from anki.db import *
|
from anki.db import *
|
||||||
from anki.models import CardModel, Model, FieldModel, formatQA
|
from anki.models import CardModel, Model, FieldModel, formatQA
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ object_session() is a replacement for the standard object_session(), which
|
||||||
provides the features of SessionHelper, and avoids taking out another
|
provides the features of SessionHelper, and avoids taking out another
|
||||||
transaction.
|
transaction.
|
||||||
"""
|
"""
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from pysqlite2 import dbapi2 as sqlite
|
from pysqlite2 import dbapi2 as sqlite
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
The Deck
|
|
||||||
====================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import tempfile, time, os, random, sys, re, stat, shutil
|
import tempfile, time, os, random, sys, re, stat, shutil
|
||||||
import types, traceback, simplejson, datetime
|
import types, traceback, simplejson, datetime
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Errors
|
|
||||||
==============================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
def __init__(self, message="", **data):
|
def __init__(self, message="", **data):
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Exporting support
|
|
||||||
==============================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import itertools, time, re, os, HTMLParser
|
import itertools, time, re, os, HTMLParser
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from anki import DeckStorage
|
from anki import DeckStorage
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Facts
|
|
||||||
========
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from anki.db import *
|
from anki.db import *
|
||||||
from anki.errors import *
|
from anki.errors import *
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Fonts - mapping to/from platform-specific fonts
|
|
||||||
==============================================================
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# set this to 'all', to get all fonts in a list
|
# set this to 'all', to get all fonts in a list
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Graphs of deck statistics
|
|
||||||
==============================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import os, sys, time
|
import os, sys, time
|
||||||
import anki.stats
|
import anki.stats
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
History - keeping a record of all reviews
|
|
||||||
==========================================
|
|
||||||
|
|
||||||
If users run 'check db', duplicate records will be inserted into the DB - I
|
|
||||||
really should have used the time stamp as the key. You can remove them by
|
|
||||||
keeping the lowest id for any given timestamp.
|
|
||||||
"""
|
|
||||||
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from anki.db import *
|
from anki.db import *
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@ may be extended by calling code if a file has more fields. To ignore a
|
||||||
particular FieldModel, replace it with None. A special number 0 donates a tags
|
particular FieldModel, replace it with None. A special number 0 donates a tags
|
||||||
field. The same field model should not occur more than once."""
|
field. The same field model should not occur more than once."""
|
||||||
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from anki.cards import cardsTable
|
from anki.cards import cardsTable
|
||||||
from anki.facts import factsTable, fieldsTable
|
from anki.facts import factsTable, fieldsTable
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Importing Anki 0.9+ decks
|
|
||||||
==========================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
from anki import DeckStorage
|
from anki import DeckStorage
|
||||||
from anki.importing import Importer
|
from anki.importing import Importer
|
||||||
from anki.sync import SyncClient, SyncServer, copyLocalMedia
|
from anki.sync import SyncClient, SyncServer, copyLocalMedia
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Importing CSV/TSV files
|
|
||||||
========================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import codecs, csv, re
|
import codecs, csv, re
|
||||||
from anki.importing import Importer, ForeignCard
|
from anki.importing import Importer, ForeignCard
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Importing Mnemosyne 1.0 decks
|
|
||||||
==============================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import sys, pickle, time, re
|
import sys, pickle, time, re
|
||||||
from anki.importing import Importer, ForeignCard
|
from anki.importing import Importer, ForeignCard
|
||||||
from anki.errors import *
|
from anki.errors import *
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: petr.michalec@gmail.com
|
# Copyright: petr.michalec@gmail.com
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Importing Supermemo XML decks
|
|
||||||
==============================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from anki.importing import Importer, ForeignCard
|
from anki.importing import Importer, ForeignCard
|
||||||
|
|
@ -24,16 +18,16 @@ import re, unicodedata, time
|
||||||
from anki.deck import Deck
|
from anki.deck import Deck
|
||||||
|
|
||||||
class SmartDict(dict):
|
class SmartDict(dict):
|
||||||
"""
|
"""
|
||||||
See http://www.peterbe.com/plog/SmartDict
|
See http://www.peterbe.com/plog/SmartDict
|
||||||
Copyright 2005, Peter Bengtsson, peter@fry-it.com
|
Copyright 2005, Peter Bengtsson, peter@fry-it.com
|
||||||
|
|
||||||
A smart dict can be instanciated either from a pythonic dict
|
A smart dict can be instanciated either from a pythonic dict
|
||||||
or an instance object (eg. SQL recordsets) but it ensures that you can
|
or an instance object (eg. SQL recordsets) but it ensures that you can
|
||||||
do all the convenient lookups such as x.first_name, x['first_name'] or
|
do all the convenient lookups such as x.first_name, x['first_name'] or
|
||||||
x.get('first_name').
|
x.get('first_name').
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, *a, **kw):
|
def __init__(self, *a, **kw):
|
||||||
if a:
|
if a:
|
||||||
if type(a[0]) is DictType:
|
if type(a[0]) is DictType:
|
||||||
|
|
@ -42,10 +36,10 @@ class SmartDict(dict):
|
||||||
kw.update(a[0].__dict__)
|
kw.update(a[0].__dict__)
|
||||||
elif hasattr(a[0], '__class__') and a[0].__class__.__name__=='SmartDict':
|
elif hasattr(a[0], '__class__') and a[0].__class__.__name__=='SmartDict':
|
||||||
kw.update(a[0].__dict__)
|
kw.update(a[0].__dict__)
|
||||||
|
|
||||||
dict.__init__(self, **kw)
|
dict.__init__(self, **kw)
|
||||||
self.__dict__ = self
|
self.__dict__ = self
|
||||||
|
|
||||||
class SuperMemoElement(SmartDict):
|
class SuperMemoElement(SmartDict):
|
||||||
"SmartDict wrapper to store SM Element data"
|
"SmartDict wrapper to store SM Element data"
|
||||||
|
|
||||||
|
|
@ -72,14 +66,14 @@ class SuperMemoElement(SmartDict):
|
||||||
class SupermemoXmlImporter(Importer):
|
class SupermemoXmlImporter(Importer):
|
||||||
"""
|
"""
|
||||||
Supermemo XML export's to Anki parser.
|
Supermemo XML export's to Anki parser.
|
||||||
Goes through a SM collection and fetch all elements.
|
Goes through a SM collection and fetch all elements.
|
||||||
|
|
||||||
My SM collection was a big mess where topics and items were mixed.
|
My SM collection was a big mess where topics and items were mixed.
|
||||||
I was unable to parse my content in a regular way like for loop on
|
I was unable to parse my content in a regular way like for loop on
|
||||||
minidom.getElementsByTagName() etc. My collection had also an
|
minidom.getElementsByTagName() etc. My collection had also an
|
||||||
limitation, topics were splited into branches with max 100 items
|
limitation, topics were splited into branches with max 100 items
|
||||||
on each. Learning themes were in deep structure. I wanted to have
|
on each. Learning themes were in deep structure. I wanted to have
|
||||||
full title on each element to be stored in tags.
|
full title on each element to be stored in tags.
|
||||||
|
|
||||||
Code should be upgrade to support importing of SM2006 exports.
|
Code should be upgrade to support importing of SM2006 exports.
|
||||||
"""
|
"""
|
||||||
|
|
@ -133,13 +127,13 @@ class SupermemoXmlImporter(Importer):
|
||||||
def _decode_htmlescapes(self,s):
|
def _decode_htmlescapes(self,s):
|
||||||
"""Unescape HTML code."""
|
"""Unescape HTML code."""
|
||||||
#In case of bad formated html you can import MinimalSoup etc.. see btflsoup source code
|
#In case of bad formated html you can import MinimalSoup etc.. see btflsoup source code
|
||||||
from BeautifulSoup import BeautifulStoneSoup as btflsoup
|
from BeautifulSoup import BeautifulStoneSoup as btflsoup
|
||||||
|
|
||||||
#my sm2004 also ecaped & char in escaped sequences.
|
#my sm2004 also ecaped & char in escaped sequences.
|
||||||
s = re.sub(u'&',u'&',s)
|
s = re.sub(u'&',u'&',s)
|
||||||
#unescaped solitary chars < or > that were ok for minidom confuse btfl soup
|
#unescaped solitary chars < or > that were ok for minidom confuse btfl soup
|
||||||
s = re.sub(u'>',u'>',s)
|
s = re.sub(u'>',u'>',s)
|
||||||
s = re.sub(u'<',u'<',s)
|
s = re.sub(u'<',u'<',s)
|
||||||
|
|
||||||
return unicode(btflsoup(s,convertEntities=btflsoup.HTML_ENTITIES ))
|
return unicode(btflsoup(s,convertEntities=btflsoup.HTML_ENTITIES ))
|
||||||
|
|
||||||
|
|
@ -148,7 +142,7 @@ class SupermemoXmlImporter(Importer):
|
||||||
"""Note: This method is not used, BeautifulSoup does better job.
|
"""Note: This method is not used, BeautifulSoup does better job.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self._unescape_trtable == None:
|
if self._unescape_trtable == None:
|
||||||
self._unescape_trtable = (
|
self._unescape_trtable = (
|
||||||
('€',u'€'), (' ',u' '), ('!',u'!'), ('"',u'"'), ('#',u'#'), ('$',u'$'), ('%',u'%'), ('&',u'&'), (''',u"'"),
|
('€',u'€'), (' ',u' '), ('!',u'!'), ('"',u'"'), ('#',u'#'), ('$',u'$'), ('%',u'%'), ('&',u'&'), (''',u"'"),
|
||||||
('(',u'('), (')',u')'), ('*',u'*'), ('+',u'+'), (',',u','), ('-',u'-'), ('.',u'.'), ('/',u'/'), ('0',u'0'),
|
('(',u'('), (')',u')'), ('*',u'*'), ('+',u'+'), (',',u','), ('-',u'-'), ('.',u'.'), ('/',u'/'), ('0',u'0'),
|
||||||
|
|
@ -195,7 +189,7 @@ class SupermemoXmlImporter(Importer):
|
||||||
('Ū',u'Ū'), ('ū',u'ū'), ('Ŭ',u'Ŭ'), ('ŭ',u'ŭ'), ('Ů',u'Ů'), ('ů',u'ů'), ('Ű',u'Ű'), ('ű',u'ű'),
|
('Ū',u'Ū'), ('ū',u'ū'), ('Ŭ',u'Ŭ'), ('ŭ',u'ŭ'), ('Ů',u'Ů'), ('ů',u'ů'), ('Ű',u'Ű'), ('ű',u'ű'),
|
||||||
('Ų',u'Ų'), ('ų',u'ų'), ('Ŵ',u'Ŵ'), ('ŵ',u'ŵ'), ('Ŷ',u'Ŷ'), ('ŷ',u'ŷ'), ('Ÿ',u'Ÿ'), ('Ź',u'Ź'),
|
('Ų',u'Ų'), ('ų',u'ų'), ('Ŵ',u'Ŵ'), ('ŵ',u'ŵ'), ('Ŷ',u'Ŷ'), ('ŷ',u'ŷ'), ('Ÿ',u'Ÿ'), ('Ź',u'Ź'),
|
||||||
('ź',u'ź'), ('Ż',u'Ż'), ('ż',u'ż'), ('Ž',u'Ž'), ('ž',u'ž'), ('ſ',u'ſ'),
|
('ź',u'ź'), ('Ż',u'Ż'), ('ż',u'ż'), ('Ž',u'Ž'), ('ž',u'ž'), ('ſ',u'ſ'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
#m = re.match()
|
#m = re.match()
|
||||||
|
|
@ -213,7 +207,7 @@ class SupermemoXmlImporter(Importer):
|
||||||
self.logger(u'Parsing started.')
|
self.logger(u'Parsing started.')
|
||||||
self.parse()
|
self.parse()
|
||||||
self.logger(u'Parsing done.')
|
self.logger(u'Parsing done.')
|
||||||
|
|
||||||
# Return imported cards
|
# Return imported cards
|
||||||
return self.cards
|
return self.cards
|
||||||
|
|
||||||
|
|
@ -236,8 +230,8 @@ class SupermemoXmlImporter(Importer):
|
||||||
# pre-process scheduling data
|
# pre-process scheduling data
|
||||||
tLastrep = time.mktime(time.strptime(item.LastRepetition, '%d.%m.%Y'))
|
tLastrep = time.mktime(time.strptime(item.LastRepetition, '%d.%m.%Y'))
|
||||||
tToday = time.time()
|
tToday = time.time()
|
||||||
|
|
||||||
# convert learning data
|
# convert learning data
|
||||||
if not self.META.resetLearningData:
|
if not self.META.resetLearningData:
|
||||||
# migration of LearningData algorithm
|
# migration of LearningData algorithm
|
||||||
card.interval = item.Interval
|
card.interval = item.Interval
|
||||||
|
|
@ -270,7 +264,7 @@ class SupermemoXmlImporter(Importer):
|
||||||
if tTaggTitle or self.META.tagAllTopics:
|
if tTaggTitle or self.META.tagAllTopics:
|
||||||
# normalize - remove diacritic punctuation from unicode chars to ascii
|
# normalize - remove diacritic punctuation from unicode chars to ascii
|
||||||
item.lTitle = [ self._unicode2ascii(topic) for topic in item.lTitle]
|
item.lTitle = [ self._unicode2ascii(topic) for topic in item.lTitle]
|
||||||
|
|
||||||
# Transfrom xyz / aaa / bbb / ccc on Title path to Tag xyzAaaBbbCcc
|
# Transfrom xyz / aaa / bbb / ccc on Title path to Tag xyzAaaBbbCcc
|
||||||
# clean things like [999] or [111-2222] from title path, example: xyz / [1000-1200] zyx / xyz
|
# clean things like [999] or [111-2222] from title path, example: xyz / [1000-1200] zyx / xyz
|
||||||
# clean whitespaces
|
# clean whitespaces
|
||||||
|
|
@ -302,27 +296,27 @@ class SupermemoXmlImporter(Importer):
|
||||||
|
|
||||||
|
|
||||||
# OPEN AND LOAD
|
# OPEN AND LOAD
|
||||||
def openAnything(self,source):
|
def openAnything(self,source):
|
||||||
"Open any source / actually only openig of files is used"
|
"Open any source / actually only openig of files is used"
|
||||||
|
|
||||||
if source == "-":
|
if source == "-":
|
||||||
return sys.stdin
|
return sys.stdin
|
||||||
|
|
||||||
# try to open with urllib (if source is http, ftp, or file URL)
|
# try to open with urllib (if source is http, ftp, or file URL)
|
||||||
import urllib
|
import urllib
|
||||||
try:
|
try:
|
||||||
return urllib.urlopen(source)
|
return urllib.urlopen(source)
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# try to open with native open function (if source is pathname)
|
# try to open with native open function (if source is pathname)
|
||||||
try:
|
try:
|
||||||
return open(source)
|
return open(source)
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# treat source as string
|
# treat source as string
|
||||||
import StringIO
|
import StringIO
|
||||||
return StringIO.StringIO(str(source))
|
return StringIO.StringIO(str(source))
|
||||||
|
|
||||||
def loadSource(self, source):
|
def loadSource(self, source):
|
||||||
|
|
@ -336,7 +330,7 @@ class SupermemoXmlImporter(Importer):
|
||||||
|
|
||||||
|
|
||||||
# PARSE
|
# PARSE
|
||||||
def parse(self, node=None):
|
def parse(self, node=None):
|
||||||
"Parse method - parses document elements"
|
"Parse method - parses document elements"
|
||||||
|
|
||||||
if node==None and self.xmldoc<>None:
|
if node==None and self.xmldoc<>None:
|
||||||
|
|
@ -349,12 +343,12 @@ class SupermemoXmlImporter(Importer):
|
||||||
else:
|
else:
|
||||||
self.logger(u'No handler for method %s' % _method, level=3)
|
self.logger(u'No handler for method %s' % _method, level=3)
|
||||||
|
|
||||||
def parse_Document(self, node):
|
def parse_Document(self, node):
|
||||||
"Parse XML document"
|
"Parse XML document"
|
||||||
|
|
||||||
self.parse(node.documentElement)
|
self.parse(node.documentElement)
|
||||||
|
|
||||||
def parse_Element(self, node):
|
def parse_Element(self, node):
|
||||||
"Parse XML element"
|
"Parse XML element"
|
||||||
|
|
||||||
_method = "do_%s" % node.tagName
|
_method = "do_%s" % node.tagName
|
||||||
|
|
@ -365,7 +359,7 @@ class SupermemoXmlImporter(Importer):
|
||||||
self.logger(u'No handler for method %s' % _method, level=3)
|
self.logger(u'No handler for method %s' % _method, level=3)
|
||||||
#print traceback.print_exc()
|
#print traceback.print_exc()
|
||||||
|
|
||||||
def parse_Text(self, node):
|
def parse_Text(self, node):
|
||||||
"Parse text inside elements. Text is stored into local buffer."
|
"Parse text inside elements. Text is stored into local buffer."
|
||||||
|
|
||||||
text = node.data
|
text = node.data
|
||||||
|
|
@ -379,12 +373,12 @@ class SupermemoXmlImporter(Importer):
|
||||||
|
|
||||||
|
|
||||||
# DO
|
# DO
|
||||||
def do_SuperMemoCollection(self, node):
|
def do_SuperMemoCollection(self, node):
|
||||||
"Process SM Collection"
|
"Process SM Collection"
|
||||||
|
|
||||||
for child in node.childNodes: self.parse(child)
|
for child in node.childNodes: self.parse(child)
|
||||||
|
|
||||||
def do_SuperMemoElement(self, node):
|
def do_SuperMemoElement(self, node):
|
||||||
"Process SM Element (Type - Title,Topics)"
|
"Process SM Element (Type - Title,Topics)"
|
||||||
|
|
||||||
self.logger('='*45, level=3)
|
self.logger('='*45, level=3)
|
||||||
|
|
@ -407,7 +401,7 @@ class SupermemoXmlImporter(Importer):
|
||||||
# if smel.Lapses != None and smel.Interval != None and smel.Question != None and smel.Answer != None:
|
# if smel.Lapses != None and smel.Interval != None and smel.Question != None and smel.Answer != None:
|
||||||
if smel.Title == None and smel.Question != None and smel.Answer != None:
|
if smel.Title == None and smel.Question != None and smel.Answer != None:
|
||||||
if smel.Answer.strip() !='' and smel.Question.strip() !='':
|
if smel.Answer.strip() !='' and smel.Question.strip() !='':
|
||||||
|
|
||||||
# migrate only memorized otherway skip/continue
|
# migrate only memorized otherway skip/continue
|
||||||
if self.META.onlyMemorizedItems and not(int(smel.Interval) > 0):
|
if self.META.onlyMemorizedItems and not(int(smel.Interval) > 0):
|
||||||
self.logger(u'Element skiped \t- not memorized ...', level=3)
|
self.logger(u'Element skiped \t- not memorized ...', level=3)
|
||||||
|
|
@ -425,7 +419,7 @@ class SupermemoXmlImporter(Importer):
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# now we know that item was topic
|
# now we know that item was topic
|
||||||
# parseing of whole node is now finished
|
# parseing of whole node is now finished
|
||||||
|
|
||||||
# test if it's really topic
|
# test if it's really topic
|
||||||
|
|
@ -434,31 +428,31 @@ class SupermemoXmlImporter(Importer):
|
||||||
t = self.cntMeta['title'].pop()
|
t = self.cntMeta['title'].pop()
|
||||||
self.logger(u'End of topic \t- %s' % (t), level=2)
|
self.logger(u'End of topic \t- %s' % (t), level=2)
|
||||||
|
|
||||||
def do_Content(self, node):
|
def do_Content(self, node):
|
||||||
"Process SM element Content"
|
"Process SM element Content"
|
||||||
|
|
||||||
for child in node.childNodes:
|
for child in node.childNodes:
|
||||||
if hasattr(child,'tagName') and child.firstChild != None:
|
if hasattr(child,'tagName') and child.firstChild != None:
|
||||||
self.cntElm[-1][child.tagName]=child.firstChild.data
|
self.cntElm[-1][child.tagName]=child.firstChild.data
|
||||||
|
|
||||||
def do_LearningData(self, node):
|
def do_LearningData(self, node):
|
||||||
"Process SM element LearningData"
|
"Process SM element LearningData"
|
||||||
|
|
||||||
for child in node.childNodes:
|
for child in node.childNodes:
|
||||||
if hasattr(child,'tagName') and child.firstChild != None:
|
if hasattr(child,'tagName') and child.firstChild != None:
|
||||||
self.cntElm[-1][child.tagName]=child.firstChild.data
|
self.cntElm[-1][child.tagName]=child.firstChild.data
|
||||||
|
|
||||||
# It's being processed in do_Content now
|
# It's being processed in do_Content now
|
||||||
#def do_Question(self, node):
|
#def do_Question(self, node):
|
||||||
# for child in node.childNodes: self.parse(child)
|
# for child in node.childNodes: self.parse(child)
|
||||||
# self.cntElm[-1][node.tagName]=self.cntBuf.pop()
|
# self.cntElm[-1][node.tagName]=self.cntBuf.pop()
|
||||||
|
|
||||||
# It's being processed in do_Content now
|
# It's being processed in do_Content now
|
||||||
#def do_Answer(self, node):
|
#def do_Answer(self, node):
|
||||||
# for child in node.childNodes: self.parse(child)
|
# for child in node.childNodes: self.parse(child)
|
||||||
# self.cntElm[-1][node.tagName]=self.cntBuf.pop()
|
# self.cntElm[-1][node.tagName]=self.cntBuf.pop()
|
||||||
|
|
||||||
def do_Title(self, node):
|
def do_Title(self, node):
|
||||||
"Process SM element Title"
|
"Process SM element Title"
|
||||||
|
|
||||||
t = self._decode_htmlescapes(node.firstChild.data)
|
t = self._decode_htmlescapes(node.firstChild.data)
|
||||||
|
|
@ -468,7 +462,7 @@ class SupermemoXmlImporter(Importer):
|
||||||
self.logger(u'Start of topic \t- ' + u" / ".join(self.cntMeta['title']), level=2)
|
self.logger(u'Start of topic \t- ' + u" / ".join(self.cntMeta['title']), level=2)
|
||||||
|
|
||||||
|
|
||||||
def do_Type(self, node):
|
def do_Type(self, node):
|
||||||
"Process SM element Type"
|
"Process SM element Type"
|
||||||
|
|
||||||
if len(self.cntBuf) >=1 :
|
if len(self.cntBuf) >=1 :
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Author Chris Aakre <caaakre@gmail.com>
|
# Author Chris Aakre <caaakre@gmail.com>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Importing WCU files
|
|
||||||
====================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import codecs
|
import codecs
|
||||||
from anki.importing import Importer, ForeignCard
|
from anki.importing import Importer, ForeignCard
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Internationalisation
|
|
||||||
=====================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
import gettext
|
import gettext
|
||||||
import threading
|
import threading
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Latex support
|
|
||||||
==============================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import re, tempfile, os, sys, shutil, cgi, subprocess
|
import re, tempfile, os, sys, shutil, cgi, subprocess
|
||||||
from anki.utils import genID, checksum, call
|
from anki.utils import genID, checksum, call
|
||||||
from anki.hooks import addHook
|
from anki.hooks import addHook
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Media support
|
|
||||||
====================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import os, shutil, re, urllib2, time, tempfile, unicodedata, urllib
|
import os, shutil, re, urllib2, time, tempfile, unicodedata, urllib
|
||||||
from anki.db import *
|
from anki.db import *
|
||||||
from anki.utils import checksum, genID
|
from anki.utils import checksum, genID
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Model - define the way in which facts are added and shown
|
|
||||||
==========================================================
|
|
||||||
|
|
||||||
- Field models
|
|
||||||
- Card models
|
|
||||||
- Models
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
import time, re
|
import time, re
|
||||||
from sqlalchemy.ext.orderinglist import ordering_list
|
from sqlalchemy.ext.orderinglist import ordering_list
|
||||||
from anki.db import *
|
from anki.db import *
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Sound support
|
|
||||||
==============================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import re, sys, threading, time, subprocess, os, signal, errno, atexit
|
import re, sys, threading, time, subprocess, os, signal, errno, atexit
|
||||||
import tempfile, shutil
|
import tempfile, shutil
|
||||||
from anki.hooks import addHook, runHook
|
from anki.hooks import addHook, runHook
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Statistical tracking and reports
|
|
||||||
=================================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
# we track statistics over the life of the deck, and per-day
|
# we track statistics over the life of the deck, and per-day
|
||||||
STATS_LIFE = 0
|
STATS_LIFE = 0
|
||||||
STATS_DAY = 1
|
STATS_DAY = 1
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Synchronisation
|
|
||||||
==============================
|
|
||||||
|
|
||||||
Support for keeping two decks synchronized. Both local syncing and syncing
|
|
||||||
over HTTP are supported.
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import zlib, re, urllib, urllib2, socket, simplejson, time, shutil
|
import zlib, re, urllib, urllib2, socket, simplejson, time, shutil
|
||||||
import os, base64, httplib, sys, tempfile, httplib, types
|
import os, base64, httplib, sys, tempfile, httplib, types
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Tags
|
|
||||||
====================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
|
|
||||||
from anki.db import *
|
from anki.db import *
|
||||||
|
|
||||||
#src 0 = fact
|
#src 0 = fact
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
|
||||||
|
|
||||||
"""\
|
|
||||||
Miscellaneous utilities
|
|
||||||
==============================
|
|
||||||
"""
|
|
||||||
__docformat__ = 'restructuredtext'
|
|
||||||
|
|
||||||
import re, os, random, time, types, math, htmlentitydefs, subprocess
|
import re, os, random, time, types, math, htmlentitydefs, subprocess
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue