Add missing stuff to make this code working.
--- a/obsolete/exp_anki.py Fri Nov 11 00:19:47 2016 +0200
+++ b/obsolete/exp_anki.py Fri Nov 11 23:24:49 2016 +0200
@@ -1,5 +1,7 @@
import sys
+import os
import tempfile
+import shutil
FONAME = "test.apkg"
@@ -7,8 +9,16 @@
# Therefore absolute path should be stored before creating temporary deck
FONAME = os.path.abspath(FONAME)
FBASENAME, _ = os.path.splitext(os.path.basename(FONAME))
+
+CWD = os.getcwd()
TMPDIR = tempfile.mkdtemp(dir = os.path.dirname(FONAME))
+def cleanup(type_, ex, traceback):
+ os.chdir(CWD)
+ shutil.rmtree(TMPDIR)
+
+sys.excepthook = cleanup
+
sys.path.append('/usr/share/anki')
import anki
from anki.exporting import AnkiPackageExporter
@@ -88,6 +98,11 @@
# model.save()
export = AnkiPackageExporter(collection)
+try:
+ os.remove(FONAME)
+except OSError as ex:
+ if ex.errno not in [2]:
+ raise
export.exportInto(FONAME)
cleanup()