# -*- coding: utf-8 -*-
from setuptools import setup

package_dir = \
{'': 'src'}

packages = \
['djankiserv',
 'djankiserv.api',
 'djankiserv.assets.jsonfiles',
 'djankiserv.assets.sql.sqlite3',
 'djankiserv.migrations',
 'djankiserv.sync',
 'djankiserv.unki']

package_data = \
{'': ['*']}

install_requires = \
['django-k8s>=0.2.9,<0.3.0',
 'django>=3.1,<4.0',
 'djangorestframework-simplejwt>=4.4.0,<5.0.0',
 'djangorestframework>=3.11.1,<4.0.0',
 'gunicorn>=20.0.4,<21.0.0']

setup_kwargs = {
    'name': 'djankiserv',
    'version': '0.0.3',
    'description': 'Django-based synchronisation and API server for Anki',
    'long_description': '# djankiserv\n`djankiserv` is an open source Django-based implementation of a synchronisation server for Anki 2.1+. It includes a user manager (the native Django user system).\n\nUnlike the other popular open source Anki synchronisation server [`anki-sync-server`](https://github.com/ankicommunity/anki-sync-server), `djankiserv` stores the user data in a "proper" RDBMS. There are two \'database connections\' that can be set - those for the \'system\' (sessions, users, etc.) and those for user data. The \'system\' stuff is just plain old Django, so any supported database can be used. The user data part currently uses either `postgresql` schemas or `mysql` databases, and currently only supports those two, though supporting other RDBMSes will definitely be considered later. `sqlite3` is an embedded database and works great for that. It is not appropriate for use in modern web applications in the opinion of the maintainer, so will never be supported by `djankiserv`.\n\nThere is a basic API for getting certain, per-user collection-related information (decks, deck configuration, models, tags) and also `notes` for a given user. It may evolve to include other functions, statistics and even doing cards, though the focus is currently on getting and maintaining proper synchronisation as well as the basic API for `notes`.\n\nLimitations\n===========\n\nThis is alpha software with some occasional data loss bugs. It works, sorta, if you hold it right. If it kills your kittens then you were forewarned!\n\nCurrent known limitations (bugs!):\n\n- it doesn\'t support abort and if it crashes in the middle of a sync then the server will have a corrupt view of the database. You should force an upload sync on next synchronisation if this ever happens!\n- The v2 scheduler is not supported, and it is unclear how difficult this might be to implement.\n\nStatus\n======\n`djankiserv` is still alpha software. It was developed for the language learning platform [Transcrob.es](https://transcrob.es) and will mature as that project matures.\n\nInstallation\n============\n`djankiserv` is a Django Rest Framework-based `Django` app, so can easily be used in any `postgresql`/`mysql`-driven `Django` site you already have. It is available in pypi, so you can simply install vi `pypi` and include as an app in your `INSTALLED_APPS`.\n\n```\n$ pip install djankiserv\n```\n\n```\nINSTALLED_APPS = [\n    # core required\n    "django.contrib.admin",\n    "django.contrib.auth",\n    "django.contrib.contenttypes",\n    "django.contrib.sessions",\n    "django.contrib.messages",\n    "django.contrib.staticfiles",\n    ...\n    "rest_framework",  # DRF IS ALSO REQUIRED!\n    "djankiserv.apps.DjankiservConfig",\n    ...\n]\n```\n\nWARNING!!!\n\nRecent `anki` clients now use \'chunking\' and `Django` doesn\'t (appear to) support that out of the box, meaning you MUST have your site behind a proxy like `Apache` `mod_proxy` or `nginx`. Any site should have this anyway, so there likely won\'t be a strong push to implement this natively.\n\nKubernetes and docker\n=====================\nThis repo also contains the `Dockerfile`s required to get it running and a `Kubernetes` helm chart. Docker images are currently being stored on the Docker Hub in `antonmelser/djankiserv` for both a working `djankiserv` and an `nginx`-based images containing the static files needed for the `admin` part in `antonmelser/djankiserv-static`.\n\nThe `helm` chart is known to work on `microk8s` and allows you to very easily install a full stack in a few commands, including SSL certificates for the synchronisation server (this is particularly important for `Ankidroid`). See the dedicated chart readme in `charts/README.md` of this repository for instructions installing the chart on a `microk8s` instance.\n\nConfiguration\n=============\n\nThis repo contains the `Django` project which is used for the `Kubernetes Helm` chart, so you can see all the required options in that file in `djankiserv/src/djankiservproj/settings.py`. Sensible defaults should exist for all options, and all of the options that make sense to change via environment variables are configurable in that way.\n\n```\n# Djankiserv values\n\nDATABASES = {}\n\nif os.getenv("DJANKISERV_MAINDB_ENGINE") == "django.db.backends.mysql":\n    DATABASES["default"] = {\n        "ENGINE": os.getenv("DJANKISERV_MAINDB_ENGINE", "django.db.backends.mysql"),\n        "NAME": os.getenv("DJANKISERV_MAINDB_NAME", "djankiserv"),\n        "USER": os.getenv("DJANKISERV_MAINDB_USER", "djankiserv"),\n        "PASSWORD": os.getenv("DJANKISERV_MAINDB_PASSWORD", "password"),\n        "HOST": os.getenv("DJANKISERV_MAINDB_HOST", "127.0.0.1"),\n        "OPTIONS": {"autocommit": True, "init_command": "SET default_storage_engine=INNODB"},\n        "PORT": os.getenv("DJANKISERV_MAINDB_PORT", "3306"),\n    }\nelse:\n    DATABASES["default"] = {\n        "ENGINE": os.getenv("DJANKISERV_MAINDB_ENGINE", "django.db.backends.postgresql"),\n        "NAME": os.getenv("DJANKISERV_MAINDB_NAME", "djankiserv"),\n        "USER": os.getenv("DJANKISERV_MAINDB_USER", "djankiserv"),\n        "PASSWORD": os.getenv("DJANKISERV_MAINDB_PASSWORD", "password"),\n        "HOST": os.getenv("DJANKISERV_MAINDB_HOST", "127.0.0.1"),\n        "PORT": os.getenv("DJANKISERV_MAINDB_PORT", "5432"),\n    }\n\nif os.getenv("DJANKISERV_USERDB_ENGINE") == "django.db.backends.mysql":\n    djankiserv.unki.AnkiDataModel = MariadbAnkiDataModel\n    DATABASES["userdata"] = {\n        "ENGINE": os.getenv("DJANKISERV_USERDB_ENGINE", "django.db.backends.mysql"),\n        "NAME": os.getenv("DJANKISERV_USERDB_NAME", "djankiserv"),\n        "USER": os.getenv("DJANKISERV_USERDB_USER", "djankiserv"),\n        "PASSWORD": os.getenv("DJANKISERV_USERDB_PASSWORD", "password"),\n        "HOST": os.getenv("DJANKISERV_USERDB_HOST", "127.0.0.1"),\n        "OPTIONS": {\n            "autocommit": True,\n            "init_command": "SET default_storage_engine=INNODB",\n            "sql_mode": "traditional,NO_BACKSLASH_ESCAPES",\n        },\n        "PORT": os.getenv("DJANKISERV_USERDB_PORT", "3306"),\n    }\nelse:\n    djankiserv.unki.AnkiDataModel = PostgresAnkiDataModel\n    DATABASES["userdata"] = {\n        "ENGINE": os.getenv("DJANKISERV_USERDB_ENGINE", "django.db.backends.postgresql"),\n        "NAME": os.getenv("DJANKISERV_USERDB_NAME", "djankiserv"),\n        "USER": os.getenv("DJANKISERV_USERDB_USER", "djankiserv"),\n        "PASSWORD": os.getenv("DJANKISERV_USERDB_PASSWORD", "password"),\n        "HOST": os.getenv("DJANKISERV_USERDB_HOST", "127.0.0.1"),\n        "PORT": os.getenv("DJANKISERV_USERDB_PORT", "5432"),\n    }\n\n\n# You can remove the AUTHENTICATION_CLASSES that you don\'t want to support, or keep them all\n# this better protects the /api/\\* methods, the xSYNC methods have \'AllowAll\' decorators\nREST_FRAMEWORK = {\n    "DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"],\n    "DEFAULT_AUTHENTICATION_CLASSES": [\n        "rest_framework_simplejwt.authentication.JWTAuthentication",\n        "rest_framework.authentication.BasicAuthentication",\n        "rest_framework.authentication.SessionAuthentication",\n    ],\n}\n\n# if you change this, it must also be changed in the images/static/Dockerfile\nSTATIC_ROOT = "build/static"\n\n# This is required as Django will add a slash and redirect to that by default, and our clients don\'t\n# support that\nAPPEND_SLASH = False\n\n# this is not actually currently configurable, due to hardcoding in the clients\nDJANKISERV_BASE_URL = "sync/"\n\n# this is not actually configurable, due to hardcoding in the clients\nDJANKISERV_BASE_MEDIA_URL = "msync/"\n\nDJANKISERV_DATA_ROOT = os.getenv("DJANKISERV_DATA_ROOT", "/tmp")\n\n# DEBUG STUFF\nDJANKISERV_DEBUG = os.getenv("DJANKISERV_DEBUG", "False").lower() == "true"\nDEBUG = DJANKISERV_DEBUG  # currently the same\n\nDJANKISERV_GENERATE_TEST_ASSETS = False\nDJANKISERV_GENERATE_TEST_ASSETS_DIR = "/tmp/asrv/"\n```\n\nConnecting Anki to the sync server\n==================================\n\nRecent versions of `Anki` desktop (2.1.32+ and maybe a bit earlier) now require you to use an environment variable to configure the sync server endpoints if you want to use a custom server. For Windows you can do the following (`powershell`):\n```\nPS C:\\Users\\your.user> $env:SYNC_ENDPOINT_MEDIA=\'http://localhost:8002/msync/\'; $env:SYNC_ENDPOINT=\'https://localhost:8002/sync/\'; & "C:\\Program Files\\Anki\\anki.exe"; Remove-Item Env:\\SYNC_ENDPOINT_MEDIA; Remove-Item Env:\\SYNC_ENDPOINT\n```\nOn Linux (assuming `anki` is in your path, which it should be. This may also work on Mac?):\n```\nSYNC_ENDPOINT_MEDIA=\'http://localhost:8002/msync/\' SYNC_ENDPOINT=\'http://localhost:8002/sync/\' anki\n```\n\nDevelopment\n===========\n\nThis implementation was initially developed in order to support the spaced repetition functionality for [`Transcrobes`](https://transcrob.es), an open source language learning platform/ecosystem. Any requests or functionality that don\'t interfere with using this project for that will definitely be entertained. Ideally the server would do everything that Ankiweb does, and much more. PRs are obviously always welcome!\n\nIf you want to get involved, start the conversation by creating an issue in the Github issue tracker for the functionality you are interest in.\n\n`djankiserv` uses `poetry`:\n\n`curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python`\n\nThen just install the project:\n\n`poetry install`\n\nThe settings will "just work" if you create a `postgresql`/`mysql` database called `djankiserv` with a superuser `djankiserv` with the password `password`.\n\nYou should then be able to launch by doing:\n\n`poetry run ./scripts/runmanage.sh migrate`\n\n`poetry run ./scripts/runmanage.sh createsuperuser`\n\nAnd create yourself an admin user.\n\nand finally:\n\n`poetry run ./scripts/rundevserver.sh`\n\nIt will then be listening on `http://localhost:8002/`, and you can log into `http://localhost:8002/admin/` and add a normal user using the normal `django` web interface.\n\n:warning::warning::warning: You MUST implement a proxy or certain sync functions WILL NOT WORK. A simple reverse proxy is all that you need, so any serious http server should be fine, and docs very easy to find.\n',
    'author': 'Anton Melser',
    'author_email': 'anton@melser.org',
    'maintainer': 'Anton Melser',
    'maintainer_email': 'anton@melser.org',
    'url': 'https://github.com/ankicommunity/djankiserv',
    'package_dir': package_dir,
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.8,<3.9',
}


setup(**setup_kwargs)
