Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated anki-sync-server to work with the latest version of Anki #20

Merged
merged 38 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f7ae69f
Removed embedded anki submodule
kalehmann Aug 26, 2020
26d16b6
Removed unused import
kalehmann Aug 26, 2020
d0f7d05
Ported Python Syncer from Anki source code
kalehmann Aug 26, 2020
bc88995
Added missing fields to meta endpoint
kalehmann Aug 26, 2020
3857f15
Read hostkey from GET or POST
kalehmann Aug 26, 2020
b566e32
Removed call to load method of anki.collection.Collection
kalehmann Aug 26, 2020
8358b09
Hide the media managers db
kalehmann Aug 26, 2020
c97a096
Made sure to use ConfigManager in Syncer
kalehmann Aug 27, 2020
93d37d6
fix chunk in sync
kalehmann Aug 27, 2020
e18e86e
Log sanity check errors
kalehmann Aug 27, 2020
7eff381
Always downgrade the database before sync
kalehmann Aug 27, 2020
4c09c1e
fix sanity check
kalehmann Aug 28, 2020
537bbe8
updated readme to reflect latest changes
kalehmann Aug 28, 2020
471e3ae
Removed haveDirty check from sync code
kalehmann Aug 28, 2020
c6f82e2
Removed unused class MediaSyncer
kalehmann Aug 28, 2020
9d67943
Marked test to fail because of missing _logChanges Method
kalehmann Aug 28, 2020
94da88a
Updated media test to work with latest changes
kalehmann Aug 28, 2020
89dcfd6
ServerMediaManager extends MediaManager
kalehmann Aug 28, 2020
75c9267
Fix parent initialization of SyncCollectionHandler
kalehmann Aug 28, 2020
2c1e593
Removed test because of deprecated MediaSyncer
kalehmann Aug 28, 2020
c5bce62
Adapted sync app test to latest changes
kalehmann Aug 28, 2020
5f17eb7
server_utils test helper works with non-expose media db
kalehmann Aug 28, 2020
e2e756d
Removed references to unused methods
kalehmann Aug 28, 2020
0ef99f3
mock_servers test helper works with new syncer code
kalehmann Aug 28, 2020
60f12cf
file_utils test helper works with new syncer code
kalehmann Aug 28, 2020
9831159
Close whole collection instead of just the database
kalehmann Aug 28, 2020
b0d57d3
Use wrapped collection in tests
kalehmann Aug 28, 2020
75c1ea0
Added emacs temporary files to gitignore
kalehmann Aug 28, 2020
9da0eb7
Added anki to dependencies
kalehmann Aug 28, 2020
70bfaa1
Further clarified configuration for Nginx proxy
kalehmann Aug 31, 2020
6f29fce
replaced relative with absolute import
kalehmann Sep 1, 2020
3ec37ec
Removed artifact from README
kalehmann Sep 1, 2020
65e9bbf
Updated docs about installation of requirements
kalehmann Sep 1, 2020
7deda95
Removed whole section about ankisyncd without pyaudio from the README
kalehmann Sep 1, 2020
614f209
Removed unused post- and prehooks
kalehmann Sep 2, 2020
0d8f3c6
Removed runHook calls from sync code
kalehmann Sep 2, 2020
e9e0645
Removed unused sync method
kalehmann Sep 2, 2020
f510050
Removed explicit object parent from FullSyncManager
kalehmann Sep 2, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ share/python-wheels/
*.egg
MANIFEST

# Emacs temporary files
kalehmann marked this conversation as resolved.
Show resolved Hide resolved
*#*#
*.#*

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

108 changes: 42 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,57 +29,55 @@ It supports Python 3 and Anki 2.1.
- [Anki 2.1](#anki-21)
- [Anki 2.0](#anki-20)
- [AnkiDroid](#ankidroid)
- [Running `ankisyncd` without `pyaudio`](#running-ankisyncd-without-pyaudio)
- [Anki ≥2.1.9](#anki-219)
- [Older versions](#older-versions)
- [ENVVAR configuration overrides](#envvar-configuration-overrides)
- [Support for other database backends](#support-for-other-database-backends)
</details>

Installing
----------

0. Install Anki. The currently supported version range is 2.1.1〜2.1.11, with the
exception of 2.1.9<sup id="readme-fn-01b">[1](#readme-fn-01)</sup>. (Keep in
mind this range only applies to the Anki used by the server, clients can be
as old as 2.0.27 and still work.) Running the server with other versions might
work as long as they're not 2.0.x, but things might break, so do it at your
own risk. If for some reason you can't get the supported Anki version easily
on your system, you can use `anki-bundled` from this repo:

$ git submodule update --init
$ cd anki-bundled
$ pip install -r requirements.txt

Keep in mind `pyaudio`, a dependency of Anki, requires development headers for
Python 3 and PortAudio to be present before running `pip`. If you can't or
don't want to install these, you can try [patching Anki](#running-ankisyncd-without-pyaudio).


1. Install the dependencies:

$ pip install webob
$ pip install -r src/requirements.txt

2. Modify ankisyncd.conf according to your needs

3. Create user:

$ ./ankisyncctl.py adduser <username>

4. Run ankisyncd:
4. Setup a proxy to unchunk the requests.
kalehmann marked this conversation as resolved.
Show resolved Hide resolved

$ python -m ankisyncd
Webob does not support the header "Transfer-Encoding: chunked" used by Anki
and therefore ankisyncd sees chunked requests as empty. To solve this problem
setup Nginx (or any other webserver of your choice) and configure it to
"unchunk" the requests for ankisyncd.

---
For example, if you use Nginx on the same machine as ankisyncd, you first
have to change the port in `ankisyncd.conf` to something other than `27701`.
Then configure Nginx to listen on port `27701` and forward the unchunked
requests to ankisyncd.

An example configuration with ankisyncd running on the same machine as Nginx
and listening on port `27702` may look like:

<span id="readme-fn-01"></span>
1. 2.1.9 is not supported due to [commit `95ccbfdd3679`][] introducing the
kalehmann marked this conversation as resolved.
Show resolved Hide resolved
dependency on the `aqt` module, which depends on PyQt5. The server should
still work fine if you have PyQt5 installed. This has been fixed in
[commit `a389b8b4a0e2`][], which is a part of the 2.1.10 release.
[↑](#readme-fn-01b)
```
server {
listen 27701;
server_name default;

[commit `95ccbfdd3679`]: https://github.com/dae/anki/commit/95ccbfdd3679dd46f22847c539c7fddb8fa904ea
[commit `a389b8b4a0e2`]: https://github.com/dae/anki/commit/a389b8b4a0e209023c4533a7ee335096a704079c
location / {
proxy_http_version 1.0;
proxy_pass http://localhost:27702/;
}
}
```

5. Run ankisyncd:

$ python -m ankisyncd

---

Installing (Docker)
-------------------
Expand All @@ -89,6 +87,18 @@ Follow [these instructions](https://github.com/kuklinistvan/docker-anki-sync-ser
Setting up Anki
---------------

### Anki 2.1.28 and above

Create a new directory in [the add-ons folder][addons21] (name it something
like ankisyncd), create a file named `__init__.py` containing the code below
and put it in the `ankisyncd` directory.

import os

addr = "http://127.0.0.1:27701/" # put your server address here
os.environ["SYNC_ENDPOINT"] = addr + "sync/"
os.environ["SYNC_ENDPOINT_MEDIA"] = addr + "msync/"

### Anki 2.1

Create a new directory in [the add-ons folder][addons21] (name it something
Expand Down Expand Up @@ -125,44 +135,10 @@ Unless you have set up a reverse proxy to handle encrypted connections, use
whatever you have specified in `ankisyncd.conf` (or, if using a reverse proxy,
whatever port you configured to accept the front-end connection).

**Do not use trailing slashes.**
kalehmann marked this conversation as resolved.
Show resolved Hide resolved

Even though the AnkiDroid interface will request an email address, this is not
required; it will simply be the username you configured with `ankisyncctl.py
adduser`.

Running `ankisyncd` without `pyaudio`
-------------------------------------

`ankisyncd` doesn't use the audio recording feature of Anki, so if you don't
want to install PortAudio, you can edit some files in the `anki-bundled`
directory to exclude `pyaudio`:

### Anki ≥2.1.9

Just remove "pyaudio" from requirements.txt and you're done. This change has
been introduced in [commit `ca710ab3f1c1`][].

[commit `ca710ab3f1c1`]: https://github.com/dae/anki/commit/ca710ab3f1c1174469a3b48f1257c0fc0ce624bf

### Older versions

First go to `anki-bundled`, then follow one of the instructions below. They all
do the same thing, you can pick whichever one you're most comfortable with.

Manual version: remove every line past "# Packaged commands" in anki/sound.py,
remove every line starting with "pyaudio" in requirements.txt

`ed` version:

$ echo '/# Packaged commands/,$d;w' | tr ';' '\n' | ed anki/sound.py
$ echo '/^pyaudio/d;w' | tr ';' '\n' | ed requirements.txt

`sed -i` version:

$ sed -i '/# Packaged commands/,$d' anki/sound.py
$ sed -i '/^pyaudio/d' requirements.txt

ENVVAR configuration overrides
------------------------------

Expand Down
Loading