From 98566ca8baaff4de15bf99f92139d5743b766eac Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 5 Jan 2020 16:24:20 -0800 Subject: [PATCH] Cleanup --- .gitignore | 1 + package.sh | 2 ++ plugin/__init__.py | 13 ++++++++++--- plugin/config.json | 9 +++++++++ plugin/config.md | 1 + test.sh | 3 +-- tests/test_misc.py | 3 --- zip.sh | 5 ----- 8 files changed, 24 insertions(+), 13 deletions(-) create mode 100755 package.sh delete mode 100755 zip.sh diff --git a/.gitignore b/.gitignore index b9b667b..2b18174 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pyc AnkiConnect.zip +meta.json diff --git a/package.sh b/package.sh new file mode 100755 index 0000000..57e1329 --- /dev/null +++ b/package.sh @@ -0,0 +1,2 @@ +#!/usr/bin/bash +7za a AnkiConnect.zip plugin/* diff --git a/plugin/__init__.py b/plugin/__init__.py index 7d3c2ab..4340280 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -29,6 +29,7 @@ from PyQt5.QtCore import QTimer from PyQt5.QtWidgets import QMessageBox import anki +import anki.lang import aqt from AnkiConnect import web, util @@ -65,6 +66,7 @@ class AnkiConnect: self.log.write('[{}]\n'.format(name)) json.dump(data, self.log, indent=4, sort_keys=True) self.log.write('\n\n') + self.log.flush() def advance(self): @@ -77,10 +79,15 @@ class AnkiConnect: name = request.get('action', '') version = request.get('version', 4) params = request.get('params', {}) + key = request.get('key') reply = {'result': None, 'error': None} try: + if key != util.setting('apiKey'): + raise Exception('valid api key must be provided') + method = None + for methodName, methodInst in inspect.getmembers(self, predicate=inspect.ismethod): apiVersionLast = 0 apiNameLast = None @@ -580,11 +587,11 @@ class AnkiConnect: mm = collection.models # Generate new Note - m = mm.new(_(modelName)) + m = mm.new(anki.lang._(modelName)) # Create fields and add them to Note for field in inOrderFields: - fm = mm.newField(_(field)) + fm = mm.newField(anki.lang._(field)) mm.addField(m, fm) # Add shared css to model if exists. Use default otherwise @@ -594,7 +601,7 @@ class AnkiConnect: # Generate new card template(s) cardCount = 1 for card in cardTemplates: - t = mm.newTemplate(_('Card ' + str(cardCount))) + t = mm.newTemplate(anki.lang._('Card ' + str(cardCount))) cardCount += 1 t['qfmt'] = card['Front'] t['afmt'] = card['Back'] diff --git a/plugin/config.json b/plugin/config.json index 2c63c08..68149f1 100644 --- a/plugin/config.json +++ b/plugin/config.json @@ -1,2 +1,11 @@ { + "apiKey": null, + "apiLogPath": null, + "apiPollInterval": 25, + "apiVersion": 6, + "webBacklog": 5, + "webBindAddress": "127.0.0.1", + "webBindPort": 8765, + "webCorsOrigin": "http://localhost", + "webTimeout": 10000 } diff --git a/plugin/config.md b/plugin/config.md index e69de29..6bacba2 100644 --- a/plugin/config.md +++ b/plugin/config.md @@ -0,0 +1 @@ +Read the documentation on the [AnkiConnect](https://foosoft.net/projects/anki-connect/) project page for details. diff --git a/test.sh b/test.sh index 1fa881b..61a4948 100755 --- a/test.sh +++ b/test.sh @@ -1,3 +1,2 @@ -#!/usr/bin/sh - +#!/usr/bin/bash python -m unittest discover -v tests diff --git a/tests/test_misc.py b/tests/test_misc.py index 6ed5f49..3115e34 100755 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -9,9 +9,6 @@ class TestMisc(unittest.TestCase): # version self.assertEqual(util.invoke('version'), 6) - # upgrade - util.invoke('upgrade') - # sync util.invoke('sync') diff --git a/zip.sh b/zip.sh deleted file mode 100755 index 2f6d2ab..0000000 --- a/zip.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/bash -rm AnkiConnect.zip -cp AnkiConnect.py __init__.py -7za a AnkiConnect.zip __init__.py -rm __init__.py